-
Notifications
You must be signed in to change notification settings - Fork 2
/
mkvscore
executable file
·54 lines (40 loc) · 1.35 KB
/
mkvscore
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
#!/usr/bin/env python
from ffmpipe import input
import sys
left,right = [], []
def overlap(label, labelset):
if len(labelset) == 0:
return True
# assert ordered(labelset)
b = min(l.beg for l in labelset)
e = max(l.end for l in labelset)
return b <= label.beg < e or\
b <= label.end < e
#
# this is because input() just concatenates file, so when a new file is opened, the
# timecode in the labels are reset and subsequently wrong overlap are calculated, i.e.
# a label in file 1 might overlap a label in another file!
#
assert len(sys.argv) < 3, "maximum one input file, otherwise scores are incorrect!"
labels = []
subtitles = lambda s,_: s.codec_type == 'subtitle'
for a,b,*_ in input(select=subtitles):
if a is not None and 'smoking' in a.label:
labels.append(a)
a.left = True
if b is not None and 'smoking' in b.label:
labels.append(b)
b.left = False
labels = sorted(labels, key=lambda x: x.beg)
cmpset = []
for label in labels:
if not overlap(label, cmpset):
n = len([x for x in cmpset if x.left])
m = len(cmpset) - n
print( 'smoking smoking' if n>0 and m>0 else \
'NULL smoking' if n>0 else \
'smoking NULL' if m>0 else \
'' )
print( 'NULL NULL' )
cmpset = []
cmpset.append(label)