TypeFind

class TypeFind(*args, **kwargs)

The following functions allow you to detect the media type of an unknown stream.

Methods

class TypeFind
get_length() int

Get the length of the data stream.

peek(offset: int, size: int) int | None

Returns the size bytes of the stream to identify beginning at offset. If offset is a positive number, the offset is relative to the beginning of the stream, if offset is a negative number the offset is relative to the end of the stream. The returned memory is valid until the typefinding function returns and must not be freed.

Parameters:
  • offset – The offset

  • size – The number of bytes to return

register(plugin: Plugin | None, name: str, rank: int, func: Callable[[...], None], extensions: str | None = None, possible_caps: Caps | None = None, *data: Any) bool

Registers a new typefind function to be used for typefinding. After registering this function will be available for typefinding. This function is typically called during an element’s plugin initialization.

Parameters:
  • plugin – A Plugin, or None for a static typefind function

  • name – The name for registering

  • rank – The rank (or importance) of this typefind function

  • func – The TypeFindFunction to use

  • extensions – Optional comma-separated list of extensions that could belong to this type

  • possible_caps – Optionally the caps that could be returned when typefinding succeeds

  • data – Optional user data. This user data must be available until the plugin is unloaded.

suggest(probability: int, caps: Caps) None

If a TypeFindFunction calls this function it suggests the caps with the given probability. A TypeFindFunction may supply different suggestions in one call. It is up to the caller of the TypeFindFunction to interpret these values.

Parameters:
  • probability – The probability in percent that the suggestion is right

  • caps – The fixed Caps to suggest

suggest_empty_simple(probability: int, media_type: str) None

If a TypeFindFunction calls this function it suggests caps of the given media_type with the given probability.

This function is similar to suggest_simple(), but uses a Caps with no fields.

Added in version 1.20.

Parameters:
  • probability – The probability in percent that the suggestion is right

  • media_type – the media type of the suggested caps

Fields

class TypeFind
data

The data used by the caller of the typefinding function.