-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrapper.py
145 lines (93 loc) · 2.92 KB
/
scrapper.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
import requests
URL = "https://mobomoviez.fun/post/"
find = True
is_paused = False
def normalize_name (series_name : str) -> str:
series_name = series_name.lower()
result = ""
for i in series_name:
if i != " ":
result += i
else:
result += "-"
return result
def normalize_link (link_tag : str) -> str:
link = "https://mobomoviez.fun/"
append = False
for i in link_tag:
if append:
link += i
if i == "/":
append = True
if i == '"':
append = False
return link[:-1]
def find_link (page, season_number, resolution_number, episode):
print ("WOW! We find that show!")
page_list = page.text.split ("\n")
seasons = []
for i in range (len(page_list)):
element = page_list[i]
if "<h3>" in element and "</h3>" in element and "فصل" in element:
seasons.append (i)
print (f"That show has {len(seasons)} seasons")
season_number = int(season_number)
resolutions = []
try:
limit = seasons[season_number]
except:
limit = len (page_list) - 100
for i in range (seasons[season_number - 1], limit):
element = page_list[i]
if resolution_number in element:
resolutions.append (i)
limit = resolutions[-1]
if len (resolutions) == 1:
try:
limit = seasons[season_number]
except:
limit = len(page_list) - 100
subtitle = 0
for i in range (resolutions[0], limit):
element = page_list[i]
if "زیرنویس چسبیده" in element:
subtitle = i
break
episode_idx = 0
for i in range (subtitle, limit):
element = page_list[i]
if "قسمت" + " " + episode in element:
episode_idx = i
break
link = ""
for i in range (episode_idx, subtitle, -1):
element = page_list[i]
if "href" in element and "<a" in element:
link = element
break
link = normalize_link(link)
file_name = ""
for i in range (len (link) - 1, 0, -1):
if link[i] != "/":
file_name += link[i]
else:
break
file_name = file_name [::-1]
return [link, file_name]
def find_page (show_name : str):
show_name = normalize_name(show_name)
page = requests.get(URL + show_name)
if "اوپس" in page.text:
return False
else:
return page
def terminate_download ():
OBJ.stop()
def pause_download ():
global is_paused
if is_paused:
OBJ.resume()
is_paused = not is_paused
else:
OBJ.pause()
is_paused = not is_paused