Initial commit.

This commit is contained in:
Lukáš Kucharczyk 2020-09-25 16:49:45 +02:00
commit 754c533192
No known key found for this signature in database
GPG Key ID: 65524498C0196B64
8 changed files with 86 additions and 0 deletions

5
.prettierrc Normal file
View File

@ -0,0 +1,5 @@
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": true
}

8
README.md Normal file
View File

@ -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.

1
mkv_sub_fix/__init__.py Normal file
View File

@ -0,0 +1 @@
from .mkv_sub_fix import *

View File

@ -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")

15
pyproject.toml Normal file
View File

@ -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
tests/__init__.py Normal file
View File

0
tests/unit/__init__.py Normal file
View File

View File

@ -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()