-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkvedit
53 lines (38 loc) · 1.92 KB
/
mkvedit
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
#!/usr/bin/python3
# Script to encode/remux multiple video files.
# Edit the first three variables accordingly.
# Dependencies: Python 3, [FFmpeg/mkvmerge].
import os
import mimetypes
from shlex import split
import subprocess
# edit the variables: inputFilename, outputFilename, mkvcmd
# common string in the input filename
# that is ALSO NOT in the `outputFilename` below IF POSSIBLE; else remove the files that were generated by this script before running it again when some error happens.
inputFilename = 'YURASUKA'
# output filename format
outputFilename = 'Overlord - S01E{episode}.mkv'
# copy the mkv cmd, remove --title, and insert {output} & {input} in proper place.
mkvcmd = "mkvmerge --ui-language en_US --priority lower --output '{output}' --audio-tracks 2 --subtitle-tracks 6 --language 0:ja --track-name '0:YURASUKA 1080p x265' --display-dimensions 0:1920x1080 --language 2:ja --track-name '2:Japanese FLAC 2.0' --sub-charset 6:UTF-8 --language 6:en --track-name '6:Full Subtitles (SallySubs)' '{input}' --track-order 0:0,0:2,0:6"
def filterVid(file):
fullPath = os.path.join(os.getcwd(), file)
guessType = mimetypes.guess_type(fullPath)
isFile = os.path.isfile(fullPath)
isNotNoneType = guessType[0] is not None
isTypeMatched = isNotNoneType and (
'video' in guessType[0] or file.endswith('.ts')) # *.ts files are wrongly(?) identified by mimetypes as 'text'.
isCorrectInput = inputFilename in file
if isFile and isTypeMatched and isCorrectInput:
return True
else:
return False
listdir = os.listdir()
filteredDir = list(filter(filterVid, listdir))
filteredDir.sort()
for idx, file in enumerate(filteredDir, start=1):
numbering = "0" + str(idx) if (idx < 10) else idx
outputFormat = outputFilename.format(episode=numbering)
cmdFormat = mkvcmd.format(input=file, output=outputFormat)
cmdArr = split(cmdFormat)
print("\n", cmdArr, "\n")
# subprocess.run(cmdArr)