tvrenamer.core package¶
Submodules¶
tvrenamer.core.episode module¶
Represents the state of a TV Episode based on a filename and additional information from a data service.
Available actions on the Episode:
parse: retrieve information about TV Episode from elements of name
enhance: lookup additional information based on parsed elements
- rename: change the name of file based on most up-to-date info
and optionally change location.
The only input is an absolute path of a filename. Everything is controlled via the provided configuration.
-
class
tvrenamer.core.episode.Episode(epfile)¶ Bases:
objectRepresents a TV episode.
Parameters: epfile (str) – absolute path and filename of media file -
api¶
-
as_dict()¶
-
enhance(*args, **kwargs)¶ Load metadata from a data service to improve naming.
Raises: - tvrenamer.exceptions.ShowNotFound – when unable to find show/series name based on parsed name
- tvrenamer.exceptions.EpisodeNotFound – when unable to find episode name(s) based on parsed data
-
format_name(*args, **kwargs)¶ Formats the media file based on enhanced metadata.
The actual name of the file and even the name of the directory structure where the file is to be stored.
-
parse(*args, **kwargs)¶ Extracts component keys from filename.
Raises: - tvrenamer.exceptions.InvalidFilename – when filename was not parseable
- tvrenamer.exceptions.ConfigValueError – when regex used for parsing was incorrectly configured
-
rename(*args, **kwargs)¶ Renames media file to formatted name.
After parsing data from initial media filename and searching for additional data to using a data service, a formatted filename will be generated and the media file will be renamed to the generated name and optionally relocated.
-
status¶ Provides current status of processing episode.
Structure of status:
original_filename => formatted_filename, state, messagesReturns: mapping of current processing state Return type: dict
-
-
tvrenamer.core.episode.state(pre, post, attr='state')¶ State decorator
tvrenamer.core.formatter module¶
-
tvrenamer.core.formatter.apply_replacements(cfile, replacements)¶ Applies custom replacements.
- mapping(dict), where each dict contains:
‘match’ - filename match pattern to check against, the filename replacement is applied.
‘replacement’ - string used to replace the matched part of the filename
‘is_regex’ - if True, the pattern is treated as a regex. If False, simple substring check is used (if ‘match’ in filename). Default is False
‘with_extension’ - if True, the file extension is not included in the pattern matching. Default is False
Example replacements:
{'match': ':', 'replacement': '-', 'is_regex': False, 'with_extension': False, }
Parameters: - cfile (str) – name of a file
- replacements (list) – mapping(dict) filename pattern matching directives
Returns: formatted filename
Return type: str
-
tvrenamer.core.formatter.clean_series_name(seriesname)¶ Cleans up series name.
By removing any . and _ characters, along with any trailing hyphens.
Is basically equivalent to replacing all _ and . with a space, but handles decimal numbers in string, for example:
>>> _clean_series_name("an.example.1.0.test") 'an example 1.0 test' >>> _clean_series_name("an_example_1.0_test") 'an example 1.0 test'
-
tvrenamer.core.formatter.find_library(series_path)¶ Search for the location of a series within the library.
Parameters: series_path (str) – name of the relative path of the series Returns: library path Return type: str
-
tvrenamer.core.formatter.format_dirname(series_name, season_number)¶ Generates a directory name based on metadata using configured format.
Parameters: - series_name (str) – name of TV series
- season_number (int) – the numeric season of series
Returns: formatted directory name using input values and configured format
Return type: str
-
tvrenamer.core.formatter.format_filename(series_name, season_number, episode_numbers, episode_names, extension)¶ Generates a filename based on metadata using configured format.
Parameters: - series_name (str) – name of TV series
- season_number (int) – the numeric season of series
- episode_numbers (list(int)) – the numeric episode of the series
- episode_names (list(str)) – episode title of the series
- extension (str) – media file extension
Returns: formatted filename using input values and configured format
Return type: str
-
tvrenamer.core.formatter.format_location(series_name, season_number)¶
tvrenamer.core.parser module¶
-
tvrenamer.core.parser.parse_filename(filename)¶ Parse media filename for metadata.
Parameters: filename (str) – the name of media file Returns: dict of metadata attributes found in filename or None if no matching expression. Return type: dict
tvrenamer.core.patterns module¶
Regular expression patterns for filename formats.
Supported filename formats:
* Sample.Show.S01E01.S01E02.S01E03.S01E04.eps.mp4
* Sample-Show.S02e22e23e24.avi
* Sample.Show.3x12.3x13.3x14.avi
* Sample.Show.4x4x5x6.mp4
* Sample.Show.S02E11-15-stuff.mkv
* Sample-Show.2x11-15.avi
* Sample-Show.[3x11-13].mp4
* Sample.Show-[013].avi
* Sample.S0202.mp4
* Sample_Show-7x17.avi
* Sample-Show S09.E11.mkv
* Sample-Show S09_E11.mkv
* Sample-Show S09 - E11.mkv
* Sample_Show-[09.01].avi
* Sample.Show - S9 E 9.avi
* SampleShow - episode 1219 [S 13 - E 07].mkv
* SampleShow - episode 1219 [S 13 Ep 07].avi
* Sample Show 2 of 7.mp4
* Sample.Show.Part.1.and.Part.2.avi
* Sample.Show.pt.1 & pt 2 & pt.3.avi
* Sample Show part 5.mkv
* Sample.Show season 10 episode 15.mp4
* Sample Show 909.mkv
* Sample Show 1011.avi
* Sample Show e19.mp4
-
tvrenamer.core.patterns.get_expressions()¶ Retrieve compiled pattern expressions.
Returns: compiled regular expressions for supported filename formats Return type: list
tvrenamer.core.renamer module¶
-
tvrenamer.core.renamer.execute(filename, formatted_name)¶ Renames a file based on the name generated using metadata.
Parameters: - filename (str) – absolute path and filename of original file
- formatted_name (str) – absolute path and new filename
tvrenamer.core.watcher module¶
-
tvrenamer.core.watcher.retrieve_files()¶ Get list of files found in provided locations.
Search through the paths provided to find files for processing.
Returns: absolute path of filename Return type: list