upsies.utils.mediainfo

Modules

audio

text

Subtitles information

video

Functions

upsies.utils.mediainfo.get_container_format(path, default=<object object>)[source]

Return container format as str or None if detection fails

For files, this is the most commonly used file extension in lowercase.

For DVD/Blu-ray trees, return VIDEO_TS or BDMV.

Parameters:
  • path (str) –

    Path to video file

    For directories, the return value of find_main_video() is used.

  • default – Return value if path doesn’t exist, raise ContentError if not provided

Raises:

ContentError – if anything goes wrong

upsies.utils.mediainfo.get_duration(path, default=<object object>)[source]

Return video duration in seconds (float)

Parameters:
  • path (str) –

    Path to video file

    For directories, the return value of find_main_video() is used.

  • default – Return value if path doesn’t exist, raise ContentError if not provided

Raises:

ContentError – if anything goes wrong

upsies.utils.mediainfo.get_duration_from_ffprobe(path, default=<object object>)[source]

Return video duration in seconds (float) from ffprobe

Parameters:
  • path (str) –

    Path to video file or directory

    For directories, the return value of find_main_video() is used.

  • default – Return value if path doesn’t exist, raise ContentError if not provided

Raises:

ContentError – if anything goes wrong

upsies.utils.mediainfo.get_duration_from_mediainfo(path, default=<object object>)[source]

Return video duration in seconds (float) from mediainfo

Parameters:
  • path (str) –

    Path to video file

    For directories, the return value of find_main_video() is used.

  • default – Return value if path doesn’t exist, raise ContentError if not provided

Raises:

ContentError – if anything goes wrong

upsies.utils.mediainfo.get_mediainfo_report(path)[source]

mediainfo output as a string

The parent directory of path is redacted.

Parameters:

path (str) –

Path to video file or directory

For directories, the return value of find_main_video() is used.

Raises:

ContentError – if anything goes wrong

upsies.utils.mediainfo.get_tracks(path, default=<object object>)[source]

mediainfo --Output=JSON as dictionary that maps each track’s @type to a list of track dictionaries

Parameters:
  • path (str) –

    Path to video file or directory

    For directories, the return value of find_main_video() is used.

  • default – Return value if path doesn’t exist, raise ContentError if not provided

Raises:

ContentError – if anything goes wrong

upsies.utils.mediainfo.lookup(path, keys, type=None, default=<object object>)[source]

Return nested value from get_tracks()

Parameters:
  • path (str) –

    Path to video file

    For directories, the return value of find_main_video() is used.

  • keys – Iterable of nested keys/indexes in the return value of get_tracks()

  • type

    Callable that takes a str value from the tracks returned by get_tracks() and returns a desired type (e.g. int)

    Note

    The default value is not converted with type and returned as is.

  • default – Return value if path doesn’t exist, raise ValueError if not provided

For example, (“Audio”, 0, “Language”) returns the language of the first audio track. If no language is defined return default or raise ContentError if default is not provided.

In lists, instead of an index, you can use "DEFAULT" to find the default track in that list, e.g. (“Audio”, “DEFAULT”, “Language”) returns the language of the default audio track. The default track is either marked specifically as such in the container or, if no track is marked, the first track is used.

Any exception from type will bubble up and must be caught by the caller.

Raises:

ContentError – if path does not exist or if keys does not resolve to a value and default is not provided.