ISCC - Mediatype Detection#
Detect and map RFC6838 mediatypes to ISCC processing modes.
mediatype_and_mode(fp)
#
mediatype_guess(data, file_name = None)
#
Guess mediatype from raw data or filename.
First try to guess by file extension. If that fails we match by content sniffing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
bytes
|
Raw file data (first 4096 bytes recommended) |
required |
file_name |
Optional[str]
|
Filename for guessing based on file extension |
None
|
Returns:
Type | Description |
---|---|
str
|
Media type sting |
mediatype_normalize(mime)
#
mediatype_supported(mime)
#
Check if mediatype is supported.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mime |
str
|
Mediatype sting |
required |
Returns:
Type | Description |
---|---|
bool
|
True if mediatype is supported |
mediatype_from_name(name)
#
Guess mediatype from filename or URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Filename or URL |
required |
Returns:
Type | Description |
---|---|
str
|
Mediatype string |
mediatype_from_data(data)
#
Guess mediatype by sniffing raw header data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
bytes
|
Raw fileheader data (first 4096 bytes recommended) |
required |
Returns:
Type | Description |
---|---|
str
|
Mediatype string |
mediatype_clean(mime)
#
Clean mediatype/content-type string or first entry of a list of mimetype strings.
Also removes semicolon separated encoding information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mime |
str|List
|
Mediatype or list of mediatypes |
required |
Returns:
Type | Description |
---|---|
str
|
Mediatype string |
mediatype_to_mode(mime_type)
#
Get perceptual processing mode from mimetype.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mime_type |
str
|
RFC-6838 mediatype string |
required |
Returns:
Type | Description |
---|---|
Processing mode ("text", "image", "audio", "video") |
Raises:
Type | Description |
---|---|
ValueError
|
if no matching processing mode was found. |