-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcensor.py
More file actions
executable file
·109 lines (86 loc) · 2.59 KB
/
Copy pathcensor.py
File metadata and controls
executable file
·109 lines (86 loc) · 2.59 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/python
import subprocess
import sys
import os
def parseMkvInfo(strInput):
# split track info to array
arList = strInput.split('\n| + Track')
# remove non subtitle items
def filterString(string, target):
if string in target:
return target
arList = list(filter((lambda x: filterString('subtitles', x)), arList))
# seperate line data by spliting ':'
def splitStringColumns(listItem):
out = listItem.split(':')
if len(out) == 2:
return [str.replace(out[0], ' ', '_'), out[1]]
if len(out) == 3:
return [str.replace(out[0], ' ', '_'), out[2]]
else:
return False
def arrayToObject(list):
obj = {}
for item in list:
if(item):
obj.update({item[0]: item[1]})
return obj
# rename this
def splitString(listItem):
out = listItem.split('\n| + ')
# print(out)
out = list(map(splitStringColumns, out))
out = arrayToObject(out)
return out
arList = list(map(splitString, arList))
return arList
def help():
print('Need file name')
def printPrompt(x):
prompt = ""
try:
prompt += x['Language']
except:
prompt += ""
try:
prompt += " - " + x['Name']
except:
prompt += ""
try:
prompt += " : " + x['Track_number']
except:
prompt += ""
print(prompt)
def generateSrt():
# validate that argument was given
if len(sys.argv) < 2:
help()
return False
else:
# remove mkv file extension
arg = sys.argv[1][:-4]
# get data from mkvinfo
output = subprocess.check_output(
['mkvinfo', arg+'.mkv']).decode("utf-8")
output = subprocess.check_output(
['mkvinfo', arg+'.mkv']).decode("utf-8")
# parse track listing
arList = parseMkvInfo(output)
# print prompt
list(map(printPrompt, arList))
answer = input("Which track would you like to censor? (x to use user supplied .srt file)")
if answer == 'x':
return
command1 = arg + ".mkv"
command2 = answer + ":" + arg + ".srt"
subprocess.call(['mkvextract', 'tracks', command1, command2])
# output = subprocess.check_output(['mkvextract', 'tracks '+ command1+ ' '+ command2])
def generateEdl():
base_dir = os.path.dirname(os.path.realpath(__file__))
arg = sys.argv[1][:-4]
subprocess.call([base_dir + '/XBMC-Language-Filter/Linux/parse_srt.pl',
'--pad=0', "--offset=0", arg + ".srt"])
def main():
generateSrt()
generateEdl()
main()