forked from Dong-learn9/TVBox-zyjk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy_bilimd.py
214 lines (205 loc) · 6.04 KB
/
py_bilimd.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
#coding=utf-8
#!/usr/bin/python
import sys
sys.path.append('..')
from base.spider import Spider
import json
from requests import session, utils
import os
import time
import base64
class Spider(Spider): # 元类 默认的元类 type
def getName(self):
return "B站影视"
def init(self,extend=""):
print("============{0}============".format(extend))
pass
def isVideoFormat(self,url):
pass
def manualVideoCheck(self):
pass
def homeContent(self,filter):
result = {}
cateManual = {
"番剧": "1",
"国创": "4",
"电影": "2",
"综艺": "7",
"电视剧": "5",
"纪录片": "3"
}
classes = []
for k in cateManual:
classes.append({
'type_name':k,
'type_id':cateManual[k]
})
result['class'] = classes
if(filter):
result['filters'] = self.config['filter']
return result
def homeVideoContent(self):
result = {
'list':[]
}
return result
cookies = ''
def getCookie(self):
#在cookies_str中填入会员或大会员cookie,以获得更好的体验
cookies_str = "innersign=0; buvid3=606BE156-AE37-AEA8-7052-9DA0B21766E776404infoc; b_nut=1663302976; i-wanna-go-back=-1; b_ut=7; b_lsid=4106252F6_18344933A90; _uuid=586AAEB7-6B88-A691-F7AC-95C27E57F53C43036infoc; buvid4=B6FF1449-4361-1C76-DEFC-4AFCA1777B7E78304-022091612-PdJr0jKE6N5TamfAEX9uACD1RXvklspbNdlcIQEFLMu0d9wS3G3sdA%3D%3D; buvid_fp=2a9b54d5e06aa54293dc7544e000552d"
cookies_dic = dict([co.strip().split('=') for co in cookies_str.split(';')])
rsp = session()
cookies_jar = utils.cookiejar_from_dict(cookies_dic)
rsp.cookies = cookies_jar
content = self.fetch("http://api.bilibili.com/x/web-interface/nav", cookies=rsp.cookies)
res = json.loads(content.text)
if res["code"] == 0:
self.cookies = rsp.cookies
else:
rsp = self.fetch("https://www.bilibili.com/")
self.cookies = rsp.cookies
return rsp.cookies
def categoryContent(self,tid,pg,filter,extend):
result = {}
url = 'https://api.bilibili.com/pgc/season/index/result?order=2&season_status=-1&style_id=-1&sort=0&area=-1&pagesize=20&type=1&st={0}&season_type={0}&page={1}'.format(tid,pg)
if len(self.cookies) <= 0:
self.getCookie()
rsp = self.fetch(url, cookies=self.cookies)
content = rsp.text
jo = json.loads(content)
videos = []
vodList = jo['data']['list']
for vod in vodList:
aid = str(vod['season_id']).strip()
title = vod['title'].strip()
img = vod['cover'].strip()
remark = vod['index_show'].strip()
videos.append({
"vod_id":aid,
"vod_name":title,
"vod_pic":img,
"vod_remarks":remark
})
result['list'] = videos
result['page'] = pg
result['pagecount'] = 9999
result['limit'] = 90
result['total'] = 999999
return result
def cleanSpace(self,str):
return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
def detailContent(self,array):
aid = array[0]
url = "http://api.bilibili.com/pgc/view/web/season?season_id={0}".format(aid)
rsp = self.fetch(url,headers=self.header)
jRoot = json.loads(rsp.text)
jo = jRoot['result']
id = jo['season_id']
title = jo['title']
pic = jo['cover']
areas = jo['areas'][0]['name']
typeName = jo['share_sub_title']
dec = jo['evaluate']
remark = jo['new_ep']['desc']
vod = {
"vod_id":id,
"vod_name":title,
"vod_pic":pic,
"type_name":typeName,
"vod_year":"",
"vod_area":areas,
"vod_remarks":remark,
"vod_actor":"",
"vod_director":"",
"vod_content":dec
}
ja = jo['episodes']
playUrl = ''
for tmpJo in ja:
eid = tmpJo['id']
cid = tmpJo['cid']
part = tmpJo['title'].replace("#", "-")
playUrl = playUrl + '{0}${1}_{2}#'.format(part, eid, cid)
vod['vod_play_from'] = 'B站影视'
vod['vod_play_url'] = playUrl
result = {
'list':[
vod
]
}
return result
def searchContent(self,key,quick):
url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=media_bangumi&keyword={0}'.format(key) # 番剧搜索
if len(self.cookies) <= 0:
self.getCookie()
rsp = self.fetch(url, cookies=self.cookies)
content = rsp.text
jo = json.loads(content)
rs = jo['data']
if rs['numResults'] == 0:
url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=media_ft&keyword={0}'.format(key) # 影视搜索
rspRetry = self.fetch(url, cookies=self.cookies)
content = rspRetry.text
jo = json.loads(content)
videos = []
vodList = jo['data']['result']
for vod in vodList:
aid = str(vod['season_id']).strip()
title = vod['title'].strip().replace("<em class=\"keyword\">", "").replace("</em>", "")
img = vod['eps'][0]['cover'].strip()
remark = vod['index_show']
videos.append({
"vod_id": aid,
"vod_name": title,
"vod_pic": img,
"vod_remarks": remark
})
result = {
'list': videos
}
return result
def playerContent(self,flag,id,vipFlags):
result = {}
ids = id.split("_")
header = {
"Referer": "https://www.bilibili.com",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
}
url = 'https://api.bilibili.com/pgc/player/web/playurl?qn=116&ep_id={0}&cid={1}'.format(ids[0],ids[1])
if len(self.cookies) <= 0:
self.getCookie()
rsp = self.fetch(url,cookies=self.cookies,headers=header)
jRoot = json.loads(rsp.text)
if jRoot['message'] != 'success':
print("需要大会员权限才能观看")
return {}
jo = jRoot['result']
ja = jo['durl']
maxSize = -1
position = -1
for i in range(len(ja)):
tmpJo = ja[i]
if maxSize < int(tmpJo['size']):
maxSize = int(tmpJo['size'])
position = i
url = ''
if len(ja) > 0:
if position == -1:
position = 0
url = ja[position]['url']
result["parse"] = 0
result["playUrl"] = ''
result["url"] = url
result["header"] = {
"Referer":"https://www.bilibili.com",
"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
}
result["contentType"] = 'video/x-flv'
return result
config = {
"player": {},
"filter": {}
}
header = {}
def localProxy(self,param):
return [200, "video/MP2T", action, ""]