upsies.utils.release
Release name parsing and formatting
ReleaseInfo parses a string into a dictionary-like object with a
specific set of keys, e.g. “title”, “resolution”, “source”, etc.
ReleaseName wraps ReleaseInfo to do the same, but in addition
it tries to read media data from the file system to get information. It also
adds a format method to turn everything back into a
string.
Module Attributes
- upsies.utils.release.DELIM = '[ \\.-]'
Regular expression that matches a single delimiter between release name parts, usually
"."or" "
Classes
- class upsies.utils.release.Episodes(*args, **kwargs)[source]
Bases:
dictdictsubclass that maps season numbers to lists of episode numbersAll keys and values are
strobjects. All episodes from a season are indicated by an empty sequence. For episodes from any sason, the key is an empty string.This class accepts the same arguments as
dict.To provide seasons as keyword arguments, you need to prefix “S” to each keyword. This is because numbers can’t be keyword arguments, but it also looks nicer.
>>> e = Episodes({"1": ["1", "2", "3"], "2": []}) >>> e.update(S01=[3, "4"], S3=range(2, 4), s05=[], S=[10, "E11", 12]) >>> e >>> Episodes({'1': ['1', '2', '3', '4'], '2': [], '3': ['2', '3'], '5': [], '': ['10', '11', '12']})
- regex = re.compile('(?:[ \\.-]|^)((?i:[SE]\\d+)+)(?:[ \\.-]|$)')
Regular expression that matches “S01E02”-like episode information
- classmethod has_episodes_info(string)[source]
Whether string contains “S01E02”-like episode information
- classmethod is_episodes_info(string)[source]
Whether string is “S01E02”-like episode information and nothing else
- classmethod from_string(value)[source]
Create instance from release name or string that contains “Sxx” and “Exx”
Examples:
>>> Episodes.from_string('foo.E01 bar') {'': ('1',)} >>> Episodes.from_string('foo E01E2.bar') {'': ('1', '2')} >>> Episodes.from_string('foo.bar.E01E2S03') {'': ('1', '2'), '3': ()} >>> Episodes.from_string('E01E2S03E04E05.baz') {'': ('1', '2'), '3': ('4', '5')} >>> Episodes.from_string('S09E08S03E06S9E1') {'9': ('1', '8',), '3': ('6',)} >>> Episodes.from_string('E01S03E06.bar.E02') {'': ('1', '2',), '3': ('6',)}
- classmethod from_sequence(sequence)[source]
Combine episode information from multiple strings
Examples:
>>> Episodes.from_sequence(['foo.S01E01.bar', 'hello']) {'1': ('1',)} >>> Episodes.from_sequence(['foo.S01E01.bar', 'bar.S01E02.baz']) {'1': ('1', '2')}
- property is_season
Whether no episodes are specified, only complete seasons
Note
If no seasons and not episodes are specified, return
False.
- class upsies.utils.release.ReleaseInfo(path, *, strict=False)[source]
Bases:
MutableMappingParse information from release name or path
Note
Consider using
ReleaseNameinstead to get more accurate info from the data of existing files.- Parameters:
release (str) – Release name or path to release content
strict (bool) – Whether to raise
ContentErrorif release looks bad, e.g. an abbreviated scene release file name like “tf-foof.mkv”
If release looks like an abbreviated scene file name (e.g. “abd-mother.mkv”), the parent directory’s name is used if possible.
Gathered information is provided as a dictionary with the following keys:
type(ReleaseTypeenum)titleaka(Also Known As; anything after “AKA” in the title)countryyearepisodes(Episodesinstance)episode_titledateedition(listof “Extended”, “Uncut”, etc)resolutionservice(Streaming service abbreviation)source(“BluRay”, “WEB-DL”, etc)audio_codec(Audio codec abbreviation)audio_channels(e.g. “2.0” or “7.1”)hdr_formatvideo_codecgrouphas_commentary(boolor None to autodetect)
Unless documented otherwise above, all values are strings. Unknown values are empty strings.
- property release_name_params
Release name without title and year or season/episode info
This allows us to find stuff in the release name that guessit doesn’t support without accidentally finding it in the title.
- class upsies.utils.release.ReleaseName(path, *, name=None, translate=None, separator=None, english_title_before_original=False)[source]
Bases:
MappingStandardized release name
- Parameters:
path (str) –
Path to release file or directory
If
pathexists, it is used to read video and audio metadata, e.g. to detect the codecs, resolution, etc.name (str) – Path or other string to pass to
ReleaseInfo(defaults to path)translate (dict) –
Map names of properties that return a string (e.g.
audio_format) to maps of regular expressions to replacement strings. The replacement strings may contain backreferences to groups in their regular expression.Example:
>>> { >>> 'audio_format': { >>> re.compile(r'^DDP$'): r'DD+', >>> }, >>> 'video_format': { >>> re.compile(r'^x26([45])$'): r'H.26\1', >>> }, >>> }
separator (str) – Separator between release name parts (usually “ “ or “.”) or None to use the default
Example:
>>> rn = ReleaseName("path/to/The.Foo.1984.1080p.Blu-ray.X264-ASDF") >>> rn.source 'BluRay' >>> rn.format() 'The Foo 1984 1080p BluRay DTS x264-ASDF' >>> "{title} ({year}) [{group}]".format(**rn) 'The Foo (1984) [ASDF]' >>> rn.set_name('The Foo 1985 1080p BluRay DTS x264-AsdF') >>> "{title} ({year}) [{group}]".format(**rn) 'The Foo (1985) [AsdF]'
- property release_info
Internal
ReleaseInfoinstance
- set_release_info(path)[source]
Update internal
ReleaseInfoinstance- Parameters:
path – Argument for
ReleaseInfo(path or any other string)
- property separator
Separator between release name parts (usually “ “ or “.”) or None to use the default
- property type
ReleaseTypeenum or one of its value namesSee also
fetch_info().
- title[source]
Original name of movie or series or “UNKNOWN_TITLE”
See also
fetch_info().
- title_aka[source]
Alternative name of movie or series or empty string
For non-English original titles, this should be the English title. If
titleis identical, this is an empty string.See also
fetch_info().
- property english_title_before_original
Whether the English title is left of “AKA” and the original title is right of “AKA” in
title_with_akaIf there is no
title_aka, this has no effect.
- title_with_aka[source]
Combination of
titleandtitle_akaSee also
english_title_before_original.
- title_with_aka_and_year[source]
Combination of
title_with_akawithcountryandyearif appropriateIf
dateis specified, it is appended totitle_with_aka. Otherwise, ifyear_requiredis True,yearis appended.If
country_requiredis True,countryis appended.In summary: This should provide a unique identifier for humans.
- year[source]
Release year or “UNKNOWN_YEAR” if
year_requiredis set, empty string otherwiseSee also
fetch_info().
- property year_required
Whether
title_with_aka_and_yearincludesyearSee also
fetch_info().
- country[source]
Release country or “UNKNOWN_COUNTRY” if
country_requiredis set, empty string otherwiseSee also
fetch_info().
- property country_required
Whether
title_with_aka_and_yearincludescountrySee also
fetch_info().
- episodes[source]
Season and episodes in “S01E02”-style format or “UNKNOWN_SEASON” for season packs, “UNKNOWN_EPISODE” for episodes, empty string for other types
This property can be set to one or more season numbers (
str,intor sequence of those), a “S01E02”-style string (seeEpisodes.from_string()) or any falsy value.
- property only_season
Season if there is only one season in
episodes_dict, None otherwise
- date[source]
Date (YYYY-MM-DD)
Sometimes single episodes are not released as part of a season but with an air date to identify them.
For episodes, this should be the air date or an empty string.
For anything that isn’t an episode, this is always an empty string.
- edition[source]
List of “Director’s Cut”, “Uncut”, “Unrated”, etc
- Raises:
ContentError – if
pathexists but contains unexpected data
- resolution[source]
Resolution (e.g. “1080p”) or “UNKNOWN_RESOLUTION”
- Raises:
ContentError – if
pathexists but contains unexpected data
- property resolution_int
Same as
resolution, but asintor None if it cannot be determined
- audio_format[source]
Audio format (e.g. “FLAC”) or empty string (no audio track) or “UNKNOWN_AUDIO_FORMAT”
- Raises:
ContentError – if
pathexists but contains unexpected data
- audio_channels[source]
Audio channels (e.g. “5.1”) or empty string (no audio track)
- Raises:
ContentError – if
pathexists but contains unexpected data
- hdr_format[source]
HDR format name (e.g. “DV” or “HDR10”) or empty string
If not set explicitly and
pathexists, this value is autodetected if possible, otherwise default to whateverReleaseInfodetected in the release name.Setting this value back to None turns on autodetection as described above.
- Raises:
ContentError – if
pathexists but contains unexpected data
- video_format[source]
Video format (or encoder in case of x264/x265/XviD) or “UNKNOWN_VIDEO_FORMAT”
- Raises:
ContentError – if
pathexists but contains unexpected data
- container[source]
Container format or “UNKNOWN_CONTAINER_FORMAT”
See
get_container_format`()for possible return values.- Raises:
ContentError – if
pathexists but contains unexpected data
- group[source]
Name of release group or “NOGROUP”
“NOGRP”, and “” are translated to “NOGROUP” case-insensitively.
- property has_commentary
Whether this release has a commentary audio track
If not set explicitly and :attr:`path` exists, this value is autodetected by looking for “commentary” case-insensitively in any audio track title.
If not set explicitly and
pathdoes not exists, default to detection byReleaseInfo.Setting this value to None turns on autodetection as described above.
- Raises:
ContentError – if
pathexists but contains unexpected data
- property has_dual_audio
Whether this release has an English and a non-English audio track
If not set explicitly and
pathexists, this value is autodetected if possible, otherwise default to whateverReleaseInfodetected in the release name.Setting this value back to None turns on autodetection as described above.
- Raises:
ContentError – if
pathexists but contains unexpected data
- property dvd_resolution
“PAL” or “NTSC” for DVD release or None for non-DVD release
- property is_complete
Whether all needed information is known and the string returned by
format()will not contain “UNKNOWN_*”This always returns False if
typeisunknown.
- async fetch_info(*, webdb, webdb_id, callback=None)[source]
Fill in information web database
- Parameters:
webdb –
WebDbApiBaseinstance (seewebdb)webdb_id (str) – Valid ID for webdb
callback (callable) – Function to call after info was fetched; gets the instance (self) as a keyword argument
Attempt to set these attributes if they are supported by webdb:
year_required(IMDb only)country_required(IMDb only)
- Returns:
The method’s instance (self) for convenience