API Reference
This section contains the automatically generated API documentation for MKV Episode Matcher.
Core Modules
mkv_episode_matcher.episode_matcher
Classes
Functions
process_show
Process the show using streaming speech recognition with OCR fallback.
Source code in mkv_episode_matcher/episode_matcher.py
TMDB Client
mkv_episode_matcher.tmdb_client
Classes
RateLimitedRequest
A class that represents a rate-limited request object.
ATTRIBUTE | DESCRIPTION |
---|---|
rate_limit |
Maximum number of requests allowed per period.
TYPE:
|
period |
Period in seconds.
TYPE:
|
requests_made |
Counter for requests made.
TYPE:
|
start_time |
Start time of the current period.
TYPE:
|
lock |
Lock for synchronization.
TYPE:
|
Source code in mkv_episode_matcher/tmdb_client.py
Functions
get
Sends a rate-limited GET request to the specified URL.
PARAMETER | DESCRIPTION |
---|---|
url
|
The URL to send the request to.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Response
|
The response object returned by the request. |
Source code in mkv_episode_matcher/tmdb_client.py
Functions
fetch_show_id
Fetch the TMDb ID for a given show name.
PARAMETER | DESCRIPTION |
---|---|
show_name
|
The name of the show.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The TMDb ID of the show, or None if not found. |
Source code in mkv_episode_matcher/tmdb_client.py
fetch_season_details
Fetch the total number of episodes for a given show and season from the TMDb API.
PARAMETER | DESCRIPTION |
---|---|
show_id
|
The ID of the show on TMDb.
TYPE:
|
season_number
|
The season number to fetch details for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The total number of episodes in the season, or 0 if the API request failed. |
Source code in mkv_episode_matcher/tmdb_client.py
get_number_of_seasons
Retrieves the number of seasons for a given TV show from the TMDB API.
Parameters: - show_id (int): The ID of the TV show.
Returns: - num_seasons (int): The number of seasons for the TV show.
Raises: - requests.HTTPError: If there is an error while making the API request.
Source code in mkv_episode_matcher/tmdb_client.py
MKV Converter
mkv_episode_matcher.mkv_to_srt
Functions
check_if_processed
Check if the file has already been processed (has SxxExx format)
PARAMETER | DESCRIPTION |
---|---|
filename
|
Filename to check
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if file is already processed
TYPE:
|
Source code in mkv_episode_matcher/mkv_to_srt.py
convert_mkv_to_sup
Convert an .mkv file to a .sup file using FFmpeg and pgs2srt.
PARAMETER | DESCRIPTION |
---|---|
mkv_file
|
Path to the .mkv file.
TYPE:
|
output_dir
|
Path to the directory where the .sup file will be saved.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Path to the converted .sup file. |
Source code in mkv_episode_matcher/mkv_to_srt.py
perform_ocr
Perform OCR on a .sup file and save the extracted text to a .srt file. Returns the path to the created SRT file.
Source code in mkv_episode_matcher/mkv_to_srt.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
extract_subtitles
Extract subtitles from MKV file based on detected subtitle type.
Source code in mkv_episode_matcher/mkv_to_srt.py
convert_mkv_to_srt
Convert subtitles from MKV files to SRT format.
Source code in mkv_episode_matcher/mkv_to_srt.py
detect_subtitle_type
Detect the type and index of subtitle streams in an MKV file.
Source code in mkv_episode_matcher/mkv_to_srt.py
Utilities
mkv_episode_matcher.utils
Functions
get_valid_seasons
Get all season directories that contain MKV files.
PARAMETER | DESCRIPTION |
---|---|
show_dir
|
Base directory for the TV show
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
List of paths to valid season directories |
Source code in mkv_episode_matcher/utils.py
check_filename
Check if the filename is in the correct format (S01E02).
PARAMETER | DESCRIPTION |
---|---|
filename
|
The filename to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the filename matches the expected pattern. |
Source code in mkv_episode_matcher/utils.py
scramble_filename
Scrambles the filename of the given file path by adding the series title and file number.
PARAMETER | DESCRIPTION |
---|---|
original_file_path
|
The original file path.
TYPE:
|
file_number
|
The file number to be added to the filename.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mkv_episode_matcher/utils.py
rename_episode_file
Rename an episode file with a standardized naming convention.
PARAMETER | DESCRIPTION |
---|---|
original_file_path
|
The original file path of the episode.
TYPE:
|
new_filename
|
The new filename including season/episode info.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Path to the renamed file, or None if rename failed. |
Source code in mkv_episode_matcher/utils.py
get_subtitles
Retrieves and saves subtitles for a given TV show and seasons.
PARAMETER | DESCRIPTION |
---|---|
show_id
|
The ID of the TV show.
TYPE:
|
seasons
|
A set of season numbers for which subtitles should be retrieved.
TYPE:
|
Source code in mkv_episode_matcher/utils.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
cleanup_ocr_files
Clean up OCR files generated during the episode matching process.
PARAMETER | DESCRIPTION |
---|---|
show_dir
|
The directory containing the show files.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
This function cleans up the OCR files generated during the episode matching process. It deletes the 'ocr' directory and all its contents in each season directory of the show.
Source code in mkv_episode_matcher/utils.py
process_reference_srt_files
Process reference SRT files for a given series.
PARAMETER | DESCRIPTION |
---|---|
series_name
|
The name of the series.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the reference files where the keys are the MKV filenames and the values are the corresponding SRT texts. |
Source code in mkv_episode_matcher/utils.py
extract_srt_text
Extracts text content from an SRT file.
PARAMETER | DESCRIPTION |
---|---|
filepath
|
Path to the SRT file.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
List of text lines from the SRT file. |
Source code in mkv_episode_matcher/utils.py
extract_season_episode
Extract season and episode numbers from filename.
PARAMETER | DESCRIPTION |
---|---|
filename
|
Filename to parse
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
(season_number, episode_number) |
Source code in mkv_episode_matcher/utils.py
process_srt_files
Process all SRT files in the given directory and its subdirectories.
PARAMETER | DESCRIPTION |
---|---|
show_dir
|
The directory path where the SRT files are located.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the SRT file paths as keys and their corresponding text content as values. |
Source code in mkv_episode_matcher/utils.py
compare_and_rename_files
Compare the srt files with the reference files and rename the matching mkv files.
PARAMETER | DESCRIPTION |
---|---|
srt_files
|
A dictionary containing the srt files as keys and their contents as values.
TYPE:
|
reference_files
|
A dictionary containing the reference files as keys and their contents as values.
TYPE:
|
dry_run
|
If True, the function will only log the renaming actions without actually renaming the files. Defaults to False.
TYPE:
|
Source code in mkv_episode_matcher/utils.py
compare_text
Compare two lists of text lines and return the number of matching lines.
PARAMETER | DESCRIPTION |
---|---|
text1
|
List of text lines from the first source.
TYPE:
|
text2
|
List of text lines from the second source.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
Number of matching lines between the two sources. |
Source code in mkv_episode_matcher/utils.py
Configuration
mkv_episode_matcher.config
Functions
set_config
set_config(tmdb_api_key, open_subtitles_api_key, open_subtitles_user_agent, open_subtitles_username, open_subtitles_password, show_dir, file, tesseract_path=None)
Sets the configuration values and writes them to a file.
PARAMETER | DESCRIPTION |
---|---|
tmdb_api_key
|
The API key for TMDB (The Movie Database).
TYPE:
|
open_subtitles_api_key
|
The API key for OpenSubtitles.
TYPE:
|
open_subtitles_user_agent
|
The user agent for OpenSubtitles.
TYPE:
|
open_subtitles_username
|
The username for OpenSubtitles.
TYPE:
|
open_subtitles_password
|
The password for OpenSubtitles.
TYPE:
|
show_dir
|
The directory where the TV show episodes are located.
TYPE:
|
file
|
The path to the configuration file.
TYPE:
|
tesseract_path
|
The path to the Tesseract OCR executable.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mkv_episode_matcher/config.py
get_config
Read and return the configuration from the specified file.
PARAMETER | DESCRIPTION |
---|---|
file
|
The path to the configuration file.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
The configuration settings as a dictionary. |