-
Notifications
You must be signed in to change notification settings - Fork 1
/
tools.py
314 lines (280 loc) · 10.4 KB
/
tools.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import re
import os
import shutil
def verifyURL(line):
verifyurl = re.compile('://').search(line)
if verifyurl:
return True
return
def tvgTypeMatch(line):
typematch = re.compile('tvg-type=\"(.*?)\"', re.IGNORECASE).search(line)
if typematch:
return typematch
return
def eventMatch(line):
eventmatch = re.compile('tvg-type=\"events\"', re.IGNORECASE).search(line)
if eventmatch:
return eventmatch
return
def ufcwweMatch(line):
ufcwwematch = re.compile('[U][f][c]|[w][w][e]|[r][i][d][i][c][u][l]', re.IGNORECASE).search(line)
if ufcwwematch:
return ufcwwematch
return
def airDateMatch(line):
datematch = re.compile('[1-2][0-9][0-9][0-9][ ][0-3][0-9][ ][0-1][0-9]|[1-2][0-9][0-9][0-9][ ][0-1][0-9][ ][0-3][0-9]').search(line)
if datematch:
return datematch
return
def tvgNameMatch(line):
namematch = re.compile('tvg-name=\"(.*?)\"', re.IGNORECASE).search(line)
if namematch:
return namematch
return
def tvidmatch(line):
tvidmatch = re.compile('tvg-ID=\"(.*?)\"', re.IGNORECASE).search(line)
if tvidmatch:
return tvidmatch
return
def tvgLogoMatch(line):
logomatch = re.compile('tvg-logo=\"(.*?)\"', re.IGNORECASE).search(line)
if logomatch:
return logomatch
return
def tvgGroupMatch(line):
groupmatch = re.compile('group-title=\"(.*?)\"', re.IGNORECASE).search(line)
if groupmatch:
return groupmatch
return
def infoMatch(line):
infomatch = re.compile('[,](?!.*[,])(.*?)$', re.IGNORECASE).search(line)
if infomatch:
return infomatch
return
def getResult(re_match):
return re_match.group().split('\"')[1]
def sxxExxMatch(line):
tvshowmatch = re.compile('[s][0-9][0-9][e][0-9][0-9]|[0-9][0-9][x][0-9][0-9][ ][-][ ]|[s][0-9][0-9][ ][e][0-9][0-9]|[0-9][0-9][x][0-9][0-9]', re.IGNORECASE).search(line)
if tvshowmatch:
return tvshowmatch
tvshowmatch = seasonMatch2(line)
if tvshowmatch:
return tvshowmatch
tvshowmatch = episodeMatch2(line)
if tvshowmatch:
return tvshowmatch
return
def tvgChannelMatch(line):
tvgchnomatch = re.compile('tvg-chno=\"(.*?)\"', re.IGNORECASE).search(line)
if tvgchnomatch:
return tvgchnomatch
tvgchannelid = re.compile('tvg-chno=\"(.*?)\"', re.IGNORECASE).search(line)
if tvgchannelid:
return tvgchannelid
return
def yearMatch(line):
yearmatch = re.compile('[(][1-2][0-9][0-9][0-9][)]').search(line)
if yearmatch:
return yearmatch
return
def resolutionMatch(line):
resolutionmatch = re.compile('HD|SD|720p WEB x264-XLF|WEB x264-XLF').search(line)
if resolutionmatch:
return resolutionmatch
return
def episodeMatch(line):
episodematch = re.compile('[e][0-9][0-9]|[0-9][0-9][x][0-9][0-9]', re.IGNORECASE).search(line)
if episodematch:
if episodematch.end() - episodematch.start() > 3:
episodenumber = episodematch.group()[3:]
#print(episodenumber,'E#')
else:
episodenumber = episodematch.group()[1:]
#print(episodenumber,'E#')
return episodenumber
return
def episodeMatch2(line):
episodematch = re.compile('[e][0-9][0-9]|[0-9][0-9][x][0-9][0-9]', re.IGNORECASE).search(line)
if episodematch:
return episodematch
return
def seasonMatch2(line):
seasonmatch = re.compile('[s][0-9][0-9]', re.IGNORECASE).search(line)
if seasonmatch:
return seasonmatch
return
def seasonMatch(line):
seasonmatch = re.compile('[s][0-9][0-9]|[0-9][0-9][x][0-9][0-9]', re.IGNORECASE).search(line)
if seasonmatch:
if seasonmatch.end() - seasonmatch.start() > 3:
seasonnumber = seasonmatch.group()[:3]
#print(seasonnumber,'s#')
else:
seasonnumber = seasonmatch.group()[1:]
#print(seasonnumber,'s#')
return seasonnumber
return
def imdbCheck(line):
imdbmatch = re.compile('[t][t][0-9][0-9][0-9]').search(line)
if imdbmatch:
return imdbmatch
return
def parseMovieInfo(info):
if ',' in info:
info = info.split(',')
if info[0] == "":
del info[0]
info = info[-1]
if '#' in info:
info = info.split('#')[0]
if ':' in info:
info = info.split(':')
if resolutionMatch(info[0]):
info = info[1]
else:
info = ':'.join(info)
return info.strip()
def parseResolution(match):
resolutionmatch = match.group().strip()
if resolutionmatch == 'HD' or resolutionmatch == '720p WEB x264-XLF':
return '720p'
elif resolutionmatch == 'SD' or resolutionmatch == 'WEB x264-XLF':
return '480p'
return
def parseGroup(match):
groupmatch = match.group().strip()
groupparse = re.findall('group-title=\"(.*?)\"', groupmatch)
return groupparse[0]
def makeStrm(filename, url):
if not os.path.exists(filename):
streamfile = open(filename, "w+")
streamfile.write(url)
streamfile.close
print("strm file created:", filename)
streamfile.close()
def makeDirectory(directory):
if not os.path.exists(directory):
os.mkdir(directory)
else:
print("directory found:", directory)
def stripYear(title):
yearmatch = re.sub('[(][1-2][0-9][0-9][0-9][)]|[1-2][0-9][0-9][0-9]', "", title)
if yearmatch:
return yearmatch.strip()
return
def languageMatch(line):
languagematch = re.compile('[|][A-Z][A-Z][|]', re.IGNORECASE).search(line)
if languagematch:
return languagematch
return
def stripLanguage(title):
languagematch = re.sub('[|][A-Z][A-Z][|]', "", title, flags=re.IGNORECASE)
if languagematch:
return languagematch.strip()
return
def stripResolution(title):
resolutionmatch = re.sub('HD|SD|720p WEB x264-XLF|WEB x264-XLF', "", title)
if resolutionmatch:
return resolutionmatch.strip()
return
def stripSxxExx(title):
sxxexxmatch = re.sub('[s][0-9][0-9][e][0-9][0-9]|[0-9][0-9][x][0-9][0-9][ ][-][ ]|[0-9][0-9][x][0-9][0-9]|[s][0-9][0-9][ ][e][0-9][0-9]', "", title, flags=re.IGNORECASE)
if sxxexxmatch:
return sxxexxmatch.strip()
return
def parseEpisode(title):
airdate = airDateMatch(title)
titlelen = len(title)
showtitle, episodetitle, language = None, None, None
if airdate:
showtitle = title[:airdate.start()].strip()
if airdate.end() != titlelen:
episodetitle = title[airdate.end():].strip()
return [showtitle,episodetitle,airdate.group()]
seasonepisode = sxxExxMatch(title)
if seasonepisode:
print(seasonepisode)
if seasonepisode.end() - seasonepisode.start() > 6 or len(seasonepisode.group()) == 5:
episodetitle = title[seasonepisode.end():].strip()
seasonnumber = seasonMatch(title)
episodenumber = episodeMatch(title)
showtitle = title[:seasonepisode.start()]
languagem = languageMatch(showtitle)
if languagem:
language = languagem.group().strip('|')
showtitle = showtitle[languagem.end():]
language2 = languageMatch(showtitle)
if language2:
showtitle = showtitle[:language2.start()]
season = seasonMatch2(showtitle)
if season:
showtitle = showtitle[:season.start()]
else:
seasonnumber = seasonMatch(title)
episodenumber = episodeMatch(title)
showtitle = stripSxxExx(title)
return [showtitle, episodetitle, seasonnumber, episodenumber, language]
def compare_and_update(dcmp):
for name in dcmp.diff_files:
print("STREAM CHANGE - %s - UPDATING" % (name))
if os.path.isdir(dcmp.left+"/"+name):
shutil.copytree(dcmp.left+"/"+name, dcmp.right+"/"+name, dirs_exist_ok=True)
elif os.path.isfile(dcmp.left+"/"+name):
shutil.copy2(dcmp.left+"/"+name, dcmp.right+"/"+name)
for name in dcmp.left_only:
if os.path.isdir(dcmp.left+"/"+name):
print("NEW STREAM DIRECTORY - %s - CREATING" % (name))
shutil.copytree(dcmp.left+"/"+name, dcmp.right+"/"+name, dirs_exist_ok=True)
elif os.path.isfile(dcmp.left+"/"+name):
print("NEW STREAM FILE - %s - CREATING" % (name))
shutil.copy2(dcmp.left+"/"+name, dcmp.right+"/"+name)
for name in dcmp.right_only:
if os.path.isdir(dcmp.right+"/"+name):
print("directory NO LONGER EXISTS - %s - DELETING" % (name))
shutil.rmtree(dcmp.right+"/"+name)
if os.path.isfile(dcmp.right+"/"+name):
print("file NO LONGER EXISTS - %s - DELETING" % (name))
os.remove(dcmp.right+"/"+name)
for sub_dcmp in dcmp.subdirs.values():
compare_and_update(sub_dcmp)
def compare_and_update_movies(dcmp):
for name in dcmp.diff_files:
print("STREAM CHANGE - %s - UPDATING" % (name))
if os.path.isdir(dcmp.left+"/"+name):
shutil.copytree(dcmp.left+"/"+name, dcmp.right+"/"+name, dirs_exist_ok=True)
elif os.path.isfile(dcmp.left+"/"+name):
shutil.copy2(dcmp.left+"/"+name, dcmp.right+"/"+name)
for name in dcmp.left_only:
if os.path.isdir(dcmp.left+"/"+name):
print("NEW STREAM DIRECTORY - %s - CREATING" % (name))
shutil.copytree(dcmp.left+"/"+name, dcmp.right+"/"+name, dirs_exist_ok=True)
elif os.path.isfile(dcmp.left+"/"+name):
print("NEW STREAM FILE - %s - CREATING" % (name))
shutil.copy2(dcmp.left+"/"+name, dcmp.right+"/"+name)
# for name in dcmp.right_only:
# if os.path.isdir(str(os.path.join(dcmp.right,name))):
#os.rename(dcmp.right+name,dcmp.right+"z"+name)
# print("Movies NO LONGER EXISTS - %s - DELETING" % (name))
# shutil.rmtree(os.path.join(dcmp.right,name))
# for sub_dcmp in dcmp.subdirs.values():
# compare_and_update_movies(sub_dcmp)
def compare_and_update_events(dcmp):
for name in dcmp.diff_files:
print("STREAM CHANGE - %s - UPDATING" % (name))
if os.path.isdir(dcmp.left+"/"+name):
shutil.copytree(dcmp.left+"/"+name, dcmp.right+"/"+name, dirs_exist_ok=True)
elif os.path.isfile(dcmp.left+"/"+name):
shutil.copy2(dcmp.left+"/"+name, dcmp.right+"/"+name)
for name in dcmp.left_only:
if os.path.isdir(dcmp.left+"/"+name):
print("NEW STREAM DIRECTORY - %s - CREATING" % (name))
shutil.copytree(dcmp.left+"/"+name, dcmp.right+"/"+name, dirs_exist_ok=True)
elif os.path.isfile(dcmp.left+"/"+name):
print("NEW STREAM FILE - %s - CREATING" % (name))
shutil.copy2(dcmp.left+"/"+name, dcmp.right+"/"+name)
for name in dcmp.right_only:
if os.path.isfile(dcmp.right+"/"+name):
print("EVENT NO LONGER EXISTS - %s - DELETING" % (name))
os.remove(dcmp.right+"/"+name)
for sub_dcmp in dcmp.subdirs.values():
compare_and_update_events(sub_dcmp)