epublib.media_type module¶
- guess_file_type(path: str | Path) str | None¶
Guess the media type of a file based on its filename or path.
- Parameters:
path – The file path or name to guess file type from.
- Returns:
The guessed media type as a string, or None if it cannot be determined.
- class Category(*values)¶
Bases:
IntEnumBroad categories of media types.
- IMAGE = 1¶
Image-based media (e.g., JPEG, PNG, SVG).
- AUDIO = 2¶
Audio media (e.g., MP3, AAC, OGG).
- STYLE = 3¶
Stylesheets (i.e., CSS).
- FONT = 4¶
Fonts (e.g., OTF, TTF, WOFF).
- OTHER = 5¶
Miscellaneous resources that do not fit in other categories.
- FOREIGN = 6¶
Non-core resources.
- class MediaType(*values)¶
Bases:
StrEnumAn EPUB media type, also known as a MIME type. Core EPUB media types are enumerated as members of this class. Non-core media types can be represented by instantiating the class with a string value. Example:
>>> MediaType("image/jpeg") <MediaType.IMAGE_JPEG: 'image/jpeg'> >>> MediaType("application/unkown") <MediaType.FOREIGN: 'application/unkown'>
- Parameters:
value (str) – The media type string.
- classmethod from_filename(
- value: str | Path,
Detect media type from filename or path. If a mimetype for the path is found, but is not supported by MediaType, return it as a string.
- Parameters:
value – The file path or name to guess file type from.
- Returns:
A MediaType instance if the media type is recognized, None otherwise.
- is_css() bool¶
Returns whether the media type is CSS.
- is_js() bool¶
Returns whether the media type is javascript.
- is_video() bool¶
Returns whether if the media type is video.