forked from Chris230291/STB-Proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stb.py
229 lines (206 loc) · 7.06 KB
/
stb.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
import requests
from requests.adapters import HTTPAdapter, Retry
from urllib.parse import urlparse
import re
s = requests.Session()
retries = Retry(total=3, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504])
s.mount("http://", HTTPAdapter(max_retries=retries))
def getUrl(url, proxy=None):
def parseResponse(url, data):
java = data.text.replace(" ", "").replace("'", "").replace("+", "")
pattern = re.search(r"varpattern.*\/(\(http.*)\/;", java).group(1)
result = re.search(pattern, url)
protocolIndex = re.search(r"this\.portal_protocol.*(\d).*;", java).group(1)
ipIndex = re.search(r"this\.portal_ip.*(\d).*;", java).group(1)
pathIndex = re.search(r"this\.portal_path.*(\d).*;", java).group(1)
protocol = result.group(int(protocolIndex))
ip = result.group(int(ipIndex))
path = result.group(int(pathIndex))
portalPatern = re.search(r"this\.ajax_loader=(.*\.php);", java).group(1)
portal = (
portalPatern.replace("this.portal_protocol", protocol)
.replace("this.portal_ip", ip)
.replace("this.portal_path", path)
)
return portal
url = urlparse(url).scheme + "://" + urlparse(url).netloc
urls = [
"/c/xpcom.common.js",
"/client/xpcom.common.js",
"/c_/xpcom.common.js",
"/stalker_portal/c/xpcom.common.js",
"/stalker_portal/c_/xpcom.common.js",
]
proxies = {"http": proxy, "https": proxy}
headers = {"User-Agent": "Mozilla/5.0 (QtEmbedded; U; Linux; C)"}
try:
for i in urls:
try:
response = s.get(url + i, headers=headers, proxies=proxies)
except:
response = None
if response:
return parseResponse(url + i, response)
except:
pass
# sometimes these pages dont like proxies!
try:
for i in urls:
try:
response = s.get(url + i, headers=headers)
except:
response = None
if response:
return parseResponse(url + i, response)
except:
pass
def getToken(url, mac, proxy=None):
proxies = {"http": proxy, "https": proxy}
cookies = {"mac": mac, "stb_lang": "en", "timezone": "Europe/London"}
headers = {"User-Agent": "Mozilla/5.0 (QtEmbedded; U; Linux; C)"}
try:
response = s.get(
url + "?type=stb&action=handshake&JsHttpRequest=1-xml",
cookies=cookies,
headers=headers,
proxies=proxies,
)
token = response.json()["js"]["token"]
if token:
return token
except:
pass
def getProfile(url, mac, token, proxy=None):
proxies = {"http": proxy, "https": proxy}
cookies = {"mac": mac, "stb_lang": "en", "timezone": "Europe/London"}
headers = {
"User-Agent": "Mozilla/5.0 (QtEmbedded; U; Linux; C)",
"Authorization": "Bearer " + token,
}
try:
response = s.get(
url + "?type=stb&action=get_profile&JsHttpRequest=1-xml",
cookies=cookies,
headers=headers,
proxies=proxies,
)
profile = response.json()["js"]
if profile:
return profile
except:
pass
def getExpires(url, mac, token, proxy=None):
proxies = {"http": proxy, "https": proxy}
cookies = {"mac": mac, "stb_lang": "en", "timezone": "Europe/London"}
headers = {
"User-Agent": "Mozilla/5.0 (QtEmbedded; U; Linux; C)",
"Authorization": "Bearer " + token,
}
try:
response = s.get(
url + "?type=account_info&action=get_main_info&JsHttpRequest=1-xml",
cookies=cookies,
headers=headers,
proxies=proxies,
)
expires = response.json()["js"]["phone"]
if expires:
return expires
except:
pass
def getAllChannels(url, mac, token, proxy=None):
proxies = {"http": proxy, "https": proxy}
cookies = {"mac": mac, "stb_lang": "en", "timezone": "Europe/London"}
headers = {
"User-Agent": "Mozilla/5.0 (QtEmbedded; U; Linux; C)",
"Authorization": "Bearer " + token,
}
try:
response = s.get(
url
+ "?type=itv&action=get_all_channels&force_ch_link_check=&JsHttpRequest=1-xml",
cookies=cookies,
headers=headers,
proxies=proxies,
)
channels = response.json()["js"]["data"]
if channels:
return channels
except:
pass
def getGenres(url, mac, token, proxy=None):
proxies = {"http": proxy, "https": proxy}
cookies = {"mac": mac, "stb_lang": "en", "timezone": "Europe/London"}
headers = {
"User-Agent": "Mozilla/5.0 (QtEmbedded; U; Linux; C)",
"Authorization": "Bearer " + token,
}
try:
response = s.get(
url + "?action=get_genres&type=itv&JsHttpRequest=1-xml",
cookies=cookies,
headers=headers,
proxies=proxies,
)
genreData = response.json()["js"]
if genreData:
return genreData
except:
pass
def getGenreNames(url, mac, token, proxy=None):
try:
genreData = getGenres(url, mac, token, proxy)
genres = {}
for i in genreData:
gid = i["id"]
name = i["title"]
genres[gid] = name
if genres:
return genres
except:
pass
def getLink(url, mac, token, cmd, proxy=None):
proxies = {"http": proxy, "https": proxy}
cookies = {"mac": mac, "stb_lang": "en", "timezone": "Europe/London"}
headers = {
"User-Agent": "Mozilla/5.0 (QtEmbedded; U; Linux; C)",
"Authorization": "Bearer " + token,
}
try:
response = s.get(
url
+ "?type=itv&action=create_link&cmd="
+ cmd
+ "&series=0&forced_storage=false&disable_ad=false&download=false&force_ch_link_check=false&JsHttpRequest=1-xml",
cookies=cookies,
headers=headers,
proxies=proxies,
)
data = response.json()
link = data["js"]["cmd"].split()[-1]
if link:
return link
except:
pass
def getEpg(url, mac, token, period, proxy=None):
proxies = {"http": proxy, "https": proxy}
cookies = {"mac": mac, "stb_lang": "en", "timezone": "Europe/London"}
headers = {
"User-Agent": "Mozilla/5.0 (QtEmbedded; U; Linux; C)",
"Authorization": "Bearer " + token,
}
try:
response = s.get(
url
+ "?type=itv&action=get_epg_info&period="
+ str(period)
+ "&JsHttpRequest=1-xml",
cookies=cookies,
headers=headers,
proxies=proxies,
)
data = response.json()["js"]["data"]
if data:
return data
except:
pass