mkv-sub-fix/mkv_sub_fix/mkv_sub_fix.py

28 lines
686 B
Python
Raw Permalink Normal View History

2020-09-25 14:49:45 +00:00
import subprocess
import os
import json
def isMkvpropeditAvailable():
if subprocess.run("mkvpropedit"):
print("mkvpropedit exists.")
def getListOfSubtitles(filename):
if not os.path.exists(filename):
raise FileNotFoundError
result = subprocess.run(
["mkvmerge", "-i", filename, "-F", "json"], capture_output=True
)
if result.returncode == 0:
info = json.loads(result.stdout)
return {
track["id"]: track["properties"]["language"]
for track in info["tracks"]
if track["type"] == "subtitles"
}
if __name__ == "__main__":
getListOfSubtitles("/home/lukas/Downloads/test5.mkv")