-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.py
executable file
·171 lines (131 loc) · 5.35 KB
/
update.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
#!/usr/bin/env python3
import os
import re
import sys
import time
import json
import urllib.parse
# pypi modules
import requests
#from bs4 import BeautifulSoup
result_path = "debrid-hoster-map.json"
def get_netloc(url):
netloc = urllib.parse.urlparse(url).netloc # "real-debrid.com"
if netloc.startswith("www."):
netloc = netloc[4:]
return netloc
def get_debrid_html(debrid_url, debrid_id):
debrid_cache = "cache/" + debrid_id + ".html"
if os.path.exists(debrid_cache):
# read cache
with open(debrid_cache) as f:
debrid_html = f.read()
else:
response = requests.get(debrid_url) # , **requests_get_kwargs)
assert response.status_code == 200
#response_status = response.response_status
#print("response.status_code", response.status_code)
#print("response.headers", response.headers)
#print("response.text", response.text)
#result = response.json()
debrid_html = response.text
# write cache
with open(debrid_cache, "w") as f:
f.write(debrid_html)
return debrid_html
# result
debrid_hoster_map = dict()
# note: we must be logged in to see this page
# otherwise we get "403 - forbidden"
# (idiots just love to hide...)
debrid_url = "https://real-debrid.com/compare"
debrid_id = get_netloc(debrid_url)
debrid_html = get_debrid_html(debrid_url, debrid_id)
debrid_hoster_map[debrid_id] = dict()
regex = (
r'<img src="https://fcdn.real-debrid.com/0830/images/hosters/100_100/([^"]+).png" ' +
r'height="42" width="42" alt="[^"]+" title="([^"]+)"'
)
for match in re.finditer(regex, debrid_html):
hoster_id, hoster_urls = match.groups()
hoster_urls = hoster_urls.split(",")
if hoster_id in debrid_hoster_map[debrid_id]:
raise KeyError(f"key already exists: {hoster_id!r}")
debrid_hoster_map[debrid_id][hoster_id] = hoster_urls
# TODO also parse daily limits
debrid_url = "https://www.deepbrid.com/status"
debrid_id = get_netloc(debrid_url)
debrid_html = get_debrid_html(debrid_url, debrid_id)
debrid_hoster_map[debrid_id] = dict()
#regex = r'<tr><td class="border-b"><div class="hosters ([^ "]+)">' # free hosters
regex = r'<td class="border-b"><div class="hosters ([^ "]+)"></div>' # premium hosters
for match in re.finditer(regex, debrid_html):
hoster_id = match.group(1)
if hoster_id in debrid_hoster_map[debrid_id]:
continue
raise KeyError(f"key already exists: {hoster_id!r}")
debrid_hoster_map[debrid_id][hoster_id] = True
# this page was removed
# alldebrid.com is based in france like real-debrid.com
# so maybe this is pro-active self-censorship...
debrid_url = "https://alldebrid.com/hosts/"
debrid_id = get_netloc(debrid_url)
debrid_html = get_debrid_html(debrid_url, debrid_id)
debrid_hoster_map[debrid_id] = dict()
regex = r'<a href="/hosts/([^ "]+)/">' # premium hosters
for match in re.finditer(regex, debrid_html):
hoster_id = match.group(1)
if hoster_id in debrid_hoster_map[debrid_id]:
raise KeyError(f"key already exists: {hoster_id!r}")
debrid_hoster_map[debrid_id][hoster_id] = True
debrid_url = "https://support.torbox.app/en/articles/9837721-supported-debrid-hosters"
debrid_id = "torbox.app"
debrid_html = get_debrid_html(debrid_url, debrid_id)
debrid_hoster_map[debrid_id] = dict()
# sections of supported hosters
regex1 = r'<h2 id="[^"]+">Supported (File|Streaming) Hosters</h2>(.*?)(?=<h2|<section)'
regex2 = r'href="(http[^"]+)"'
for match1 in re.finditer(regex1, debrid_html):
section_type, section_html = match1.groups()
for match2 in re.finditer(regex2, section_html):
hoster_url = match2.group(1)
hoster_id = get_netloc(hoster_url)
if hoster_id in debrid_hoster_map[debrid_id]:
raise KeyError(f"key already exists: {hoster_id!r}")
debrid_hoster_map[debrid_id][hoster_id] = True
debrid_url = "https://www.premiumize.me/services?q=all"
debrid_id = get_netloc(debrid_url)
debrid_html = get_debrid_html(debrid_url, debrid_id)
debrid_hoster_map[debrid_id] = dict()
# src="https://www.google.com/s2/favicons?domain=uploadgig.com"
regex = r'src="https://www\.google\.com/s2/favicons\?domain=([^"]+)"'
for match in re.finditer(regex, debrid_html):
hoster_id = match.group(1)
hoster_id = hoster_id.split("%2F")[0]
if hoster_id in debrid_hoster_map[debrid_id]:
raise KeyError(f"key already exists: {hoster_id!r}")
debrid_hoster_map[debrid_id][hoster_id] = True
# TODO also parse daily limits
# note: we must be logged in to see this page
# otherwise we get "403 - forbidden"
# (idiots just love to hide...)
debrid_url = "https://neodebrid.com/hosts-status"
debrid_id = get_netloc(debrid_url)
debrid_html = get_debrid_html(debrid_url, debrid_id)
debrid_hoster_map[debrid_id] = dict()
regex = (
r'<a href="#" class="text-gray-800 fw-bold text-hover-primary mb-1 fs-6">([^<]+)</a>'
)
for match in re.finditer(regex, debrid_html):
hoster_id = match.group(1).lower()
if hoster_id in debrid_hoster_map[debrid_id]:
continue
debrid_hoster_map[debrid_id][hoster_id] = True
# sort by debrid_id
debrid_hoster_map = dict(sorted(debrid_hoster_map.items()))
# sort by hoster_id
for debrid_id in debrid_hoster_map:
debrid_hoster_map[debrid_id] = dict(sorted(debrid_hoster_map[debrid_id].items()))
print("writing", result_path)
with open(result_path, "w") as f:
json.dump(debrid_hoster_map, f, indent=2)