MKVAttachment

MKVAttachment classes are used to represent attachment files within an MKV or to be used in an MKV.

Examples

Below are some basic examples of how the MKVAttachment objects can be used.

Create a new MKVAttachment and add it to an MKVFile.

>>> from pymkv import MKVAttachment
>>> attachment = MKVAttachment('path/to/attachment.jpg', name='NAME')
>>> attachment.description = 'DESCRIPTION'

Attachments can also be added directly to an MKVFile.

>>> from pymkv import MKVFile
>>> mkv = MKVFile('path/to/file.mkv')
>>> mkv.add_attachment('path/to/other/attachment.png')

Now, the MKV can be muxed with both attachments.

>>> mkv.add_attachment(attachment)
>>> mkv.mux('path/to/output.mkv')
class pymkv.MKVAttachment(file_path: str, name: str | None = None, description: str | None = None, attach_once: bool | None = False)

A class that represents an MKV attachment for an MKVFile object.

Parameters:
file_path : str

The path to the attachment file.

name : str, optional

The name that will be given to the attachment when muxed into a file.

description : str, optional

The description that will be given to the attachment when muxed into a file.

attach_once : bool, optional

Determines if the attachment should be added to all split files or only the first. Default is False, which will attach to all files.

mime_type

The attachment’s MIME type. The type will be guessed when file_path is set.

Type:

str

name

The name that will be given to the attachment when muxed into a file.

Type:

str

description

The description that will be given to the attachment when muxed into a file.

Type:

str

attach_once

Determines if the attachment should be added to all split files or only the first. Default is False, which will attach to all files.

Type:

bool

size

The size of the attachment in bytes, as reported by the file it was read from. It is None for an attachment built from a local path, since that attachment is not part of an MKV yet.

Type:

int | None

property attach_once : bool | None

Get whether the attachment should be added only to the first split file.

Returns:

True if attachment should only be added to the first split file,

False if it should be added to all split files.

Return type:

bool | None

property description : str | None

Get the description of the attachment.

Returns:

The description of the attachment or None if not set.

Return type:

str | None

property file_path : str

The path to the attachment file.

For an attachment read out of an MKV this is the containing file, and the path cannot be changed. Replace such an attachment with remove_attachment() followed by add_attachment().

Raises:
  • FileNotFoundError – Raised if file_path does not exist.

  • ValueError – Raised when changing the path of an attachment that was read from a file.

Type:

str

property mime_type : str | None

Get the MIME type of the attachment.

Returns:

The MIME type of the attachment or None if not detected.

Return type:

str | None

property name : str | None

Get the name of the attachment.

Returns:

The name of the attachment or None if not set.

Return type:

str | None

property size : int | None

Get the size of the attachment in bytes.

The value comes from the file the attachment was read from, not from file_path, which points at the containing MKV for an attachment read out of one.

It stays None for an attachment built from a local path, including after mux(): this object is never refreshed from the output. Load the muxed file into a new MKVFile to read the sizes it ended up with.

Returns:

The size in bytes, or None for an attachment that was not read from a file.

Return type:

int | None

property source_file : str | None

Get the path to the source file containing the attachment.

Returns:

The path to the source file or None if not from a source file.

Return type:

str | None

property source_id : int | None

Get the ID of the attachment from the source file.

Returns:

The ID of the attachment in the source file or None if not from a source file.

Return type:

int | None