forked from vdcrim/AvsP-macros
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MP_Pipeline.py
202 lines (176 loc) · 5.51 KB
/
MP_Pipeline.py
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import os
import os.path
import pyavs
import re
import sys
sel = ''
sep = '"'
global IsFuncOn
maxPrefetch = 64 # min 8
if maxPrefetch < 8:
maxPrefetch = 8
self = avsp.GetWindow()
MyBookmarks = ''
txt = ''
txt_lines =[]
tmp_lines = []
tmp_lines = avsp.GetText(index=None, clean=False).strip().encode(sys.getfilesystemencoding()).split('\n')
# remove MyBookmark lines and store it
for line in tmp_lines:
if line.find('#Bookmarks:') > -1:
MyBookmarks += line + '\n'
else :
txt += line + '\n'
txt_lines.append(line)
if txt == '':
return
# Get source file name if selected
sel = avsp.GetSelectedText()
if sel and not os.path.isdir(os.path.split(sel)[0]):
sel = ''
# if not sel, find source file name
if not sel:
i = txt.find('SourceFile : "')
if i < 0:
i = txt.find( 'ScriptDir()')
if i < 0:
i = txt.find('("')
if i > -1:
s = txt[i : len(txt)]
a =[]
a = s.split(sep)
sel = a[1]
if sel:
dir, file = os.path.split(sel)
if file:
sel = 'String(ScriptDir()) + ' + '"' + file + '"'
else:
sel = '"' + sel + '"'
def IsOn(s):
if s != '':
sp = s.split('\n')
for line in sp:
if not line.startswith('#'):
return True
return False
# Can find multiple Instances and func's with line breaks
def FindFunc3(fu, L=None, ignor=False, onlyOne=False):
global IsFuncOn
i = 0
rs = ''
while (i > -1) and (i < len(txt)-1):
i = txt.lower().find(fu.lower(), i)
if i > -1:
if (i > 0) and ((txt[i-1] == '#') and ignor): # skip if ignor
i += 1
continue
# skip if found funcName not word start eg. (TUnsharp, unsharp)
if (i > 0) and (txt[i-1] != '#') and (txt[i-1] != ' ') and (txt[i-1] != '\n'):
i += 1
continue
#dec found index if func disabled '#'
if (i > 0) and (txt[i-1] == '#'):
e = i-1
else:
e = i
s = txt[e : len(txt)]
### find funcEnd
a = 0; b = 0; e = 0
for x in range(0, len(s)):
if s[x] == '(':
a += 1
if s[x] == ')':
b += 1
if (a > 0) and (b >= a):
e = x
break
if e > 0:
i = i + e
# inc s to line endPos
while (e < len(s)) and (not s[e+1:e+2] in ['\n']):
e += 1
s = s[: e+1].strip()
if IsOn(s):
IsFuncOn = True
rs += s + '\n'
if onlyOne and IsOn(s):
break
else:
rs += '### Error cannot find funcEnd:' + fu + '\n'
i += 1
if rs != '':
rs = rs[:-1]
if L != None:
L.append(rs)
return rs
# can find multiple instances but cannot find func's with line breaks
def FindFunc2(fu, L=None, ignor=False, onlyOne=False):
rs = ''
for line in txt_lines:
i = line.lower().find(fu.lower())
if i > -1:
if (i > 0) and ((line[i-1] == '#') and ignor):
continue
else:
rs += line.strip() + '\n'
if onlyOne:
break
if rs != '':
rs = rs[:-1]
if (L != None) and (rs != ''):
L.append(rs)
return rs
# can only find one Instance of the func and no line breaks
def FindFunc(fu, L=None, ignor=False):
i = txt.lower().find(fu.lower())
if i > -1:
if (i > 0) and ((txt[i-1] == '#') and ignor):
return ''
if (txt[i-1] == '#'):
i = i-1
s = txt[i : len(txt)]
i = s.find(')')
if i > -1:
while (i < len(s)) and not (s[i+1:i+2] in ['\n']):
i += 1
if L != None:
L.append(s[0 : i+1].strip())
return s[0 : i+1].strip()
return ''
txt2 = ['']
txt2.append(r'MP_Pipeline("""')
txt2.append(r'### inherit start ###')
txt2.append(r'SourceFile = ' + sel)
txt2.append(r'SourceFile = Exist(SourceFile) ? SourceFile : "' + dir + '\\' + file + '"')
txt2.append(r'### inherit end ###')
txt2.append('')
s = FindFunc(r'LSMASHVideoSource', None, True)
if s:
txt2.append(r'LSMASHVideoSource(SourceFile)')
else:
txt2.append(r'LWLibavVideoSource(SourceFile, cache=False)')
FindFunc('SelectEven(', txt2)
txt2.append(r'# ### prefetch: ' + str(maxPrefetch) + ', ' + str(int(maxPrefetch/2)))
txt2.append(r'### ###')
FindFunc('QTGMC(', txt2, True)
FindFunc('KTGMC(', txt2, True)
txt2.append(r'### platform: Win32')
txt2.append('v=HDRAGC(coef_gain=1.0, max_gain=3.0,min_gain=1.0,coef_sat=1.0,max_sat=9.0,min_sat=0.0,avg_lum=128,avg_window=24,corrector=1.0,\n' +
'\\reducer=0.0,response=100,protect=2,mode=2,passes=4,black_clip=0.0,shift=0,shift_u=0,shift_v=0,freezer=-1,shadows=true,debug=0)\nhdr2(v, 0.5)')
txt2.append(r'### platform: Win64')
txt2.append(r'### ###')
s = FindFunc('audio=LSMASHAudioSource', None, True)
if s:
txt2.append(r'audio=LSMASHAudioSource(SourceFile)')
txt2.append(r'audioDub(last, audio)')
else:
s = FindFunc('audio=LWLibavAudioSource')
if s:
txt2.append(r'audio=LWLibavAudioSource(SourceFile, cache=False)')
txt2.append(r'audioDub(last, audio)')
txt2.append('return last')
txt2.append('""")')
txt2.append('')
s = '\n'.join(map(str, txt2))
avsp.InsertText('*/\n' + s, pos=None)
avsp.InsertText('/*', pos=0)