-
Notifications
You must be signed in to change notification settings - Fork 29
/
recover.py
342 lines (253 loc) · 10.7 KB
/
recover.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import datetime
import hashlib
import time
import urllib.request
from threading import Thread
from bs4 import BeautifulSoup
import requests
import webbrowser
import random
import sys
domains = [
"https://vod-secure.twitch.tv",
"https://vod-metro.twitch.tv",
"https://vod-pop-secure.twitch.tv",
"https://d2e2de1etea730.cloudfront.net",
"https://dqrpb9wgowsf5.cloudfront.net",
"https://ds0h3roq6wcgc.cloudfront.net",
"https://d2nvs31859zcd8.cloudfront.net",
"https://d2aba1wr3818hz.cloudfront.net",
"https://d3c27h4odz752x.cloudfront.net",
"https://dgeft87wbj63p.cloudfront.net",
"https://d1m7jfoe9zdc1j.cloudfront.net",
"https://d3vd9lfkzbru3h.cloudfront.net",
"https://d2vjef5jvl6bfs.cloudfront.net",
"https://d1ymi26ma8va5x.cloudfront.net",
"https://d1mhjrowxxagfy.cloudfront.net",
"https://ddacn6pr5v0tl.cloudfront.net",
"https://d3aqoihi2n8ty8.cloudfront.net",
"https://d1xhnb4ptk05mw.cloudfront.net",
"https://d6tizftlrpuof.cloudfront.net",
"https://d36nr0u3xmc4mm.cloudfront.net",
"https://d1oca24q5dwo6d.cloudfront.net",
"https://d2um2qdswy1tb0.cloudfront.net",
'https://d1w2poirtb3as9.cloudfront.net',
'https://d6d4ismr40iw.cloudfront.net',
'https://d1g1f25tn8m2e6.cloudfront.net',
'https://dykkng5hnh52u.cloudfront.net',
'https://d2dylwb3shzel1.cloudfront.net',
'https://d2xmjdvx03ij56.cloudfront.net']
find1c = 0
def linkChecker(link): # twitchtracker ve streamscharts destekli
global streamername
global vodID
link = link.split('/')
if link[2] == 'twitchtracker.com':
streamername = link[3]
vodID = link[5]
return 1
elif link[2] == 'streamscharts.com':
streamername = link[4]
vodID = link[6]
return 2
elif link[0] == 'twitchtracker.com':
streamername = link[1]
vodID = link[3]
return 3
elif link[0] == 'streamscharts.com':
streamername = link[2]
vodID = link[4]
return 4
else:
print('Check the link again. (An unsupported link has been entered or the link has an error.)')
return 0
def linkTimeCheck(link):
# global timestamp
if linkChecker(link) == 2 or linkChecker(link) == 4: # streamscharts
print('Date and Time are checking..')
r = requests.get(link)
soup = BeautifulSoup(r.content, 'html.parser')
gelenveri = soup.find_all('time', 'ml-2 font-bold')
try:
time = gelenveri[0].text
except:
print('You probably got into cloudflare for bots.(could not find time data) There is nothing I can do for this error for now. \n'
'Please fork if you can bypass this cloudflare. \n'
'You will not get an error when you try again after a while. \n'
'So try again after a while. ')
return
if '\n' in time:
time = time.replace('\n', '')
if ',' in time:
time = time.replace(',', '')
print(f'Clock data: {time}')
print(f'Streamer name: {streamername} \nvodID: {vodID}')
time = time.split(' ')
hoursandminut = time[3]
hoursandminut = hoursandminut.split(':')
day = int(time[0])
month = time[1]
year = int(time[2])
hour = int(hoursandminut[0])
minute = int(hoursandminut[1])
def months(month):
if month == 'Jan':
return 1
if month == 'Feb':
return 2
if month == 'Mar':
return 3
if month == 'Apr':
return 4
if month == 'May':
return 5
if month == 'Jun':
return 6
if month == 'Jul':
return 7
if month == 'Aug':
return 8
if month == 'Sep':
return 9
if month == 'Oct':
return 10
if month == 'Nov':
return 11
if month == 'Dec':
return 12
else:
return 0
month = months(month)
second = 60
timestamp = str(year) + '-' + str(month) + '-' + str(day) + '-' + str(hour) + '-' + str(minute) + '-' + str(
second)
print(f'timestamp', timestamp)
return timestamp
elif linkChecker(link) == 1 or linkChecker(link) == 3: #twitchtracker
print('Date and Time are checking...')
useragent = ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 12.5; rv:103.0) Gecko/20100101 Firefox/103.0",
"Mozilla/5.0 (X11; Linux i686; rv:103.0) Gecko/20100101 Firefox/103.0",
"Mozilla/5.0 (Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0",
"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:103.0) Gecko/20100101 Firefox/103.0",
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0",
"Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 12.5; rv:102.0) Gecko/20100101 Firefox/102.0",
"Mozilla/5.0 (X11; Linux i686; rv:102.0) Gecko/20100101 Firefox/102.0",
"Mozilla/5.0 (Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0",
"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:102.0) Gecko/20100101 Firefox/102.0",
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0",
"Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6 Safari/605.1.15",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36 Edg/103.0.1264.77",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36 Edg/103.0.1264.77",
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36']
header = {
'user-agent': f'{random.choice(useragent)}'
}
r = requests.get(link, headers=header)
soup = BeautifulSoup(r.content, 'html.parser')
gelenveri = soup.find_all('div', 'stream-timestamp-dt')
try:
time = gelenveri[0].text
except:
print('You probably got into cloudflare for bots.(could not find time data) There is nothing I can do for this error for now. \n'
'Please fork if you can bypass this cloudflare. \n'
'You will not get an error when you try again after a while. \n'
'So try again after a while. ')
return
print(f'Clock data: {gelenveri[0].text}')
print(f'Streamer name: {streamername} \nvodID: {vodID}')
firstandsecond_time = gelenveri[0].text.split(' ')
first_time = firstandsecond_time[0].split('-')
second_time = firstandsecond_time[1].split(':')
day = int(first_time[2])
month = int(first_time[1])
year = int(first_time[0])
hour = int(second_time[0])
minute = int(second_time[1])
second = int(second_time[2])
timestamp = str(year) + '-' + str(month) + '-' + str(day) + '-' + str(hour) + '-' + str(minute) + '-' + str(
second)
print(f'timestamp', timestamp)
return timestamp
elif linkChecker(link) == 0:
print('You entered an unsupported link.')
return 0
else:
print('An unknown error has occurred.')
return None
def totimestamp(dt, epoch=datetime.datetime(1970, 1, 1)):
td = dt - epoch
return (td.microseconds + (td.seconds + td.days * 86400) * 10 ** 6) / 10 ** 6
def find(timestamp, domain):
timestamp = timestamp.split('-')
year = int(timestamp[0])
month = int(timestamp[1])
day = int(timestamp[2])
hour = int(timestamp[3])
minute = int(timestamp[4])
second = int(timestamp[5])
def check(url):
global find1c
try:
urllib.request.urlopen(url)
except urllib.error.HTTPError:
pass
else:
print(url)
#webbrowser.open(url)
find1c = 1
threads = []
if second == 60:
for i in range(60):
seconds = i
td = datetime.datetime(year, month, day, hour, minute, seconds)
converted_timestamp = totimestamp(td)
formattedstring = streamername + "_" + vodID + "_" + str(int(converted_timestamp))
hash = str(hashlib.sha1(formattedstring.encode('utf-8')).hexdigest())
requiredhash = hash[:20]
finalformattedstring = requiredhash + '_' + formattedstring
url = f"{domain}/{finalformattedstring}/chunked/index-dvr.m3u8"
threads.append(Thread(target=check, args=(url,)))
for i in threads:
i.start()
for i in threads:
i.join()
else:
td = datetime.datetime(year, month, day, hour, minute, second)
converted_timestamp = totimestamp(td)
formattedstring = streamername + "_" + vodID + "_" + str(int(converted_timestamp))
hash = str(hashlib.sha1(formattedstring.encode('utf-8')).hexdigest())
requiredhash = hash[:20]
finalformattedstring = requiredhash + '_' + formattedstring
url = f"{domain}/{finalformattedstring}/chunked/index-dvr.m3u8"
threads.append(Thread(target=check, args=(url,)))
for i in threads:
i.start()
for i in threads:
i.join()
if len(sys.argv) < 2:
# just python and recover.py as 1st argument
print('Find the broadcast link you want from Twitchtracker or Streamscharts site.')
link = str(input('Enter the link:'))
else:
link = sys.argv[1]
timestamp = linkTimeCheck(link)
if timestamp == None:
quit()
for domain in domains:
if find1c == 0:
find(timestamp, domain)
else:
pass
if find1c == 0:
print('No File Found on Twitch Servers.')
if find1c == 1:
time.sleep(10)