-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTypeTrack.py
81 lines (73 loc) · 1.96 KB
/
TypeTrack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pymkv.MKVTrack import MKVTrack
type_files = {
"video": {
"V_MPEG1": "mpg",
"V_MPEG2": "mpg",
"V_MPEG4/ISO/AVC": "264",
"MPEG-4p10": "h264",
"HEVC": "h265",
"V_MS/VFW/FOURCC": "avi",
"V_REAL": "rm",
"V_THEORA": "ogg",
"V_VP8": "ivf",
"V_VP9": "ivf",
"AVC/H.264/MPEG-4p10": "mp4",
},
"audio": {
"AAC": "aac",
"AC3": "ac3",
"AC-3": "ac3",
"ALAC": "caf",
"DTS": "dts",
"FLAC": "flac",
"MPEG/L2": "mp2",
"MPEG/L3": "mp3",
"OPUS": "ogg",
"PCM": "wav",
"REAL": "ra",
"TRUEHD": "thd",
"MLP": "mlp",
"TTA1": "tta",
"VORBIS": "ogg",
"WAVPACK4": "wv",
"V_MS/VFW/FOURCC, WVC1": "wvc",
"VC-1": "wvc",
"Vorbis": "ogg",
},
"subtitles": {
"PGS": "sup",
"ASS": "ass",
"SSA": "ssa",
"UTF8": "srt",
"SubRip/SRT": "srt",
"ASCII": "srt",
"VOBSUB": "sub",
"USF": "usf",
"WEBVTT": "vtt",
},
}
def get_track_extension(track: MKVTrack) -> str | None:
"""
Get the file extension for a given MKVTrack.
Parameters
----------
track : MKVTrack
The MKVTrack object from which to determine the file extension.
Returns
-------
str | None
The file extension corresponding to the track's type and codec, or None if not found.
Notes
-----
This function uses the track's type and codec to look up the appropriate
file extension in the `type_files` dictionary. If no matching extension
is found, it returns None.
"""
track_type = track.track_type
track_codec = track.track_codec
if track_type in type_files and track_codec in type_files[track_type]:
return type_files[track_type][track_codec]
return None