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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
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
121 122 123 124 125 126 127 128 129 130 |
|
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
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
parse ¶
parse(filename: Path) -> FileSignature | None
Parse a given file.
Parameters:
Returns:
-
FileSignature | None
–The input file's mime signature.
Source code
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
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 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.
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
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
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
364 365 366 367 368 369 |
|
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.
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.
:force_ffprobe: Only rely on ffprobe to parse the file info.
Returns:
-
ParsedFile
–ParsedFile object, holding the file's info.
Source code
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 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
IndexingType ¶
Bases: CustomStrEnum
Enum of common indexing file extensions.
Attributes:
ParsedFile ¶
Bases: NamedTuple
Structure for file info.
Attributes: