forked from heroaku/TVboxo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy_bilibili_gz.py
192 lines (181 loc) · 4.97 KB
/
py_bilibili_gz.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
#coding=utf-8
#!/usr/bin/python
import sys
sys.path.append('..')
from base.spider import Spider
import json
import time
import base64
class Spider(Spider): # 元类 默认的元类 type
def getName(self):
return "哔哩"
def init(self,extend=""):
print("============{0}============".format(extend))
pass
def isVideoFormat(self,url):
pass
def manualVideoCheck(self):
pass
def homeContent(self,filter):
result = {}
cateManual = {
"高一语文": "高一语文",
"高一数学": "高一数学",
"高一英语": "高一英语",
"高一物理": "高一物理",
"高一化学": "高一化学",
"高一生物": "高一生物",
"高一政治": "高一政治",
"高一历史": "高一历史",
"高一地理": "高一地理",
"高二语文": "高二语文",
"高二数学": "高二数学",
"高二英语": "高二英语",
"高二物理": "高二物理",
"高二化学": "高二化学",
"高二生物": "高二生物",
"高二政治": "高二政治",
"高二历史": "高二历史",
"高二地理": "高二地理",
"高三语文": "高三语文",
"高三数学": "高三数学",
"高三英语": "高三英语",
"高三物理": "高三物理",
"高三化学": "高三化学",
"高三生物": "高三生物",
"高三政治": "高三政治",
"高三历史": "高三历史",
"高三地理": "高三地理",
"高中信息技术": "高中信息技术"
}
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):
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/x/web-interface/search/type?search_type=video&keyword={0}&duration=4&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)
if jo['code'] != 0:
rspRetry = self.fetch(url,cookies=self.getCookie())
content = rspRetry.text
jo = json.loads(content)
videos = []
vodList = jo['data']['result']
for vod in vodList:
aid = str(vod['aid']).strip()
title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
img = 'https:' + vod['pic'].strip()
remark = str(vod['duration']).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 = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
rsp = self.fetch(url,headers=self.header)
jRoot = json.loads(rsp.text)
jo = jRoot['data']
title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
pic = jo['pic']
desc = jo['desc']
typeName = jo['tname']
vod = {
"vod_id":aid,
"vod_name":title,
"vod_pic":pic,
"type_name":typeName,
"vod_year":"",
"vod_area":"",
"vod_remarks":"",
"vod_actor":"",
"vod_director":"",
"vod_content":desc
}
ja = jo['pages']
playUrl = ''
for tmpJo in ja:
cid = tmpJo['cid']
part = tmpJo['part']
playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
vod['vod_play_from'] = 'B站'
vod['vod_play_url'] = playUrl
result = {
'list':[
vod
]
}
return result
def searchContent(self,key,quick):
result = {
'list':[]
}
return result
def playerContent(self,flag,id,vipFlags):
# https://www.555dianying.cc/vodplay/static/js/playerconfig.js
result = {}
ids = id.split("_")
url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
rsp = self.fetch(url)
jRoot = json.loads(rsp.text)
jo = jRoot['data']
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, ""]