This repository was archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathvideos__scripthandler.py
84 lines (66 loc) · 3.37 KB
/
videos__scripthandler.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
class scripthandler:
def scriptResponseHandler(self):
#########scriptResponseHandler PROPERTY#########
#########This property is later called in the another property exec() of the class. #########
temp = 0
#########Defining Result Arrays.#########
self.links = []
self.ids = []
self.titles = []
self.channels = []
self.views = []
self.durations = []
self.thumbnails = []
#########Transversing Through Network Request Array.#########
self.pageSource = self.page.split('":"')
for index in range(0, len(self.pageSource) - 1, 1):
#########Setting Video Durations And View Counts.#########
if self.pageSource[index][-14:] == '}},"simpleText' and self.pageSource[index+1][-28:] == '"viewCountText":{"simpleText':
durationBuffer = ""
viewCountBuffer = 0
for character in self.pageSource[index+1]:
if character!= '"':
durationBuffer+=character
else:
break
for character in self.pageSource[index+2].split()[0]:
if character.isnumeric():
viewCountBuffer = viewCountBuffer * 10 + int(character)
self.durations[-1] = durationBuffer
self.views[-1] = viewCountBuffer
#########Setting Video Links, IDs And Thumbnails.#########
if self.pageSource[index][0:9] == '/watch?v=':
id = self.pageSource[index][9:20]
modes = ["default", "hqdefault", "mqdefault", "sddefault", "maxresdefault"]
self.ids+=[id]
self.links+=['https://www.youtube.com/watch?v='+ id]
thumbnailbuffer = []
for mode in modes:
thumbnailbuffer+=["https://img.youtube.com/vi/" + id + "/" + mode + ".jpg"]
self.thumbnails+=[thumbnailbuffer]
#########Setting Video Titles.#########
if self.pageSource[index][-23:] == '"title":{"runs":[{"text' and self.pageSource[index+1][-44:] == '"accessibility":{"accessibilityData":{"label':
titleBuffer = ""
for character in self.pageSource[index+1]:
if character!= '"':
titleBuffer+=character
else:
break
self.titles+=[titleBuffer.replace("\\u0026", "&")]
self.views+=["LIVE"]
self.durations+=["LIVE"]
self.channels+= [""]
#########Setting Video Channels.#########
if self.pageSource[index][-32:] == '"longBylineText":{"runs":[{"text' and self.pageSource[index+1][-42:] == '"navigationEndpoint":{"clickTrackingParams':
channelBuffer = ""
for character in self.pageSource[index+1]:
if character!= '"':
channelBuffer+=character
else:
break
try:
self.channels[-1] = channelBuffer.replace("\\u0026", "&")
except:
pass
if len(self.ids) + 1 > self.max_results:
break