API Reference
This section contains the automatically generated API documentation for MKV Episode Matcher.
Core Modules
mkv_episode_matcher.__main__
Functions
print_welcome_message
Print a stylized welcome message.
Source code in mkv_episode_matcher/__main__.py
confirm_api_key
Confirm if the user wants to use an existing API key or enter a new one.
PARAMETER | DESCRIPTION |
---|---|
config_value
|
The current value from the config
TYPE:
|
key_name
|
The name of the key
TYPE:
|
description
|
Description of the key for user information
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The API key to use |
Source code in mkv_episode_matcher/__main__.py
mask_api_key
select_season
Allow user to select a season from a list.
PARAMETER | DESCRIPTION |
---|---|
seasons
|
List of available seasons
|
RETURNS | DESCRIPTION |
---|---|
Selected season number or None for all seasons |
Source code in mkv_episode_matcher/__main__.py
main
Entry point of the application with enhanced user interface.
Source code in mkv_episode_matcher/__main__.py
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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
mkv_episode_matcher.episode_matcher
Classes
Functions
process_show
Process the show using streaming speech recognition with improved UI feedback.
PARAMETER | DESCRIPTION |
---|---|
season
|
Season number to process. Defaults to None (all seasons).
TYPE:
|
dry_run
|
If True, only simulate actions without making changes.
TYPE:
|
get_subs
|
If True, download subtitles for the show.
TYPE:
|
verbose
|
If True, display more detailed progress information.
TYPE:
|
confidence
|
Confidence threshold for episode matching (0.0-1.0).
TYPE:
|
Source code in mkv_episode_matcher/episode_matcher.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 |
|
mkv_episode_matcher.episode_identification
Classes
SubtitleCache
Cache for storing parsed subtitle data to avoid repeated loading and parsing.
Source code in mkv_episode_matcher/episode_identification.py
Functions
get_subtitle_content
Get the full content of a subtitle file, loading it only once.
Source code in mkv_episode_matcher/episode_identification.py
get_chunk
Get a specific time chunk from a subtitle file, with caching.
Source code in mkv_episode_matcher/episode_identification.py
EpisodeMatcher
Source code in mkv_episode_matcher/episode_identification.py
Functions
extract_audio_chunk
Extract a chunk of audio from MKV file with caching.
Source code in mkv_episode_matcher/episode_identification.py
load_reference_chunk
Load reference subtitles for a specific time chunk with caching.
PARAMETER | DESCRIPTION |
---|---|
srt_file
|
Path to the SRT file
TYPE:
|
chunk_idx
|
Index of the chunk to load
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Combined text from the subtitle chunk |
Source code in mkv_episode_matcher/episode_identification.py
get_reference_files
Get reference subtitle files with caching.
Source code in mkv_episode_matcher/episode_identification.py
identify_episode
Progressive episode identification with faster initial attempt.
Source code in mkv_episode_matcher/episode_identification.py
SubtitleReader
Helper class for reading and parsing subtitle files.
Functions
parse_timestamp
staticmethod
Parse SRT timestamp into seconds.
read_srt_file
staticmethod
Read an SRT file and return its contents with robust encoding handling.
PARAMETER | DESCRIPTION |
---|---|
file_path
|
Path to the SRT file
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Contents of the SRT file |
Source code in mkv_episode_matcher/episode_identification.py
extract_subtitle_chunk
staticmethod
Extract subtitle text for a specific time window.
PARAMETER | DESCRIPTION |
---|---|
content
|
Full SRT file content
TYPE:
|
start_time
|
Chunk start time in seconds
TYPE:
|
end_time
|
Chunk end time in seconds
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
List of subtitle texts within the time window |
Source code in mkv_episode_matcher/episode_identification.py
Functions
get_video_duration
cached
Get video duration with caching.
Source code in mkv_episode_matcher/episode_identification.py
detect_file_encoding
Detect the encoding of a file using chardet.
PARAMETER | DESCRIPTION |
---|---|
file_path
|
Path to the file
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Detected encoding, defaults to 'utf-8' if detection fails |
Source code in mkv_episode_matcher/episode_identification.py
read_file_with_fallback
cached
Read a file trying multiple encodings in order of preference.
PARAMETER | DESCRIPTION |
---|---|
file_path
|
Path to the file
TYPE:
|
encodings
|
List of encodings to try, defaults to common subtitle encodings
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
File contents |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If file cannot be read with any encoding |
Source code in mkv_episode_matcher/episode_identification.py
get_whisper_model
Cache whisper models to avoid reloading.
Source code in mkv_episode_matcher/episode_identification.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
Utilities
mkv_episode_matcher.utils
Functions
normalize_path
Normalize a path string to handle cross-platform path issues. Properly handles trailing slashes and backslashes in both Windows and Unix paths.
PARAMETER | DESCRIPTION |
---|---|
path_str
|
The path string to normalize
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
pathlib.Path: A normalized Path object |
Source code in mkv_episode_matcher/utils.py
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 |
---|---|
Path
|
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:
|
config
|
Preloaded configuration.
TYPE:
|
Source code in mkv_episode_matcher/utils.py
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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
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 with support for multiple formats.
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)
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:
|
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. |