API Reference
This section contains the automatically generated API documentation for MKV Episode Matcher.
Core Modules
mkv_episode_matcher.__main__
mkv_episode_matcher.cli
Unified CLI Interface for MKV Episode Matcher V2
This module provides a single, intuitive command-line interface that handles all use cases with intelligent auto-detection and minimal configuration.
Functions
print_banner
match
match(
path=typer.Argument(
...,
help="Path to MKV file, series folder, or entire library",
exists=True,
),
season=typer.Option(
None,
"--season",
"-s",
help="Override season number for all files",
),
recursive=typer.Option(
True,
"--recursive/--no-recursive",
"-r/-nr",
help="Search recursively in directories",
),
dry_run=typer.Option(
False,
"--dry-run",
"-d",
help="Preview changes without renaming files",
),
output_dir=typer.Option(
None,
"--output-dir",
"-o",
help="Copy renamed files to this directory instead of renaming in place",
),
json_output=typer.Option(
False,
"--json",
help="Output results in JSON format for automation",
),
confidence_threshold=typer.Option(
None,
"--confidence",
"-c",
min=0.0,
max=1.0,
help="Minimum confidence score for matches (0.0-1.0)",
),
download_subs=typer.Option(
True,
"--download-subs/--no-download-subs",
help="Automatically download subtitles if not found locally",
),
tmdb_id=typer.Option(
None,
"--tmdb-id",
help="Manually specify the TMDB Show ID (e.g. 549 for Law & Order)",
),
log_level=typer.Option(
"INFO",
"--log-level",
"-l",
help="Set logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
case_sensitive=False,
),
)
Process MKV files with intelligent episode matching.
Automatically detects whether you're processing: • A single file • A series folder • An entire library
Examples:
# Process a single file
mkv-match episode.mkv
# Process a series season
mkv-match "/media/Breaking Bad/Season 1/"
# Process entire library
mkv-match /media/tv-shows/ --recursive
# Dry run with custom output
mkv-match episode.mkv --dry-run --output-dir ./renamed/
# Automation mode
mkv-match show/ --json --confidence 0.8
Source code in mkv_episode_matcher/cli.py
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 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 | |
config
config(
show_cache_dir=typer.Option(
False,
"--show-cache-dir",
help="Show current cache directory location",
),
reset=typer.Option(
False,
"--reset",
help="Reset configuration to defaults",
),
)
Configure MKV Episode Matcher settings.
Most settings are auto-configured, but you can customize: • Cache directory location • Default confidence thresholds • ASR model preferences
Source code in mkv_episode_matcher/cli.py
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 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
info
Show system information and available models.
Source code in mkv_episode_matcher/cli.py
version
Show version information.
Source code in mkv_episode_matcher/cli.py
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 and error handling.
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
mkv_episode_matcher.asr_models
ASR Model Abstraction Layer
This module provides a unified interface for different Automatic Speech Recognition models, including OpenAI Whisper and NVIDIA Parakeet models.
Classes
ASRModel
Bases: ABC
Abstract base class for ASR models.
Initialize ASR model.
| PARAMETER | DESCRIPTION |
|---|---|
model_name
|
Name/identifier of the model
TYPE:
|
device
|
Device to run on ('cpu', 'cuda', or None for auto-detect)
TYPE:
|
Source code in mkv_episode_matcher/asr_models.py
Attributes
Functions
load
abstractmethod
transcribe
abstractmethod
Transcribe audio file.
| PARAMETER | DESCRIPTION |
|---|---|
audio_path
|
Path to audio file
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Dictionary with at least 'text' key containing transcription |
Source code in mkv_episode_matcher/asr_models.py
calculate_match_score
Calculate similarity score between transcription and reference.
| PARAMETER | DESCRIPTION |
|---|---|
transcription
|
Transcribed text
TYPE:
|
reference
|
Reference subtitle text
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Float score between 0.0 and 1.0 |
Source code in mkv_episode_matcher/asr_models.py
ParakeetTDTModel
Bases: ASRModel
NVIDIA Parakeet TDT ASR model implementation.
WARNING: This model (TDT) uses the Transducer decoder which requires significant GPU resources and may be unstable on some Windows configurations (CUDA errors).
Initialize Parakeet TDT model.
| PARAMETER | DESCRIPTION |
|---|---|
model_name
|
Parakeet model identifier from HuggingFace
TYPE:
|
device
|
Device to run on
TYPE:
|
Source code in mkv_episode_matcher/asr_models.py
Attributes
Functions
load
Load Parakeet model with caching.
Source code in mkv_episode_matcher/asr_models.py
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 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 | |
calculate_match_score
Calculate similarity score with Parakeet-specific weights. Parakeet produces longer, more detailed transcriptions, so we favor partial matches.
Source code in mkv_episode_matcher/asr_models.py
transcribe
Transcribe audio using Parakeet with preprocessing and text normalization.
| PARAMETER | DESCRIPTION |
|---|---|
audio_path
|
Path to audio file
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Dictionary with 'text' and 'segments' from Parakeet |
Source code in mkv_episode_matcher/asr_models.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
ParakeetCTCModel
Bases: ParakeetTDTModel
NVIDIA Parakeet CTC ASR model implementation.
This uses the CTC decoder which is more stable and robust on various hardware than the TDT version, though potentially slightly less accurate.
Initialize Parakeet CTC model.
| PARAMETER | DESCRIPTION |
|---|---|
model_name
|
Parakeet model identifier (default: nvidia/parakeet-ctc-0.6b)
TYPE:
|
device
|
Device to run on
TYPE:
|
Source code in mkv_episode_matcher/asr_models.py
Attributes
Functions
load
Load Parakeet CTC model with caching.
Source code in mkv_episode_matcher/asr_models.py
transcribe
Transcribe audio using Parakeet with preprocessing and text normalization.
| PARAMETER | DESCRIPTION |
|---|---|
audio_path
|
Path to audio file
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Dictionary with 'text' and 'segments' from Parakeet |
Source code in mkv_episode_matcher/asr_models.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
calculate_match_score
Calculate similarity score with Parakeet-specific weights. Parakeet produces longer, more detailed transcriptions, so we favor partial matches.
Source code in mkv_episode_matcher/asr_models.py
Functions
create_asr_model
Factory function to create ASR models from configuration.
| PARAMETER | DESCRIPTION |
|---|---|
model_config
|
Dictionary with 'type' and 'name' keys
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ASRModel
|
Configured ASRModel instance |
Example
model_config = {"type": "parakeet", "name": "nvidia/parakeet-ctc-0.6b"} model = create_asr_model(model_config)
Source code in mkv_episode_matcher/asr_models.py
get_cached_model
Get a cached model instance, creating it if necessary.
| PARAMETER | DESCRIPTION |
|---|---|
model_config
|
Dictionary with model configuration
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ASRModel
|
ASRModel instance (loaded and ready for use) |
Source code in mkv_episode_matcher/asr_models.py
clear_model_cache
Clear all cached models to free memory.
Source code in mkv_episode_matcher/asr_models.py
list_available_models
List available model types and their requirements.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Dictionary with model types and their availability status |
Source code in mkv_episode_matcher/asr_models.py
mkv_episode_matcher.subtitle_utils
Functions
generate_subtitle_patterns
Generate various common subtitle filename patterns.
| PARAMETER | DESCRIPTION |
|---|---|
series_name
|
Name of the series
TYPE:
|
season
|
Season number
TYPE:
|
episode
|
Episode number
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List[str]: List of possible subtitle filenames |
Source code in mkv_episode_matcher/subtitle_utils.py
find_existing_subtitle
Check for existing subtitle files in various naming formats.
| PARAMETER | DESCRIPTION |
|---|---|
series_cache_dir
|
Directory containing subtitle files
TYPE:
|
series_name
|
Name of the series
TYPE:
|
season
|
Season number
TYPE:
|
episode
|
Episode number
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
Optional[str]: Path to existing subtitle file if found, None otherwise |
Source code in mkv_episode_matcher/subtitle_utils.py
sanitize_filename
Sanitize filename by removing/replacing invalid characters.
| PARAMETER | DESCRIPTION |
|---|---|
filename
|
Original filename
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Sanitized filename
TYPE:
|
Source code in mkv_episode_matcher/subtitle_utils.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
retry_network_operation
Decorator for retrying network operations.
Source code in mkv_episode_matcher/tmdb_client.py
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.
TYPE:
|
Source code in mkv_episode_matcher/tmdb_client.py
fetch_show_details
Fetch show details from TMDB by ID.
| PARAMETER | DESCRIPTION |
|---|---|
show_id
|
The TMDB show ID
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Show details including 'name', 'number_of_seasons', etc.
TYPE:
|
None
|
If request fails or API key not configured
TYPE:
|
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.
TYPE:
|
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. Also strips surrounding quotes that might be present in command line arguments.
| 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:
|
max_retries
|
Number of times to retry subtitle download on OpenSubtitlesException. Defaults to 3.
TYPE:
|
Source code in mkv_episode_matcher/utils.py
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 | |
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. |