Initial commit.
This commit is contained in:
commit
754c533192
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
# mkv-sub-fix
|
||||||
|
|
||||||
|
Easily assign language tags and descriptions to subtitle tracks in the Matroska container files.
|
||||||
|
|
||||||
|
# How it works
|
||||||
|
|
||||||
|
1. After running the program, it shows you a list of all subtitle tracks.
|
||||||
|
2. You go through each track, assigning it a language tag and optionally a description.
|
|
@ -0,0 +1 @@
|
||||||
|
from .mkv_sub_fix import *
|
|
@ -0,0 +1,27 @@
|
||||||
|
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")
|
|
@ -0,0 +1,15 @@
|
||||||
|
[tool.poetry]
|
||||||
|
name = "mkv-sub-fix"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Easily assign language tags to subtitles in .mkv files."
|
||||||
|
authors = ["Lukas Kucharczyk"]
|
||||||
|
license = "GPL-3.0-only"
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
python = "^3.8"
|
||||||
|
|
||||||
|
[tool.poetry.dev-dependencies]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry>=0.12"]
|
||||||
|
build-backend = "poetry.masonry.api"
|
|
@ -0,0 +1,30 @@
|
||||||
|
from mkv_sub_fix import *
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
class TestFileOpening(unittest.TestCase):
|
||||||
|
def testOpenExistingFile(self):
|
||||||
|
getListOfSubtitles("/home/lukas/Downloads/test5.mkv")
|
||||||
|
|
||||||
|
def testOpeningNonExistingFile(self):
|
||||||
|
with self.assertRaises(FileNotFoundError):
|
||||||
|
getListOfSubtitles("/nonexistent")
|
||||||
|
|
||||||
|
def testReturnListofSubtitles(self):
|
||||||
|
self.assertEqual(
|
||||||
|
getListOfSubtitles("/home/lukas/Downloads/test5.mkv"),
|
||||||
|
{
|
||||||
|
2: "eng",
|
||||||
|
3: "hun",
|
||||||
|
4: "ger",
|
||||||
|
5: "fre",
|
||||||
|
6: "spa",
|
||||||
|
7: "ita",
|
||||||
|
9: "jpn",
|
||||||
|
10: "und",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue