mime ¶
Classes:
-
FileSignature
–Child structure of FileSignatures, holding info of certain types of files and their signatures.
-
FileSignatures
–Structure wrapping a json file holding all file signatures.
-
FileType
–Enum for file types and mime types.
-
IndexingType
–Enum of common indexing file extensions.
-
ParsedFile
–Structure for file info.
FileSignature ¶
Bases: NamedTuple
Child structure of FileSignatures, holding info of certain types of files and their signatures.
Methods:
-
check_signature
–Verify the signature of the file.
Attributes:
-
ext
(str
) –Extension from the signature.
-
file_type
(str
) –FileType as a str.
-
mime
(str
) –MIME type of the signature.
-
offset
(int
) –Offset from the start of the file of the signatures.
-
signatures
(list[bytes]
) –Byte data signatures, unique for this file type.
signatures instance-attribute
¶
Byte data signatures, unique for this file type.
check_signature ¶
Verify the signature of the file.
Parameters:
-
file_bytes
¶bytes | bytearray
) –Header bytes of the file to be checked.
-
ignore
¶int
, default:0
) –If a found signature is shorter than this length, it will be ignored.
Returns:
-
int
–Length of the found signature.
Source code
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
FileSignatures ¶
FileSignatures(
*,
custom_header_data: str | Path | list[FileSignature] | None = None,
force: bool = False
)
Bases: list[FileSignature]
Structure wrapping a json file holding all file signatures.
Fetch all the file signatures, optionally with added custom signatures.
Methods:
-
load_headers_data
–Load file signatures from json file. This is cached unless
custom_header_data
is set. -
parse
–Parse a given file.
Attributes:
-
file_headers_path
–Custom path for the json containing file headers.
-
max_signature_len
–
Source code
107 108 109 110 111 112 113 114 |
|
file_headers_path class-attribute
instance-attribute
¶
Custom path for the json containing file headers.
max_signature_len instance-attribute
¶
max_signature_len = max(
from_iterable([len(signature) for signature in signatures] for mime in self)
)
load_headers_data ¶
load_headers_data(
*,
custom_header_data: str | Path | list[FileSignature] | None = None,
force: bool = False
) -> list[FileSignature]
Load file signatures from json file. This is cached unless custom_header_data
is set.
Parameters:
-
custom_header_data
¶str | Path | list[FileSignature] | None
, default:None
) –Custom header data path file or custom list of already parsed FileSignature.
-
force
¶bool
, default:False
) –Ignore cache and reload header data from disk.
Returns:
-
list[FileSignature]
–List of parsed FileSignature from json file.
Source code
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
parse ¶
parse(filename: Path) -> FileSignature | None
Parse a given file.
Parameters:
Returns:
-
FileSignature | None
–The input file's mime signature.
Source code
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
FileType ¶
Bases: FileTypeBase
Enum for file types and mime types.
Methods:
-
__call__
–Get an INDEX FileType of another FileType (Video, Audio, Other).
-
is_index
–Verify whether the FileType is an INDEX that holds its own FileType (e.g. mime: index/video).
-
parse
–Parse infos from a file. If the FileType is different than AUTO, this function will throw if the file
Attributes:
-
ARCHIVE
–File type for archive files.
-
AUDIO
–File type for audio files.
-
AUTO
–Special file type for :py:attr:
FileType.parse
. -
CHAPTERS
–File type for chapters files.
-
DOCUMENT
–File type for documents.
-
FONT
–File type for font files.
-
IMAGE
–File type for image files.
-
INDEX
– -
INDEX_AUDIO
– -
INDEX_VIDEO
– -
OTHER
–File type for generic files, like applications.
-
VIDEO
–File type for video files.
AUTO class-attribute
instance-attribute
¶
AUTO = 'auto'
Special file type for :py:attr:FileType.parse
.
OTHER class-attribute
instance-attribute
¶
OTHER = 'other'
File type for generic files, like applications.
__call__ ¶
__call__(file_type: str | FileType) -> FileTypeIndexWithType
Get an INDEX FileType of another FileType (Video, Audio, Other).
Source code
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
is_index ¶
is_index() -> TypeGuard[FileTypeIndexWithType]
Verify whether the FileType is an INDEX that holds its own FileType (e.g. mime: index/video).
Source code
324 325 326 327 |
|
parse ¶
parse(
path: FilePathType,
*,
func: FuncExceptT | None = None,
force_ffprobe: bool | None = None
) -> ParsedFile
Parse infos from a file. If the FileType is different than AUTO, this function will throw if the file is a different FileType than what this method was called on.
:force_ffprobe: Only rely on ffprobe to parse the file info.
Parameters:
-
path
¶FilePathType
) –Path of the file to be parsed.
-
func
¶FuncExceptT | None
, default:None
) –Function returned for custom error handling. This should only be set by VS package developers.
Returns:
-
ParsedFile
–ParsedFile object, holding the file's info.
Source code
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
IndexingType ¶
Bases: CustomStrEnum
Enum of common indexing file extensions.
Attributes:
ParsedFile ¶
Bases: NamedTuple
Structure for file info.
Attributes: