-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathAppMuou.py
More file actions
311 lines (293 loc) · 11.9 KB
/
AppMuou.py
File metadata and controls
311 lines (293 loc) · 11.9 KB
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
"""
@header({
searchable: 1,
filterable: 1,
quickSearch: 1,
title: 'AppMuou',
lang: 'hipy'
})
"""
# -*- coding: utf-8 -*-
# 仅可用于学习用途
from Crypto.Cipher import AES
try:
# from base.spider import Spider as BaseSpider
from base.spider import BaseSpider
except ImportError:
from t4.base.spider import BaseSpider
from Crypto.Util.Padding import unpad
import re,sys,time,json,base64,hashlib,urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
sys.path.append('..')
class Spider(BaseSpider):
host,name,version,data_key,data_iv,cms_host,jx_api,playerinfo,= '', '', '', '', '', '', '',[]
headers = {
'User-Agent': "Mozilla/5.0 (Linux; Android 12) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.105 MUOUAPP/10.8.4506.400",
'Accept-Encoding': "gzip",
'brand-model': "xiaomi",
'app-device': "nodata",
'app-time': "",
'sys-version': "12",
'device': "831395239bddf2e6",
'os': "Android",
'app-version': version
}
def init(self, extend=""):
try:
config = json.loads(self.extend.strip())
except (json.JSONDecodeError, TypeError):
config = {}
name = config.get("name", "muou")
self.headers['app-version'] = config.get("version", "4.2.0")
self.host = config['host']
if not re.match(r'^https?:\/\/[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(:\d+)?(\/)?$', self.host):
self.host = self.fetch(self.host, headers=self.headers, timeout=10, verify=False).text.rstrip('/')
timestamp = int(time.time())
self.headers['app-time'] = str(timestamp)
inner_sha1 = hashlib.sha1(f"{timestamp}{name}".encode('utf-8')).hexdigest()
outer_sha1 = hashlib.sha1(f"{timestamp}{inner_sha1}muouapp".encode('utf-8')).hexdigest()
payload = { 't': timestamp, 'n': inner_sha1, 'm': outer_sha1 }
try:
response = self.post(f'{self.host}/app_info.php', data=payload)
if response.status_code != 200:
return '-2 数据获取失败'
dat = response.text
except:
return '-2 数据获取失败'
try:
dat2 = json.loads(dat)
except:
return '-2 数据获取失败'
data = dat2.get('data', '')
a = dat2.get('a', '')
e = dat2.get('e', '')
s = dat2.get('s', '')
if not a or not e or not s:
return '-3 参数获取失败'
data2 = self.t(data, s, e)
key = hashlib.md5(a.encode('utf-8')).hexdigest()[:16]
iv = hashlib.md5(outer_sha1.encode('utf-8')).hexdigest()[:16]
result = self.decrypt(data2, key, iv)
if not result:
return '-4 解密失败'
try:
dat3 = json.loads(result)
except:
return '-5 解密失败'
key2 = dat3['key']
iv2 = dat3['iv']
self.data_key = hashlib.md5(key2.encode('utf-8')).hexdigest()[:16]
self.data_iv = hashlib.md5(iv2.encode('utf-8')).hexdigest()[:16]
self.cms_host = dat3['HBqq']
jx_api = dat3.get('HBrjjg','')
if jx_api.startswith('http'):
self.jx_api = jx_api
return None
def homeContent(self, filter):
if not self.cms_host:
return {'list': []}
self.headers['app-time'] = str(int(time.time()))
try:
response = self.fetch(f'{self.cms_host}/api.php/v1.vod/types', headers=self.headers).text
except Exception as e:
return {"class": [], "filters": {}}
try:
data = json.loads(response) or {}
except json.JSONDecodeError:
try:
data = json.loads(self.decrypt(response))
except (json.JSONDecodeError, TypeError):
return {"class": [], "filters": {}}
filter_keys = {"class", "area", "lang", "year", "letter", "by", "sort"}
filters = {}
classes = []
typelist = data.get('data', {}).get('typelist', [])
for item in typelist:
type_id = str(item["type_id"])
classes.append({"type_name": item["type_name"], "type_id": type_id})
extend = item.get("type_extend", {})
type_filters = []
for key, value_str in extend.items():
if key not in filter_keys:
continue
stripped = value_str.strip()
if not stripped:
continue
values = [v.strip() for v in stripped.split(",") if v.strip()]
if not values:
continue
type_filters.append({
"key": key,
"name": key,
"value": [{"n": v, "v": v} for v in values]
})
if type_filters:
filters[type_id] = type_filters
return {"class": classes, "filters": filters}
def homeVideoContent(self):
if not self.cms_host:
return {'list': []}
self.headers['app-time'] = str(int(time.time()))
print(f'{self.cms_host}/api.php/v1.vod/HomeIndex?page=&limit=6')
response = self.fetch(f'{self.cms_host}/api.php/v1.vod/HomeIndex?page=&limit=6', headers=self.headers).text
try:
data = json.loads(response)
except (json.JSONDecodeError, TypeError):
data_ = self.decrypt(response)
data = json.loads(data_)
videos = []
for i in data['data']:
if i.get('vod_list'):
vod_list = i['vod_list']
for j in vod_list:
pic = j.get('vod_pic')
if pic:
if not pic.startswith('http'):
j['vod_pic'] = self.cms_host + pic
videos.extend(vod_list)
return {'list': videos}
def detailContent(self, ids):
self.headers['app-time'] = str(int(time.time()))
response = self.fetch(f'{self.cms_host}/api.php/v1.vod/detail?vod_id={ids[0]}', headers=self.headers).text
try:
data = json.loads(response)
except (json.JSONDecodeError, TypeError):
data_ = self.decrypt(response)
data = json.loads(data_)
data = data['data']
if data == '':
return {'list': []}
vod_play_url = ''
show = ''
for i,j in data['vod_play_list'].items():
show += j['player_info']['show'] + '$$$'
urls = j.get('urls',{})
play_url = ''
if isinstance(urls, dict):
for i2,j2 in urls.items():
play_url += f"{j2['name']}${j2['from']}@{j2['url']}#"
play_url = play_url.rstrip('#')
vod_play_url += play_url + '$$$'
data['vod_play_from'] = show.rstrip('$$$')
data['vod_play_url'] = vod_play_url.rstrip('$$$')
data['vod_play_note'] = '$$$'
data.pop('vod_play_list')
data.pop('type')
return {'list': [data]}
def searchContent(self, key, quick, pg="1"):
if not self.cms_host:
return {'list': []}
self.headers['app-time'] = str(int(time.time()))
response = self.fetch(f'{self.cms_host}/api.php/v1.vod?wd={key}&limit=18&page={pg}', headers=self.headers).text
try:
data = json.loads(response)
except (json.JSONDecodeError, TypeError):
data_ = self.decrypt(response)
data = json.loads(data_)
videos = data['data']['list']
for item in data['data']['list']:
item.pop('type', None)
return {'list': videos, 'page': pg}
def categoryContent(self, tid, pg, filter, extend):
if not self.cms_host:
return {'list': []}
self.headers['app-time'] = str(int(time.time()))
response = self.fetch(
f"{self.cms_host}/api.php/v1.vod?type={tid}&class={extend.get('class', '')}&area={extend.get('area', '')}&year={extend.get('year', '')}&by=time&page={pg}&limit=18",
headers=self.headers).text
try:
data = json.loads(response)
except (json.JSONDecodeError, TypeError):
data_ = self.decrypt(response)
data = json.loads(data_)
videos = data['data']['list']
for item in data['data']['list']:
pic = item.get('vod_pic', '')
if pic:
if not pic.startswith('http'):
item['vod_pic'] = self.cms_host + pic
item.pop('type', None)
print(videos)
return {'list': videos, 'page': pg}
def playerContent(self, flag, id, vipFlags):
play_from, raw_url = id.split('@')
jx,url,playurl, = 1,raw_url,''
try:
if not self.playerinfo:
res = self.fetch(f'{self.host}/api.php?action=playerinfo',headers=self.headers).text
data = self.decrypt(res)
playerinfo =json.loads(data).get('data',{}).get('playerinfo',[])
if len(playerinfo) > 1:
self.playerinfo = playerinfo
if self.playerinfo:
for i in self.playerinfo:
play_jx = i.get('playerjiekou','')
if i.get('playername') == play_from and play_jx.startswith('http'):
response = self.fetch(f'{play_jx}{raw_url}&playerkey={play_from}',headers=self.headers,verify=False).text
try:
data = json.loads(response)
except (json.JSONDecodeError, TypeError):
data_ = self.decrypt(response)
data = json.loads(data_)
if str(data.get('code','')) == '403':
playurl = ''
else:
playurl = data['url']
jx = 0
except Exception:
playurl = ''
if playurl.startswith('http'):
url = playurl
else:
if re.search(r'^https?[^\s]*\.(m3u8|mp4|flv)', raw_url, re.I):
url = raw_url
jx = 0
else:
try:
response = self.fetch(self.jx_api + raw_url,headers=self.headers,verify=False).text
try:
data = json.loads(response)
except (json.JSONDecodeError, TypeError):
data_ = self.decrypt(response)
data = json.loads(data_)
playurl = data.get('url','')
if playurl.startswith('http'):
jx,url = 0,playurl
else:
jx,url = 1,raw_url
except Exception as e:
jx,url = 1,raw_url
if url.startswith('NBY-'):
jx,url = 0,''
return {'jx': jx, 'parse': 0, 'url': url,'header': {'User-Agent': 'Mozilla/5.0 (Linux; Android 12) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.105 MUOUAPP/10.8.4506.400'}}
def decrypt(self,data, key='', iv=''):
if not(key or iv):
key = self.data_key
iv = self.data_iv
key_bytes = key.encode('utf-8')
iv_bytes = iv.encode('utf-8')
encrypted_data = base64.b64decode(data)
cipher = AES.new(key_bytes, AES.MODE_CBC, iv_bytes)
decrypted_padded = cipher.decrypt(encrypted_data)
decrypted = unpad(decrypted_padded, AES.block_size)
return decrypted.decode('utf-8')
def t(self, s, v, v1):
if s is not None and s != '':
n = len(s)
if v < 0 or v1 < 0:
raise ValueError("参数不能为负数")
if v + v1 <= n:
return s[v:n - v1]
else:
return ''
return s
def getName(self):
return 'AppMuou'
def isVideoFormat(self, url):
pass
def manualVideoCheck(self):
pass
def destroy(self):
pass
def localProxy(self, param):
pass