py_bilibili_v3b.py 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. # coding=utf-8
  2. # !/usr/bin/python
  3. import sys
  4. sys.path.append('..')
  5. from base.spider import Spider
  6. import json
  7. import requests
  8. from requests import session, utils
  9. import os
  10. import time
  11. import base64
  12. from time import strftime
  13. from time import gmtime
  14. class Spider(Spider): # 元类 默认的元类 type
  15. box_video_type = ''
  16. vod_area='bilidanmu'
  17. def getName(self):
  18. return "哔哩3_带直播"
  19. def __init__(self):
  20. self.getCookie()
  21. url = 'http://api.bilibili.com/x/v3/fav/folder/created/list-all?up_mid=%s&jsonp=jsonp' % (self.userid)
  22. rsp = self.fetch(url, cookies=self.cookies)
  23. content = rsp.text
  24. jo = json.loads(content)
  25. fav_list=[]
  26. if jo['code'] == 0:
  27. for fav in jo['data'].get('list'):
  28. fav_dict = {'n':fav['title'].replace("<em class=\"keyword\">", "").replace("</em>", "").replace("&quot;", '"').strip() ,'v':fav['id']}
  29. fav_list.append(fav_dict)
  30. if self.config["filter"].get('收藏夹'):
  31. for i in self.config["filter"].get('收藏夹'):
  32. if i['key']=='mlid':
  33. i['value']=fav_list
  34. def init(self, extend=""):
  35. print("============{0}============".format(extend))
  36. pass
  37. def isVideoFormat(self, url):
  38. pass
  39. def second_to_time(self,a):
  40. #将秒数转化为 时分秒的格式
  41. if a < 3600:
  42. return time.strftime("%M:%S", time.gmtime(a))
  43. else:
  44. return time.strftime("%H:%M:%S", time.gmtime(a))
  45. def manualVideoCheck(self):
  46. pass
  47. #用户userid
  48. userid=''
  49. def get_live_userInfo(self,uid):
  50. url = 'https://api.live.bilibili.com/live_user/v1/Master/info?uid=%s'%uid
  51. rsp = self.fetch(url, cookies=self.cookies)
  52. content = rsp.text
  53. jo = json.loads(content)
  54. if jo['code'] == 0:
  55. return jo['data']["info"]["uname"]
  56. def homeContent(self, filter):
  57. result = {}
  58. cateManual = {
  59. "推荐": "推荐",
  60. "新闻": "新闻",
  61. "热门": "热门",
  62. "排行榜": "排行榜",
  63. "AI孙燕姿": "AI孙燕姿",
  64. "舞蹈": "舞蹈",
  65. "频道": "频道",
  66. "直播": "直播",
  67. "动态": "动态",
  68. "历史记录": '历史记录',
  69. "收藏夹": '收藏夹',
  70. "宅舞": "宅舞",
  71. "少女": "少女",
  72. 'cosplay':'cosplay',
  73. 'mmd':'mmd',
  74. '索尼':'索尼音乐中国',
  75. "鬼畜": "鬼畜",
  76. "狗狗": "汪星人",
  77. '科技': '科技',
  78. "音声": "音声",
  79. "演唱会": "演唱会",
  80. "番剧": "1",
  81. "国创": "4",
  82. "电影": "2",
  83. "综艺": "7",
  84. "电视剧": "5",
  85. "纪录片": "3",
  86. }
  87. classes = []
  88. for k in cateManual:
  89. classes.append({
  90. 'type_name': k,
  91. 'type_id': cateManual[k]
  92. })
  93. result['class'] = classes
  94. if (filter):
  95. result['filters'] = self.config['filter']
  96. return result
  97. def homeVideoContent(self):
  98. self.box_video_type = '热门'
  99. return self.get_hot(pg='1')
  100. cookies = ''
  101. # def getCookie(self):
  102. # # 在cookies_str中填入会员或大会员cookie,以获得更好的体验。
  103. # cookies_str = "buvid3=CFF74DA7-E79E-4B53-BB96-FC74AB8CD2F3184997infoc; LIVE_BUVID=AUTO4216125328906835; rpdid=|(umRum~uY~R0J'uYukYukkkY; balh_is_closed=; balh_server_inner=__custom__; PVID=4; video_page_version=v_old_home; i-wanna-go-back=-1; CURRENT_BLACKGAP=0; blackside_state=0; fingerprint=8965144a609d60190bd051578c610d72; buvid_fp_plain=undefined; CURRENT_QUALITY=120; hit-dyn-v2=1; nostalgia_conf=-1; buvid_fp=CFF74DA7-E79E-4B53-BB96-FC74AB8CD2F3184997infoc; CURRENT_FNVAL=4048; DedeUserID=85342; DedeUserID__ckMd5=f070401c4c699c83; b_ut=5; hit-new-style-dyn=0; buvid4=15C64651-E8B7-100C-4B1F-C7CFD2DB473007906-022110820-jYQRaMeS%2BRXRfw14q70%2FLQ%3D%3D; b_nut=1667910208; b_lsid=3CE4AE79_184578915C0; is-2022-channel=1; innersign=0; SESSDATA=a5e4d58d%2C1683641322%2C2c39a%2Ab1; bili_jct=2f3126b5954e37f593130f2fef082cd8; sid=p7tjqv22; bp_video_offset_85342=726936847258746900"
  104. # cookies_dic = dict([co.strip().split('=') for co in cookies_str.split(';')])
  105. # rsp = session()
  106. # cookies_jar = utils.cookiejar_from_dict(cookies_dic)
  107. # rsp.cookies = cookies_jar
  108. # content = self.fetch("http://api.bilibili.com/x/web-interface/nav", cookies=rsp.cookies)
  109. # res = json.loads(content.text)
  110. # if res["code"] == 0:
  111. # self.cookies = rsp.cookies
  112. # else:
  113. # rsp = self.fetch("https://www.bilibili.com/")
  114. # self.cookies = rsp.cookies
  115. # return rsp.cookies
  116. def getCookie(self):
  117. #在下方cookies_str 后面 双引号里面放置你的cookies
  118. cookies_str = "DedeUserID=516036434; DedeUserID__ckMd5=4e5107a4bc891865;SESSDATA=4fe90c6b%2C1698242168%2C30912%2A41; bili_jct=faffed7de17218860f3aa958182ca2ee"
  119. if cookies_str:
  120. cookies = dict([co.strip().split('=') for co in cookies_str.split(';')])
  121. bili_jct = cookies['bili_jct']
  122. SESSDATA = cookies['SESSDATA']
  123. DedeUserID = cookies['DedeUserID']
  124. cookies_jar={"bili_jct":bili_jct,
  125. 'SESSDATA': SESSDATA,
  126. 'DedeUserID':DedeUserID
  127. }
  128. rsp = session()
  129. rsp.cookies = cookies_jar
  130. content = self.fetch("http://api.bilibili.com/x/web-interface/nav", cookies=rsp.cookies)
  131. res = json.loads(content.text)
  132. if res["code"] == 0:
  133. self.cookies = rsp.cookies
  134. self.userid = res["data"].get('mid')
  135. return rsp.cookies
  136. rsp = self.fetch("https://www.bilibili.com/")
  137. self.cookies = rsp.cookies
  138. return rsp.cookies
  139. def get_rcmd(self, pg):
  140. result = {}
  141. url = 'https://api.bilibili.com/x/web-interface/index/top/feed/rcmd?ps=20&pn={0}'.format(pg)
  142. rsp = self.fetch(url, cookies=self.cookies)
  143. content = rsp.text
  144. jo = json.loads(content)
  145. if jo['code'] == 0:
  146. videos = []
  147. vodList = jo['data']['item']
  148. for vod in vodList:
  149. aid = str(vod['id']).strip()
  150. title = vod['title'].strip().replace("<em class=\"keyword\">", "").replace("</em>", "")
  151. img = vod['pic'].strip()
  152. remark = str(self.second_to_time(vod['duration'])).strip()
  153. videos.append({
  154. "vod_id": aid,
  155. "vod_name": title,
  156. "vod_pic": img,
  157. "vod_remarks": remark
  158. })
  159. result['list'] = videos
  160. result['page'] = pg
  161. result['pagecount'] = 9999
  162. result['limit'] = 90
  163. result['total'] = 999999
  164. return result
  165. def get_hot(self, pg):
  166. result = {}
  167. url = 'https://api.bilibili.com/x/web-interface/popular?ps=20&pn={0}'.format(pg)
  168. rsp = self.fetch(url, cookies=self.cookies)
  169. content = rsp.text
  170. jo = json.loads(content)
  171. if jo['code'] == 0:
  172. videos = []
  173. vodList = jo['data']['list']
  174. for vod in vodList:
  175. aid = str(vod['aid']).strip()
  176. title = vod['title'].strip().replace("<em class=\"keyword\">", "").replace("</em>", "")
  177. img = vod['pic'].strip()
  178. remark = str(self.second_to_time(vod['duration'])).strip()
  179. videos.append({
  180. "vod_id": aid,
  181. "vod_name": title,
  182. "vod_pic": img,
  183. "vod_remarks": remark
  184. })
  185. result['list'] = videos
  186. result['page'] = pg
  187. result['pagecount'] = 9999
  188. result['limit'] = 90
  189. result['total'] = 999999
  190. return result
  191. def str2sec(self,x):
  192. '''
  193. 字符串时分秒转换成秒
  194. '''
  195. x=str(x)
  196. try:
  197. h, m, s = x.strip().split(':') #.split()函数将其通过':'分隔开,.strip()函数用来除去空格
  198. return int(h)*3600 + int(m)*60 + int(s) #int()函数转换成整数运算
  199. except:
  200. m, s = x.strip().split(':') #.split()函数将其通过':'分隔开,.strip()函数用来除去空格
  201. return int(m)*60 + int(s) #int()函数转换成整数运算
  202. def get_rank(self,cid):
  203. result = {}
  204. url = 'https://api.bilibili.com/x/web-interface/ranking/v2?rid={0}&type=all'.format(cid)
  205. rsp = self.fetch(url, cookies=self.cookies)
  206. content = rsp.text
  207. jo = json.loads(content)
  208. if jo['code'] == 0:
  209. videos = []
  210. vodList = jo['data']['list']
  211. for vod in vodList:
  212. aid = str(vod['aid']).strip()
  213. title = vod['title'].strip().replace("<em class=\"keyword\">", "").replace("</em>", "")
  214. img = vod['pic'].strip()
  215. remark = str(self.second_to_time(vod['duration'])).strip()
  216. videos.append({
  217. "vod_id": aid,
  218. "vod_name": title,
  219. "vod_pic": img,
  220. "vod_remarks": remark
  221. })
  222. result['list'] = videos
  223. result['page'] = 1
  224. result['pagecount'] = 1
  225. result['limit'] = 90
  226. result['total'] = 999999
  227. return result
  228. def filter_duration(self, vodlist, key):
  229. # 按时间过滤
  230. if key == '0':
  231. return vodlist
  232. else:
  233. vod_list_new = [i for i in vodlist if self.time_diff1[key][0] <= self.str2sec(str(i["vod_remarks"])) < self.time_diff1[key][1]]
  234. return vod_list_new
  235. chanel_offset=''
  236. def get_channel(self, pg, cid,extend,order,duration_diff):
  237. result = {}
  238. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}&duration={2}&order={3}'.format(
  239. cid, pg,duration_diff,order)
  240. rsp = self.fetch(url, cookies=self.cookies)
  241. content = rsp.text
  242. jo = json.loads(content)
  243. if jo.get('code') == 0:
  244. videos = []
  245. vodList = jo['data']['result']
  246. for vod in vodList:
  247. aid = str(vod['aid']).strip()
  248. title = vod['title'].replace("<em class=\"keyword\">", "").replace("</em>", "").replace("&quot;", '"')
  249. img = 'https:' + vod['pic'].strip()
  250. remark = str( self.second_to_time(self.str2sec(vod['duration']))).strip()
  251. videos.append({
  252. "vod_id": aid,
  253. "vod_name": title,
  254. "vod_pic": img,
  255. "vod_remarks": remark
  256. })
  257. #videos=self.filter_duration(videos, duration_diff)
  258. result['list'] = videos
  259. result['page'] = pg
  260. result['pagecount'] = 9999
  261. result['limit'] = 90
  262. result['total'] = 999999
  263. return result
  264. dynamic_offset = ''
  265. def get_dynamic(self, pg):
  266. result = {}
  267. if str(pg) == '1':
  268. url = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=all&page=%s' % pg
  269. else:
  270. # print('偏移',self.dynamic_offset)
  271. url = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=all&offset=%s&page=%s' % (
  272. self.dynamic_offset, pg)
  273. rsp = self.fetch(url, cookies=self.cookies)
  274. content = rsp.text
  275. jo = json.loads(content)
  276. if jo['code'] == 0:
  277. self.dynamic_offset = jo['data'].get('offset')
  278. videos = []
  279. vodList = jo['data']['items']
  280. for vod in vodList:
  281. if vod['type'] == 'DYNAMIC_TYPE_AV':
  282. #up=vod['modules']["module_author"]['name']
  283. ivod = vod['modules']['module_dynamic']['major']['archive']
  284. aid = str(ivod['aid']).strip()
  285. title = ivod['title'].strip().replace("<em class=\"keyword\">", "").replace("</em>", "")
  286. img = ivod['cover'].strip()
  287. #remark = str(ivod['duration_text']).strip()
  288. remark =str( self.second_to_time(self.str2sec(ivod['duration_text']))).strip()
  289. videos.append({
  290. "vod_id": aid,
  291. "vod_name": title,
  292. "vod_pic": img,
  293. "vod_remarks": remark
  294. })
  295. result['list'] = videos
  296. result['page'] = pg
  297. result['pagecount'] = 9999
  298. result['limit'] = 90
  299. result['total'] = 999999
  300. return result
  301. time_diff1={'1':[0,300],
  302. '2':[300,900],'3':[900,1800],'4':[1800,3600],
  303. '5':[3600,99999999999999999999999999999999]
  304. }
  305. time_diff='0'
  306. def get_fav_detail(self,pg,mlid,order):
  307. result = {}
  308. url = 'http://api.bilibili.com/x/v3/fav/resource/list?media_id=%s&order=%s&pn=%s&ps=20&platform=web&type=0'%(mlid,order,pg)
  309. rsp = self.fetch(url, cookies=self.cookies)
  310. content = rsp.text
  311. jo = json.loads(content)
  312. if jo['code'] == 0:
  313. videos = []
  314. vodList = jo['data']['medias']
  315. for vod in vodList:
  316. #print(vod)
  317. #只展示类型为 视频的条目
  318. #过滤去掉收藏夹中的 已失效视频;如果不喜欢可以去掉这个 if条件
  319. if vod.get('type') in [2] and vod.get('title') != '已失效视频':
  320. aid = str(vod['id']).strip()
  321. title = vod['title'].replace("<em class=\"keyword\">", "").replace("</em>", "").replace("&quot;", '"')
  322. img = vod['cover'].strip()
  323. remark = str( self.second_to_time(vod['duration'])).strip()
  324. videos.append({
  325. "vod_id": aid,
  326. "vod_name": title,
  327. "vod_pic": img,
  328. "vod_remarks": remark
  329. })
  330. #videos=self.filter_duration(videos, duration_diff)
  331. result['list'] = videos
  332. result['page'] = pg
  333. result['pagecount'] = 9999
  334. result['limit'] = 90
  335. result['total'] = 999999
  336. return result
  337. def get_fav(self,pg,order,extend):
  338. #获取自己的up_mid(也就是用户uid)
  339. mlid=''
  340. fav_config=self.config["filter"].get('收藏夹')
  341. #默认显示第一个收藏夹内容
  342. if fav_config:
  343. for i in fav_config:
  344. if i['key']=='mlid':
  345. if len(i['value'])>0:
  346. mlid=i['value'][0]['v']
  347. #print(self.config["filter"].get('收藏夹'))
  348. if 'mlid' in extend:
  349. mlid = extend['mlid']
  350. if mlid:
  351. return self.get_fav_detail(pg=pg,mlid=mlid,order=order)
  352. else:
  353. return {}
  354. def get_history(self,pg):
  355. result = {}
  356. url = 'http://api.bilibili.com/x/v2/history?pn=%s' % pg
  357. rsp = self.fetch(url,cookies=self.cookies)
  358. content = rsp.text
  359. jo = json.loads(content) #解析api接口,转化成json数据对象
  360. if jo['code'] == 0:
  361. videos = []
  362. vodList = jo['data']
  363. for vod in vodList:
  364. if vod['duration'] > 0: #筛选掉非视频的历史记录
  365. aid = str(vod["aid"]).strip() #获取 aid
  366. #获取标题
  367. title = vod["title"].replace("<em class=\"keyword\">", "").replace("</em>", "").replace("&quot;",
  368. '"')
  369. #封面图片
  370. img = vod["pic"].strip()
  371. #获取已观看时间
  372. if str(vod['progress'])=='-1':
  373. process=str(self.second_to_time(vod['duration'])).strip()
  374. else:
  375. process = str(self.second_to_time(vod['progress'])).strip()
  376. #获取视频总时长
  377. total_time= str(self.second_to_time(vod['duration'])).strip()
  378. #组合 已观看时间 / 总时长 ,赋值给 remark
  379. remark = process+' / '+total_time
  380. videos.append({
  381. "vod_id": aid,
  382. "vod_name": title,
  383. "vod_pic": img,
  384. "vod_remarks": remark
  385. })
  386. result['list'] = videos
  387. result['page'] = pg
  388. result['pagecount'] = 9999
  389. result['limit'] = 90
  390. result['total'] = 999999
  391. return result
  392. def get_live(self,pg,parent_area_id):
  393. result = {}
  394. url = 'https://api.live.bilibili.com/room/v3/area/getRoomList?page=%s&sort_type=online&parent_area_id=%s'%(pg,parent_area_id)
  395. rsp = self.fetch(url, cookies=self.cookies)
  396. content = rsp.text
  397. jo = json.loads(content)
  398. if jo['code'] == 0:
  399. videos = []
  400. vodList = jo['data']['list']
  401. for vod in vodList:
  402. aid = str(vod['roomid']).strip()
  403. title = vod['title'].replace("<em class=\"keyword\">", "").replace("</em>", "").replace("&quot;", '"')
  404. img = vod.get('cover').strip()
  405. roomname = str( vod['uname']).strip()+'❤️'+str( vod['online']).strip()
  406. remark = '直播间人数:'+str( vod['online']).strip()
  407. videos.append({
  408. "vod_id": aid,
  409. "vod_name": title,
  410. "vod_pic": img,
  411. "vod_remarks": roomname
  412. })
  413. #videos=self.filter_duration(videos, duration_diff)
  414. result['list'] = videos
  415. result['page'] = pg
  416. result['pagecount'] = 9999
  417. result['limit'] = 90
  418. result['total'] = 999999
  419. return result
  420. def categoryContent(self, tid, pg, filter, extend):
  421. result = {}
  422. if len(self.cookies) <= 0:
  423. self.getCookie()
  424. if tid == "热门":
  425. self.box_video_type = '热门'
  426. return self.get_hot(pg=pg)
  427. elif tid == "推荐":
  428. self.box_video_type = '推荐'
  429. return self.get_rcmd(pg=pg)
  430. elif tid == "排行榜":
  431. self.box_video_type = '排行榜'
  432. cid = '0'
  433. if 'cid' in extend:
  434. cid = extend['cid']
  435. return self.get_rank(cid=cid)
  436. elif tid == "新闻":
  437. self.box_video_type = '新闻'
  438. cid = '新闻&tids=202'
  439. duration_diff='0'
  440. order = 'pubdate'
  441. return self.get_channel(pg=pg, cid=cid,extend=extend,order=order,duration_diff=duration_diff)
  442. elif tid == "收藏夹":
  443. self.box_video_type = '收藏夹'
  444. order = 'mtime'
  445. if 'order' in extend:
  446. order = extend['order']
  447. return self.get_fav(pg=pg, order=order,extend=extend)
  448. elif tid == '直播':
  449. self.box_video_type = '直播'
  450. parent_area_id = '1&area_id=207'
  451. if 'parent_area_id' in extend:
  452. parent_area_id = extend['parent_area_id']
  453. return self.get_live(pg=pg,parent_area_id=parent_area_id)
  454. elif tid == '舞蹈':
  455. self.box_video_type = '舞蹈'
  456. cid = '舞蹈'
  457. if 'cid' in extend:
  458. cid = extend['cid']
  459. duration_diff='0'
  460. if 'duration' in extend:
  461. duration_diff = extend['duration']
  462. order = 'pubdate'
  463. if 'order' in extend:
  464. order = extend['order']
  465. return self.get_channel(pg=pg, cid=cid,extend=extend,order=order,duration_diff=duration_diff)
  466. elif tid == 'AI孙燕姿':
  467. self.box_video_type = 'AI孙燕姿'
  468. cid = 'AI孙燕姿'
  469. duration_diff='0'
  470. if 'duration' in extend:
  471. duration_diff = extend['duration']
  472. order = 'pubdate'
  473. if 'order' in extend:
  474. order = extend['order']
  475. return self.get_channel(pg=pg, cid=cid,extend=extend,order=order,duration_diff=duration_diff)
  476. elif tid == '频道':
  477. self.box_video_type = '频道'
  478. cid = '生活'
  479. if 'cid' in extend:
  480. cid = extend['cid']
  481. duration_diff='0'
  482. if 'duration' in extend:
  483. duration_diff = extend['duration']
  484. order = 'pubdate'
  485. if 'order' in extend:
  486. order = extend['order']
  487. return self.get_channel(pg=pg, cid=cid,extend=extend,order=order,duration_diff=duration_diff)
  488. elif tid == '动态':
  489. self.box_video_type = '动态'
  490. return self.get_dynamic(pg=pg)
  491. elif tid == '历史记录':
  492. self.box_video_type = '历史记录'
  493. return self.get_history(pg=pg)
  494. elif tid.isdigit():
  495. self.box_video_type = '影视'
  496. 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(
  497. tid, pg)
  498. rsp = self.fetch(url, cookies=self.cookies)
  499. content = rsp.text
  500. jo = json.loads(content)
  501. videos = []
  502. vodList = jo['data']['list']
  503. for vod in vodList:
  504. aid = str(vod['season_id']).strip()
  505. title = vod['title'].strip()
  506. img = vod['cover'].strip()
  507. remark = vod['index_show'].strip()
  508. videos.append({
  509. "vod_id": aid,
  510. "vod_name": title,
  511. "vod_pic": img,
  512. "vod_remarks": remark # 视频part数量
  513. })
  514. result['list'] = videos
  515. result['page'] = pg
  516. result['pagecount'] = 9999
  517. result['limit'] = 90
  518. result['total'] = 999999
  519. else:
  520. duration_diff='0'
  521. if 'duration' in extend:
  522. duration_diff = extend['duration']
  523. order = 'totalrank'
  524. if 'order' in extend:
  525. order = extend['order']
  526. self.box_video_type = '其他'
  527. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}&duration={2}&order={3}'.format(
  528. tid, pg,duration_diff,order)
  529. rsp = self.fetch(url, cookies=self.cookies)
  530. content = rsp.text
  531. jo = json.loads(content)
  532. if jo.get('code') == 0:
  533. videos = []
  534. vodList = jo['data']['result']
  535. for vod in vodList:
  536. aid = str(vod['aid']).strip()
  537. title = vod['title'].replace("<em class=\"keyword\">", "").replace("</em>", "").replace("&quot;", '"')
  538. img = 'https:' + vod['pic'].strip()
  539. #remark = str(vod['duration']).strip()
  540. remark =str( self.second_to_time(self.str2sec(vod['duration']))).strip()
  541. videos.append({
  542. "vod_id": aid,
  543. "vod_name": title,
  544. "vod_pic": img,
  545. "vod_remarks": remark
  546. })
  547. #videos=self.filter_duration(videos, duration_diff)
  548. result['list'] = videos
  549. result['page'] = pg
  550. result['pagecount'] = 9999
  551. result['limit'] = 90
  552. result['total'] = 999999
  553. return result
  554. def cleanSpace(self, str):
  555. return str.replace('\n', '').replace('\t', '').replace('\r', '').replace(' ', '')
  556. def detailContent(self, array):
  557. # if int(array[0])< 1000000:
  558. result={}
  559. if self.box_video_type == '影视':
  560. aid = array[0]
  561. url = "http://api.bilibili.com/pgc/view/web/season?season_id={0}".format(aid)
  562. rsp = self.fetch(url, headers=self.header)
  563. jRoot = json.loads(rsp.text)
  564. if jRoot['code'] == 0:
  565. jo = jRoot['result']
  566. id = jo['season_id']
  567. title = jo['title']
  568. pic = jo['cover']
  569. areas = jo['areas'][0]['name']
  570. typeName = jo['share_sub_title']
  571. dec = jo['evaluate']
  572. remark = jo['new_ep']['desc']
  573. vod = {
  574. "vod_id": id,
  575. "vod_name": title,
  576. "vod_pic": pic,
  577. "type_name": typeName,
  578. "vod_year": "",
  579. # "vod_area":areas,
  580. "vod_area": self.vod_area, #弹幕是否显示的开关
  581. "vod_remarks": remark,
  582. "vod_actor": "",
  583. "vod_director": "",
  584. "vod_content": dec
  585. }
  586. ja = jo['episodes']
  587. playUrl = ''
  588. for tmpJo in ja:
  589. eid = tmpJo['id']
  590. cid = tmpJo['cid']
  591. part = tmpJo['title'].replace("#", "-")
  592. playUrl = playUrl + '{0}${1}_{2}#'.format(part, eid, cid)
  593. vod['vod_play_from'] = 'B站'
  594. vod['vod_play_url'] = playUrl
  595. result = {
  596. 'list': [
  597. vod
  598. ]
  599. }
  600. elif self.box_video_type == '直播':
  601. aid = array[0]
  602. url = "https://api.live.bilibili.com/room/v1/Room/get_info?room_id=%s"%aid
  603. rsp = self.fetch(url, headers=self.header,cookies=self.cookies)
  604. jRoot = json.loads(rsp.text)
  605. if jRoot.get('code')==0:
  606. jo = jRoot['data']
  607. title = jo['title'].replace("<em class=\"keyword\">", "").replace("</em>", "")
  608. pic = jo.get("user_cover")
  609. desc = jo.get('description')
  610. dire = self.get_live_userInfo(jo["uid"])
  611. typeName = jo.get("area_name")
  612. area = jo.get("parent_area_name")
  613. remark = '在线人数:'+str(jo['online']).strip()
  614. playUrl = 'flv线路原画$platform=web&quality=4_' + aid + '#flv线路高清$platform=web&quality=3_' + aid + '#h5线路原画$platform=h5&quality=4_' + aid + '#h5线路高清$platform=h5&quality=3_' + aid
  615. vod = {
  616. "vod_id": aid,
  617. "vod_name": '(' + dire + ")" + title,
  618. "vod_pic": pic,
  619. "type_name": typeName,
  620. "vod_area": area,
  621. #"vod_area":"",
  622. "vod_remarks": remark,
  623. "vod_actor": "",
  624. "vod_director": dire,
  625. "vod_content": desc + 'up主:' + dire,
  626. 'vod_play_from':'B站',
  627. 'vod_play_url':playUrl,
  628. }
  629. result = {
  630. 'list': [
  631. vod
  632. ]
  633. }
  634. else:
  635. aid = array[0]
  636. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  637. rsp = self.fetch(url, headers=self.header)
  638. jRoot = json.loads(rsp.text)
  639. if jRoot['code'] == 0:
  640. jo = jRoot['data']
  641. title = jo['title'].replace("<em class=\"keyword\">", "").replace("</em>", "")
  642. pic = jo['pic']
  643. desc = jo['desc']
  644. timeStamp = jo['pubdate']
  645. timeArray = time.localtime(timeStamp)
  646. tim = str(time.strftime("%Y-%m-%d %H:%M:%S", timeArray))
  647. year = str(time.strftime("%Y", timeArray))
  648. m = str(time.strftime("%m", timeArray))
  649. d = str(time.strftime("%d", timeArray))
  650. h = str(time.strftime("%H", timeArray))
  651. m1 = str(time.strftime("%M", timeArray))
  652. s = str(time.strftime("%S", timeArray))
  653. dire = jo['owner']['name']
  654. typeName = jo['tname']
  655. remark = str(jo['duration']).strip()
  656. vod = {
  657. "vod_id": aid,
  658. "vod_name": '🔥标题 : ' + title,
  659. "vod_pic": pic,
  660. "type_name": typeName,
  661. "vod_year": year,
  662. "vod_area": self.vod_area,
  663. # "vod_area":"",
  664. "vod_remarks": remark,
  665. "vod_actor": tim,
  666. "vod_director": '🔥UP主:'+dire+'❤️❤️日期:'+year+'-'+m+'-'+d+' '+h+':'+m1+':'+s,
  667. "vod_content": desc + 'up主:' + dire
  668. }
  669. ja = jo['pages']
  670. playUrl = ''
  671. for tmpJo in ja:
  672. cid = tmpJo['cid']
  673. part = tmpJo['part'].replace("#", "-")
  674. playUrl = playUrl + '{0}${1}_{2}#'.format(part, aid, cid)
  675. vod['vod_play_from'] = 'B站'
  676. vod['vod_play_url'] = playUrl
  677. result = {
  678. 'list': [
  679. vod
  680. ]
  681. }
  682. return result
  683. def searchContent(self, key, quick):
  684. self.box_video_type = '搜索'
  685. header = {
  686. "Referer": "https://www.bilibili.com",
  687. "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
  688. }
  689. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page=1'.format(key)
  690. rsp = self.fetch(url, cookies=self.cookies, headers=header)
  691. content = rsp.text
  692. jo = json.loads(content)
  693. if jo['code'] != 0:
  694. rspRetry = self.fetch(url, cookies=self.cookies, headers=header)
  695. content = rspRetry.text
  696. jo = json.loads(content)
  697. videos = []
  698. vodList = jo['data']['result']
  699. for vod in vodList:
  700. aid = str(vod['aid']).strip()
  701. title = vod['title'].replace("<em class=\"keyword\">", "").replace("</em>", "").replace("&quot;", '"')
  702. img = 'https:' + vod['pic'].strip()
  703. remark = str(vod['duration']).strip()
  704. videos.append({
  705. "vod_id": aid,
  706. "vod_name": title,
  707. "vod_pic": img,
  708. "vod_remarks": remark
  709. })
  710. result = {
  711. 'list': videos
  712. }
  713. return result
  714. def playerContent(self, flag, id, vipFlags):
  715. result = {}
  716. if self.box_video_type == '影视':
  717. ids = id.split("_")
  718. header = {
  719. "Referer": "https://www.bilibili.com",
  720. "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
  721. }
  722. url = 'https://api.bilibili.com/pgc/player/web/playurl?qn=116&ep_id={0}&cid={1}'.format(ids[0], ids[1])
  723. if len(self.cookies) <= 0:
  724. self.getCookie()
  725. rsp = self.fetch(url, cookies=self.cookies, headers=header)
  726. jRoot = json.loads(rsp.text)
  727. if jRoot['message'] != 'success':
  728. print("需要大会员权限才能观看")
  729. return {}
  730. jo = jRoot['result']
  731. ja = jo['durl']
  732. maxSize = -1
  733. position = -1
  734. for i in range(len(ja)):
  735. tmpJo = ja[i]
  736. if maxSize < int(tmpJo['size']):
  737. maxSize = int(tmpJo['size'])
  738. position = i
  739. url = ''
  740. if len(ja) > 0:
  741. if position == -1:
  742. position = 0
  743. url = ja[position]['url']
  744. result["parse"] = 0
  745. result["playUrl"] = ''
  746. result["url"] = url
  747. result["header"] = {
  748. "Referer": "https://www.bilibili.com",
  749. "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
  750. }
  751. result["contentType"] = 'video/x-flv'
  752. elif self.box_video_type == '直播':
  753. ids = id.split("_")
  754. url = 'https://api.live.bilibili.com/room/v1/Room/playUrl?cid=%s&%s' % (ids[1], ids[0])
  755. if len(self.cookies) <= 0:
  756. self.getCookie()
  757. rsp = self.fetch(url, cookies=self.cookies)
  758. jRoot = json.loads(rsp.text)
  759. if jRoot['code'] == 0:
  760. jo = jRoot['data']
  761. ja = jo['durl']
  762. url = ''
  763. if len(ja) > 0:
  764. url = ja[0]['url']
  765. result["parse"] = 0
  766. # result['type'] ="m3u8"
  767. result["playUrl"] = ''
  768. result["url"] = url
  769. result["header"] = {
  770. "Referer": "https://live.bilibili.com",
  771. "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
  772. }
  773. else:
  774. ids = id.split("_")
  775. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid={1}&qn=116'.format(ids[0], ids[1])
  776. if len(self.cookies) <= 0:
  777. self.getCookie()
  778. rsp = self.fetch(url, cookies=self.cookies)
  779. jRoot = json.loads(rsp.text)
  780. jo = jRoot['data']
  781. ja = jo['durl']
  782. maxSize = -1
  783. position = -1
  784. for i in range(len(ja)):
  785. tmpJo = ja[i]
  786. if maxSize < int(tmpJo['size']):
  787. maxSize = int(tmpJo['size'])
  788. position = i
  789. url = ''
  790. if len(ja) > 0:
  791. if position == -1:
  792. position = 0
  793. url = ja[position]['url']
  794. result["parse"] = 0
  795. result["playUrl"] = ''
  796. result["url"] = url
  797. result["header"] = {
  798. "Referer": "https://www.bilibili.com",
  799. "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
  800. }
  801. result["contentType"] = 'video/x-flv'
  802. return result
  803. config = {
  804. "player": {},
  805. "filter": {
  806. "PD": [{
  807. "key": "cid",
  808. "name": "频道",
  809. "value": [
  810. {
  811. "n": "全部",
  812. "v": "0"
  813. },
  814. {'n': '搞笑', 'v': 1833}, {'n': '美食', 'v': 20215}, {'n': '鬼畜', 'v': 68}, {'n': '天官赐福', 'v': 2544632}, {'n': '英雄联盟', 'v': 9222}, {'n': '美妆', 'v': 832569}, {'n': '必剪创作', 'v': 15775524}, {'n': '单机游戏', 'v': 17683}, {'n': '搞笑', 'v': 1833}, {'n': '科普', 'v': 5417}, {'n': '影视剪辑', 'v': 318570}, {'n': 'vlog', 'v': 2511282}, {'n': '声优', 'v': 1645}, {'n': '动漫杂谈', 'v': 530918}, {'n': 'COSPLAY', 'v': 88}, {'n': '漫展', 'v': 22551}, {'n': 'MAD', 'v': 281}, {'n': '手书', 'v': 608}, {'n': '英雄联盟', 'v': 9222}, {'n': '王者荣耀', 'v': 1404375}, {'n': '单机游戏', 'v': 17683}, {'n': '我的世界', 'v': 47988}, {'n': '守望先锋', 'v': 926988}, {'n': '恐怖游戏', 'v': 17941}, {'n': '英雄联盟', 'v': 9222}, {'n': '王者荣耀', 'v': 1404375}, {'n': '守望先锋', 'v': 926988}, {'n': '炉石传说', 'v': 318756}, {'n': 'DOTA2', 'v': 47034}, {'n': 'CS:GO', 'v': 99842}, {'n': '鬼畜', 'v': 68}, {'n': '鬼畜调教', 'v': 497221}, {'n': '诸葛亮', 'v': 51330}, {'n': '二次元鬼畜', 'v': 29415}, {'n': '王司徒', 'v': 987568}, {'n': '万恶之源', 'v': 21}, {'n': '美妆', 'v': 832569}, {'n': '服饰', 'v': 313718}, {'n': '减肥', 'v': 20805}, {'n': '穿搭', 'v': 1139735}, {'n': '发型', 'v': 13896}, {'n': '化妆教程', 'v': 261355}, {'n': '电音', 'v': 14426}, {'n': '欧美音乐', 'v': 17034}, {'n': '中文翻唱', 'v': 8043}, {'n': '洛天依', 'v': 8564}, {'n': '翻唱', 'v': 386}, {'n': '日文翻唱', 'v': 85689}, {'n': '科普', 'v': 5417}, {'n': '技术宅', 'v': 368}, {'n': '历史', 'v': 221}, {'n': '科学', 'v': 1364}, {'n': '人文', 'v': 40737}, {'n': '科幻', 'v': 5251}, {'n': '手机', 'v': 7007}, {'n': '手机评测', 'v': 143751}, {'n': '电脑', 'v': 1339}, {'n': '摄影', 'v': 25450}, {'n': '笔记本', 'v': 1338}, {'n': '装机', 'v': 413678}, {'n': '课堂教育', 'v': 3233375}, {'n': '公开课', 'v': 31864}, {'n': '演讲', 'v': 2739}, {'n': 'PS教程', 'v': 335752}, {'n': '编程', 'v': 28784}, {'n': '英语学习', 'v': 360005}, {'n': '喵星人', 'v': 1562}, {'n': '萌宠', 'v': 6943}, {'n': '汪星人', 'v': 9955}, {'n': '大熊猫', 'v': 22919}, {'n': '柴犬', 'v': 30239}, {'n': '吱星人', 'v': 6947}, {'n': '美食', 'v': 20215}, {'n': '甜点', 'v': 35505}, {'n': '吃货', 'v': 6942}, {'n': '厨艺', 'v': 239855}, {'n': '烘焙', 'v': 218245}, {'n': '街头美食', 'v': 1139423}, {'n': 'A.I.Channel', 'v': 3232987}, {'n': '虚拟UP主', 'v': 4429874}, {'n': '神楽めあ', 'v': 7562902}, {'n': '白上吹雪', 'v': 7355391}, {'n': '彩虹社', 'v': 1099778}, {'n': 'hololive', 'v': 8751822}, {'n': 'EXO', 'v': 191032}, {'n': '防弹少年团', 'v': 536395}, {'n': '肖战', 'v': 1450880}, {'n': '王一博', 'v': 902215}, {'n': '易烊千玺', 'v': 15186}, {'n': 'BLACKPINK', 'v': 1749296}, {'n': '宅舞', 'v': 9500}, {'n': '街舞', 'v': 5574}, {'n': '舞蹈教学', 'v': 157087}, {'n': '明星舞蹈', 'v': 6012204}, {'n': '韩舞', 'v': 159571}, {'n': '古典舞', 'v': 161247}, {'n': '旅游', 'v': 6572}, {'n': '绘画', 'v': 2800}, {'n': '手工', 'v': 11265}, {'n': 'vlog', 'v': 2511282}, {'n': 'DIY', 'v': 3620}, {'n': '手绘', 'v': 1210}, {'n': '综艺', 'v': 11687}, {'n': '国家宝藏', 'v': 105286}, {'n': '脱口秀', 'v': 4346}, {'n': '日本综艺', 'v': 81265}, {'n': '国内综艺', 'v': 641033}, {'n': '人类观察', 'v': 282453}, {'n': '影评', 'v': 111377}, {'n': '电影解说', 'v': 1161117}, {'n': '影视混剪', 'v': 882598}, {'n': '影视剪辑', 'v': 318570}, {'n': '漫威', 'v': 138600}, {'n': '超级英雄', 'v': 13881}, {'n': '影视混剪', 'v': 882598}, {'n': '影视剪辑', 'v': 318570}, {'n': '诸葛亮', 'v': 51330}, {'n': '韩剧', 'v': 53056}, {'n': '王司徒', 'v': 987568}, {'n': '泰剧', 'v': 179103}, {'n': '郭德纲', 'v': 8892}, {'n': '相声', 'v': 5783}, {'n': '张云雷', 'v': 1093613}, {'n': '秦霄贤', 'v': 3327368}, {'n': '孟鹤堂', 'v': 1482612}, {'n': '岳云鹏', 'v': 24467}, {'n': '假面骑士', 'v': 2069}, {'n': '特摄', 'v': 2947}, {'n': '奥特曼', 'v': 963}, {'n': '迪迦奥特曼', 'v': 13784}, {'n': '超级战队', 'v': 32881}, {'n': '铠甲勇士', 'v': 11564}, {'n': '健身', 'v': 4344}, {'n': '篮球', 'v': 1265}, {'n': '体育', 'v': 41103}, {'n': '帕梅拉', 'v': 257412}, {'n': '极限运动', 'v': 8876}, {'n': '足球', 'v': 584}, {'n': '星海', 'v': 178862}, {'n': '张召忠', 'v': 116480}, {'n': '航母', 'v': 57834}, {'n': '航天', 'v': 81618}, {'n': '导弹', 'v': 14958}, {'n': '战斗机', 'v': 24304}
  815. ]
  816. }],
  817. "排行榜": [{
  818. "key": "cid",
  819. "name": "分区",
  820. "value": [
  821. {
  822. "n": "全部",
  823. "v": "0"
  824. },
  825. {"n": "舞蹈","v": "129"},{"n": "音乐","v": "3"},{'n': '生活', 'v': '160'},{'n': '美食', 'v': '211'},{'n': '动物圈', 'v': '217'},{'n': '鬼畜', 'v': '119'},{'n': '时尚', 'v': '155'},{'n': '娱乐', 'v': '5'},{'n': '影视', 'v': '181'},{"n": "游戏","v": "4"},{"n": "知识","v": "36"},{'n': '科技', 'v': '188'},{'n': '运动', 'v': '234'},{'n': '汽车', 'v': '223'},{'n': '国创相关', 'v': '168'},{'n': '动画', 'v': '1'},{'n': '原创', 'v': '0&type=origin'},{'n': '新人', 'v': '0&type=rookie'}
  826. ]
  827. }],
  828. "舞蹈": [{
  829. "key": "order",
  830. "name": "排序",
  831. "value": [
  832. {
  833. "n": "综合排序",
  834. "v": "totalrank"
  835. },
  836. {
  837. "n": "最新发布",
  838. "v": "pubdate"
  839. },
  840. {
  841. "n": "最多点击",
  842. "v": "click"
  843. },
  844. {
  845. "n": "最多收藏",
  846. "v": "stow"
  847. },
  848. {
  849. "n": "最多弹幕",
  850. "v": "dm"
  851. },
  852. ]
  853. },
  854. {"key": "cid", "name": "分类",
  855. "value":[{'n': '斗鱼', 'v': '斗鱼舞蹈'},{'n': '虎牙', 'v': '虎牙舞蹈'}, {'n': '王雨檬', 'v': '王雨檬'}, {'n': '萌七', 'v': '萌七'}, {'n': '米娜', 'v': '米娜呀'}, {'n': '周淑怡', 'v': '周淑怡'}, {'n': '沫子', 'v': '沫子'}]
  856. },
  857. {
  858. "key": "duration",
  859. "name": "时长",
  860. "value": [{
  861. "n": "全部",
  862. "v": "0"
  863. },
  864. {
  865. "n": "60分钟以上",
  866. "v": "4"
  867. },
  868. {
  869. "n": "30~60分钟",
  870. "v": "3"
  871. },
  872. {
  873. "n": "5~30分钟",
  874. "v": "2"
  875. },
  876. {
  877. "n": "5分钟以下",
  878. "v": "1"
  879. }
  880. ]
  881. }],
  882. "少女": [{
  883. "key": "order",
  884. "name": "排序",
  885. "value": [
  886. {
  887. "n": "综合排序",
  888. "v": "totalrank"
  889. },
  890. {
  891. "n": "最新发布",
  892. "v": "pubdate"
  893. },
  894. {
  895. "n": "最多点击",
  896. "v": "click"
  897. },
  898. {
  899. "n": "最多收藏",
  900. "v": "stow"
  901. },
  902. {
  903. "n": "最多弹幕",
  904. "v": "dm"
  905. },
  906. ]
  907. },
  908. {
  909. "key": "duration",
  910. "name": "时长",
  911. "value": [{
  912. "n": "全部",
  913. "v": "0"
  914. },
  915. {
  916. "n": "60分钟以上",
  917. "v": "4"
  918. },
  919. {
  920. "n": "30~60分钟",
  921. "v": "3"
  922. },
  923. {
  924. "n": "5~30分钟",
  925. "v": "2"
  926. },
  927. {
  928. "n": "5分钟以下",
  929. "v": "1"
  930. }
  931. ]
  932. }],
  933. "AI孙燕姿": [{
  934. "key": "order",
  935. "name": "排序",
  936. "value": [
  937. {
  938. "n": "综合排序",
  939. "v": "totalrank"
  940. },
  941. {
  942. "n": "最新发布",
  943. "v": "pubdate"
  944. },
  945. {
  946. "n": "最多点击",
  947. "v": "click"
  948. },
  949. {
  950. "n": "最多收藏",
  951. "v": "stow"
  952. },
  953. {
  954. "n": "最多弹幕",
  955. "v": "dm"
  956. },
  957. ]
  958. },
  959. {
  960. "key": "duration",
  961. "name": "时长",
  962. "value": [{
  963. "n": "全部",
  964. "v": "0"
  965. },
  966. {
  967. "n": "60分钟以上",
  968. "v": "4"
  969. },
  970. {
  971. "n": "30~60分钟",
  972. "v": "3"
  973. },
  974. {
  975. "n": "5~30分钟",
  976. "v": "2"
  977. },
  978. {
  979. "n": "5分钟以下",
  980. "v": "1"
  981. }
  982. ]
  983. }],
  984. "mmd": [{
  985. "key": "order",
  986. "name": "排序",
  987. "value": [
  988. {
  989. "n": "综合排序",
  990. "v": "totalrank"
  991. },
  992. {
  993. "n": "最新发布",
  994. "v": "pubdate"
  995. },
  996. {
  997. "n": "最多点击",
  998. "v": "click"
  999. },
  1000. {
  1001. "n": "最多收藏",
  1002. "v": "stow"
  1003. },
  1004. {
  1005. "n": "最多弹幕",
  1006. "v": "dm"
  1007. },
  1008. ]
  1009. },
  1010. {
  1011. "key": "duration",
  1012. "name": "时长",
  1013. "value": [{
  1014. "n": "全部",
  1015. "v": "0"
  1016. },
  1017. {
  1018. "n": "60分钟以上",
  1019. "v": "4"
  1020. },
  1021. {
  1022. "n": "30~60分钟",
  1023. "v": "3"
  1024. },
  1025. {
  1026. "n": "5~30分钟",
  1027. "v": "2"
  1028. },
  1029. {
  1030. "n": "5分钟以下",
  1031. "v": "1"
  1032. }
  1033. ]
  1034. }],
  1035. "索尼音乐中国": [{
  1036. "key": "order",
  1037. "name": "排序",
  1038. "value": [
  1039. {
  1040. "n": "综合排序",
  1041. "v": "totalrank"
  1042. },
  1043. {
  1044. "n": "最新发布",
  1045. "v": "pubdate"
  1046. },
  1047. {
  1048. "n": "最多点击",
  1049. "v": "click"
  1050. },
  1051. {
  1052. "n": "最多收藏",
  1053. "v": "stow"
  1054. },
  1055. {
  1056. "n": "最多弹幕",
  1057. "v": "dm"
  1058. },
  1059. ]
  1060. },
  1061. {
  1062. "key": "duration",
  1063. "name": "时长",
  1064. "value": [{
  1065. "n": "全部",
  1066. "v": "0"
  1067. },
  1068. {
  1069. "n": "60分钟以上",
  1070. "v": "4"
  1071. },
  1072. {
  1073. "n": "30~60分钟",
  1074. "v": "3"
  1075. },
  1076. {
  1077. "n": "5~30分钟",
  1078. "v": "2"
  1079. },
  1080. {
  1081. "n": "5分钟以下",
  1082. "v": "1"
  1083. }
  1084. ]
  1085. }],
  1086. "直播": [{
  1087. "key": "parent_area_id",
  1088. "name": "直播分区",
  1089. "value": [
  1090. {
  1091. "n": "全部分区",
  1092. "v": "0"
  1093. },
  1094. {
  1095. "n": "娱乐",
  1096. "v": "1"
  1097. },
  1098. {
  1099. "n": "电台",
  1100. "v": "5"
  1101. },
  1102. {
  1103. "n": "网游",
  1104. "v": "2"
  1105. },
  1106. {
  1107. "n": "手游",
  1108. "v": "3"
  1109. },
  1110. {
  1111. "n": "单机游戏",
  1112. "v": "6"
  1113. },
  1114. {
  1115. "n": "虚拟主播",
  1116. "v": "9"
  1117. },{'n': '生活', 'v': 10},
  1118. {'n': '知识', 'v': 11},
  1119. {'n': '赛事', 'v': 13}
  1120. ]
  1121. },
  1122. {
  1123. "key": "parent_area_id",
  1124. "name": "娱乐",
  1125. "value": [{"n": "娱乐全部","v": "1"},{"n":"视频唱见","v":"1&area_id=21"},{"n":"萌宅领域","v":"1&area_id=530"},{"n":"视频聊天","v":"1&area_id=145"},{"n":"舞见","v":"1&area_id=207"},{"n":"情感","v":"1&area_id=706"},{"n":"户外","v":"1&area_id=123"},{"n":"日常","v":"1&area_id=399"}]
  1126. },
  1127. {
  1128. "key": "parent_area_id",
  1129. "name": "生活",
  1130. "value": [{"n":"生活全部","v":"10"},{"n":"生活分享","v":"10&area_id=646"},{"n":"运动","v":"10&area_id=628"},{"n":"搞笑","v":"10&area_id=624"},{"n":"手工绘画","v":"10&area_id=627"},{"n":"萌宠","v":"10&area_id=369"},{"n":"美食","v":"10&area_id=367"},{"n":"时尚","v":"10&area_id=378"},{"n":"影音馆","v":"10&area_id=33"}]
  1131. },
  1132. ],
  1133. "音声": [{
  1134. "key": "order",
  1135. "name": "排序",
  1136. "value": [
  1137. {
  1138. "n": "综合排序",
  1139. "v": "totalrank"
  1140. },
  1141. {
  1142. "n": "最新发布",
  1143. "v": "pubdate"
  1144. },
  1145. {
  1146. "n": "最多点击",
  1147. "v": "click"
  1148. },
  1149. {
  1150. "n": "最多收藏",
  1151. "v": "stow"
  1152. },
  1153. {
  1154. "n": "最多弹幕",
  1155. "v": "dm"
  1156. },
  1157. ]
  1158. },
  1159. {
  1160. "key": "duration",
  1161. "name": "时长",
  1162. "value": [{
  1163. "n": "全部",
  1164. "v": "0"
  1165. },
  1166. {
  1167. "n": "60分钟以上",
  1168. "v": "4"
  1169. },
  1170. {
  1171. "n": "30~60分钟",
  1172. "v": "3"
  1173. },
  1174. {
  1175. "n": "5~30分钟",
  1176. "v": "2"
  1177. },
  1178. {
  1179. "n": "5分钟以下",
  1180. "v": "1"
  1181. }
  1182. ]
  1183. }],
  1184. "收藏夹": [{
  1185. "key": "order",
  1186. "name": "排序",
  1187. "value": [
  1188. {
  1189. "n": "收藏时间",
  1190. "v": "mtime"
  1191. },
  1192. {
  1193. "n": "播放量",
  1194. "v": "view"
  1195. },
  1196. {
  1197. "n": "投稿时间",
  1198. "v": "pubtime"
  1199. }
  1200. ]
  1201. },
  1202. {
  1203. "key": "mlid",
  1204. "name": "收藏夹分区",
  1205. "value": [
  1206. ]
  1207. }],
  1208. "cosplay": [{
  1209. "key": "order",
  1210. "name": "排序",
  1211. "value": [
  1212. {
  1213. "n": "综合排序",
  1214. "v": "totalrank"
  1215. },
  1216. {
  1217. "n": "最新发布",
  1218. "v": "pubdate"
  1219. },
  1220. {
  1221. "n": "最多点击",
  1222. "v": "click"
  1223. },
  1224. {
  1225. "n": "最多收藏",
  1226. "v": "stow"
  1227. },
  1228. {
  1229. "n": "最多弹幕",
  1230. "v": "dm"
  1231. },
  1232. ]
  1233. },
  1234. {
  1235. "key": "duration",
  1236. "name": "时长",
  1237. "value": [{
  1238. "n": "全部",
  1239. "v": "0"
  1240. },
  1241. {
  1242. "n": "60分钟以上",
  1243. "v": "4"
  1244. },
  1245. {
  1246. "n": "30~60分钟",
  1247. "v": "3"
  1248. },
  1249. {
  1250. "n": "5~30分钟",
  1251. "v": "2"
  1252. },
  1253. {
  1254. "n": "5分钟以下",
  1255. "v": "1"
  1256. }
  1257. ]
  1258. }],
  1259. "频道": [
  1260. {"key": "cid", "name": "分类",
  1261. "value":[{'n': '生活', 'v': '生活'},{'n': '搞笑', 'v': '搞笑'}, {'n': '美食', 'v': '美食'}, {'n': '鬼畜', 'v': '鬼畜'}, {'n': '美妆', 'v': '美妆'}, {'n': 'mmd', 'v': 'mmd'},
  1262. {'n': '科普', 'v': '科普'}, {'n': 'COSPLAY', 'v': 'COSPLAY'}, {'n': '漫展', 'v': '漫展'}, {'n': 'MAD', 'v': 'MAD'}, {'n': '手书', 'v': '手书'},
  1263. {'n': '穿搭', 'v': '穿搭'}, {'n': '发型', 'v': '发型'}, {'n': '化妆教程', 'v': '化妆教程'},
  1264. {'n': '电音', 'v': '电音'}, {'n': '欧美音乐', 'v': '欧美音乐'}, {'n': '中文翻唱', 'v': '中文翻唱'}, {'n': '洛天依', 'v': '洛天依'}, {'n': '翻唱', 'v': '翻唱'}, {'n': '日文翻唱', 'v': '日文翻唱'},
  1265. {'n': '科普', 'v': '科普'}, {'n': '技术宅', 'v': '技术宅'}, {'n': '历史', 'v': '历史'}, {'n': '科学', 'v': '科学'}, {'n': '人文', 'v': '人文'}, {'n': '科幻', 'v': '科幻'},
  1266. {'n': '手机', 'v': '手机'}, {'n': '手机评测', 'v': '手机评测'}, {'n': '电脑', 'v': '电脑'}, {'n': '摄影', 'v': '摄影'}, {'n': '笔记本', 'v': '笔记本'}, {'n': '装机', 'v': '装机'},
  1267. {'n': '课堂教育', 'v': '课堂教育'}, {'n': '公开课', 'v': '公开课'}, {'n': '演讲', 'v': '演讲'}, {'n': 'PS教程', 'v': 'PS教程'}, {'n': '编程', 'v': '编程'}, {'n': '英语学习', 'v': '英语学习'},
  1268. {'n': '喵星人', 'v': '喵星人'}, {'n': '萌宠', 'v': '萌宠'}, {'n': '汪星人', 'v': '汪星人'}, {'n': '大熊猫', 'v': '大熊猫'}, {'n': '柴犬', 'v': '柴犬'},{'n': '田园犬', 'v': '田园犬'}, {'n': '吱星人', 'v': '吱星人'},
  1269. {'n': '美食', 'v': '美食'}, {'n': '甜点', 'v': '甜点'}, {'n': '吃货', 'v': '吃货'}, {'n': '厨艺', 'v': '厨艺'}, {'n': '烘焙', 'v': '烘焙'}, {'n': '街头美食', 'v': '街头美食'},
  1270. {'n': 'A.I.Channel', 'v': 'A.I.Channel'}, {'n': '虚拟UP主', 'v': '虚拟UP主'}, {'n': '神楽めあ', 'v': '神楽めあ'}, {'n': '白上吹雪', 'v': '白上吹雪'}, {'n': '婺源', 'v': '婺源'}, {'n': 'hololive', 'v': 'hololive'}, {'n': 'EXO', 'v': 'EXO'}, {'n': '防弹少年团', 'v': '防弹少年团'}, {'n': '肖战', 'v': '肖战'}, {'n': '王一博', 'v': '王一博'}, {'n': '易烊千玺', 'v': '易烊千玺'}, {'n': '赵今麦', 'v': '赵今麦'},
  1271. {'n': '宅舞', 'v': '宅舞'}, {'n': '街舞', 'v': '街舞'}, {'n': '舞蹈教学', 'v': '舞蹈教学'}, {'n': '明星舞蹈', 'v': '明星舞蹈'}, {'n': '韩舞', 'v': '韩舞'}, {'n': '古典舞', 'v': '古典舞'},
  1272. {'n': '旅游', 'v': '旅游'}, {'n': '绘画', 'v': '绘画'}, {'n': '手工', 'v': '手工'}, {'n': 'vlog', 'v': 'vlog'}, {'n': 'DIY', 'v': 'DIY'}, {'n': '手绘', 'v': '手绘'},
  1273. {'n': '综艺', 'v': '综艺'}, {'n': '国家宝藏', 'v': '国家宝藏'}, {'n': '脱口秀', 'v': '脱口秀'}, {'n': '日本综艺', 'v': '日本综艺'}, {'n': '国内综艺', 'v': '国内综艺'}, {'n': '人类观察', 'v': '人类观察'},
  1274. {'n': '影评', 'v': '影评'}, {'n': '电影解说', 'v': '电影解说'}, {'n': '影视混剪', 'v': '影视混剪'}, {'n': '影视剪辑', 'v': '影视剪辑'}, {'n': '漫威', 'v': '漫威'}, {'n': '超级英雄', 'v': '超级英雄'}, {'n': '影视混剪', 'v': '影视混剪'}, {'n': '影视剪辑', 'v': '影视剪辑'},
  1275. {'n': '诸葛亮', 'v': '诸葛亮'}, {'n': '韩剧', 'v': '韩剧'}, {'n': '王司徒', 'v': '王司徒'}, {'n': '泰剧', 'v': '泰剧'},
  1276. {'n': '郭德纲', 'v': '郭德纲'}, {'n': '相声', 'v': '相声'}, {'n': '张云雷', 'v': '张云雷'}, {'n': '秦霄贤', 'v': '秦霄贤'}, {'n': '孟鹤堂', 'v': '孟鹤堂'}, {'n': '岳云鹏', 'v': '岳云鹏'}, {'n': '假面骑士', 'v': '假面骑士'}, {'n': '特摄', 'v': '特摄'}, {'n': '奥特曼', 'v': '奥特曼'}, {'n': '迪迦奥特曼', 'v': '迪迦奥特曼'}, {'n': '超级战队', 'v': '超级战队'}, {'n': '铠甲勇士', 'v': '铠甲勇士'},
  1277. {'n': '健身', 'v': '健身'}, {'n': '篮球', 'v': '篮球'}, {'n': '体育', 'v': '体育'}, {'n': '帕梅拉', 'v': '帕梅拉'}, {'n': '极限运动', 'v': '极限运动'}, {'n': '足球', 'v': '足球'}, {'n': '星海', 'v': '星海'},
  1278. {'n': '张召忠', 'v': '张召忠'}, {'n': '航母', 'v': '航母'}, {'n': '航天', 'v': '航天'}, {'n': '导弹', 'v': '导弹'}, {'n': '战斗机', 'v': '战斗机'}]
  1279. },
  1280. {
  1281. "key": "order",
  1282. "name": "排序",
  1283. "value": [
  1284. {
  1285. "n": "综合排序",
  1286. "v": "totalrank"
  1287. },
  1288. {
  1289. "n": "最新发布",
  1290. "v": "pubdate"
  1291. },
  1292. {
  1293. "n": "最多点击",
  1294. "v": "click"
  1295. },
  1296. {
  1297. "n": "最多收藏",
  1298. "v": "stow"
  1299. },
  1300. {
  1301. "n": "最多弹幕",
  1302. "v": "dm"
  1303. },
  1304. ]
  1305. },
  1306. {
  1307. "key": "duration",
  1308. "name": "时长",
  1309. "value": [{
  1310. "n": "全部",
  1311. "v": "0"
  1312. },
  1313. {
  1314. "n": "60分钟以上",
  1315. "v": "4"
  1316. },
  1317. {
  1318. "n": "30~60分钟",
  1319. "v": "3"
  1320. },
  1321. {
  1322. "n": "5~30分钟",
  1323. "v": "2"
  1324. },
  1325. {
  1326. "n": "5分钟以下",
  1327. "v": "1"
  1328. }
  1329. ]
  1330. }
  1331. ],
  1332. }
  1333. }
  1334. header = {
  1335. "Referer": "https://www.bilibili.com",
  1336. "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
  1337. }
  1338. def localProxy(self, param):
  1339. return [200, "video/MP2T", action, ""]
  1340. if __name__ == '__main__':
  1341. a=Spider()
  1342. print(a.config['filter'].get('收藏夹'))
  1343. #print(a.get_live(pg=1,parent_area_id='0'))
  1344. a.box_video_type='直播'
  1345. print(a.detailContent( ['7553185']))
  1346. print(a.playerContent('flag', '7553185_12368303#', 'vipFlags'))
  1347. #print(a.get_fav(pg='1',order='mtime',extend={}))