123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- #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 = {
- "梅西":"梅西",
- "C罗":"C罗",
- "天下足球":"天下足球",
- "罗纳尔多":"罗纳尔多",
- "亨利":"亨利",
- "小罗":"小罗",
- "齐达内":"齐达内",
- "贝克汉姆":"贝克汉姆",
- "内马尔":"内马尔",
- "德布劳内":"德布劳内",
- "欧冠":"欧冠",
- "世界杯":"世界杯",
- "西甲":"西甲",
- "英超":"英超",
- "意甲":"意甲",
- "德甲":"德甲",
- "国米":"国米",
- "皇马":"皇马",
- "巴萨":"巴萨",
- "巴黎圣日耳曼":"巴黎圣日耳曼",
- "曼联":"曼联",
- "曼城":"曼城",
- "NBA":"NBA",
- "詹姆斯":"詹姆斯",
- "库里":"库里",
- "杜兰特":"杜兰特",
- "UFC":"UFC",
- "斯诺克":"斯诺克",
- "网球":"网球",
- "F1":"F1",
- "高尔夫":"高尔夫"
- }
- 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):
- import requests
- import http.cookies
- # 这里填cookie
- raw_cookie_line = "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"
- simple_cookie = http.cookies.SimpleCookie(raw_cookie_line)
- cookie_jar = requests.cookies.RequestsCookieJar()
- cookie_jar.update(simple_cookie)
- return cookie_jar
- def get_dynamic(self,pg):
- result = {}
-
- url= 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=all&page={0}'.format(pg)
-
- rsp = self.fetch(url,cookies=self.getCookie())
- content = rsp.text
- jo = json.loads(content)
- if jo['code'] == 0:
- videos = []
- vodList = jo['data']['items']
- for vod in vodList:
- if vod['type'] == 'DYNAMIC_TYPE_AV':
- ivod = vod['modules']['module_dynamic']['major']['archive']
- aid = str(ivod['aid']).strip()
- title = ivod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
- img = ivod['cover'].strip()
- remark = str(ivod['duration_text']).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 get_hot(self,pg):
- result = {}
- url= 'https://api.bilibili.com/x/web-interface/popular?ps=20&pn={0}'.format(pg)
- rsp = self.fetch(url,cookies=self.getCookie())
- content = rsp.text
- jo = json.loads(content)
- if jo['code'] == 0:
- videos = []
- vodList = jo['data']['list']
- for vod in vodList:
- aid = str(vod['aid']).strip()
- title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
- img = 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 get_rank(self):
- result = {}
- url= 'https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all'
- rsp = self.fetch(url,cookies=self.getCookie())
- content = rsp.text
- jo = json.loads(content)
- if jo['code'] == 0:
- videos = []
- vodList = jo['data']['list']
- for vod in vodList:
- aid = str(vod['aid']).strip()
- title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
- img = 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'] = 1
- result['pagecount'] = 1
- result['limit'] = 90
- result['total'] = 999999
- return result
- def categoryContent(self,tid,pg,filter,extend):
- result = {}
- if tid == "热门":
- return self.get_hot(pg=pg)
- if tid == "排行榜" :
- return self.get_rank()
- if tid == '动态':
- return self.get_dynamic(pg=pg)
- url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}'.format(tid,pg)
- if len(self.cookies) <= 0:
- self.getCookie()
- rsp = self.fetch(url,cookies=self.getCookie())
- 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 = tid + ":" + 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,cookies=self.getCookie())
- 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":"bilidanmu",
- "vod_remarks":"",
- "vod_actor":jo['owner']['name'],
- "vod_director":jo['owner']['name'],
- "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):
- search = self.categoryContent(tid=key,pg=1,filter=None,extend=None)
- result = {
- 'list':search['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,cookies=self.getCookie())
- 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, ""]
|