球队球星.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 time
  8. import base64
  9. class Spider(Spider): # 元类 默认的元类 type
  10. def getName(self):
  11. return "球队明星"
  12. def init(self,extend=""):
  13. print("============{0}============".format(extend))
  14. pass
  15. def isVideoFormat(self,url):
  16. pass
  17. def manualVideoCheck(self):
  18. pass
  19. def homeContent(self,filter):
  20. result = {}
  21. cateManual = {
  22. "梅西":"梅西",
  23. "C罗":"C罗",
  24. "天下足球":"天下足球",
  25. "罗纳尔多":"罗纳尔多",
  26. "亨利":"亨利",
  27. "小罗":"小罗",
  28. "齐达内":"齐达内",
  29. "贝克汉姆":"贝克汉姆",
  30. "内马尔":"内马尔",
  31. "德布劳内":"德布劳内",
  32. "欧冠":"欧冠",
  33. "世界杯":"世界杯",
  34. "西甲":"西甲",
  35. "英超":"英超",
  36. "意甲":"意甲",
  37. "德甲":"德甲",
  38. "国米":"国米",
  39. "皇马":"皇马",
  40. "巴萨":"巴萨",
  41. "巴黎圣日耳曼":"巴黎圣日耳曼",
  42. "曼联":"曼联",
  43. "曼城":"曼城",
  44. "NBA":"NBA",
  45. "詹姆斯":"詹姆斯",
  46. "库里":"库里",
  47. "杜兰特":"杜兰特",
  48. "UFC":"UFC",
  49. "斯诺克":"斯诺克",
  50. "网球":"网球",
  51. "F1":"F1",
  52. "高尔夫":"高尔夫"
  53. }
  54. classes = []
  55. for k in cateManual:
  56. classes.append({
  57. 'type_name':k,
  58. 'type_id':cateManual[k]
  59. })
  60. result['class'] = classes
  61. if(filter):
  62. result['filters'] = self.config['filter']
  63. return result
  64. def homeVideoContent(self):
  65. result = {
  66. 'list':[]
  67. }
  68. return result
  69. cookies = ''
  70. def getCookie(self):
  71. import requests
  72. import http.cookies
  73. # 这里填cookie
  74. 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"
  75. simple_cookie = http.cookies.SimpleCookie(raw_cookie_line)
  76. cookie_jar = requests.cookies.RequestsCookieJar()
  77. cookie_jar.update(simple_cookie)
  78. return cookie_jar
  79. def get_dynamic(self,pg):
  80. result = {}
  81. url= 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=all&page={0}'.format(pg)
  82. rsp = self.fetch(url,cookies=self.getCookie())
  83. content = rsp.text
  84. jo = json.loads(content)
  85. if jo['code'] == 0:
  86. videos = []
  87. vodList = jo['data']['items']
  88. for vod in vodList:
  89. if vod['type'] == 'DYNAMIC_TYPE_AV':
  90. ivod = vod['modules']['module_dynamic']['major']['archive']
  91. aid = str(ivod['aid']).strip()
  92. title = ivod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  93. img = ivod['cover'].strip()
  94. remark = str(ivod['duration_text']).strip()
  95. videos.append({
  96. "vod_id":aid,
  97. "vod_name":title,
  98. "vod_pic":img,
  99. "vod_remarks":remark
  100. })
  101. result['list'] = videos
  102. result['page'] = pg
  103. result['pagecount'] = 9999
  104. result['limit'] = 90
  105. result['total'] = 999999
  106. return result
  107. def get_hot(self,pg):
  108. result = {}
  109. url= 'https://api.bilibili.com/x/web-interface/popular?ps=20&pn={0}'.format(pg)
  110. rsp = self.fetch(url,cookies=self.getCookie())
  111. content = rsp.text
  112. jo = json.loads(content)
  113. if jo['code'] == 0:
  114. videos = []
  115. vodList = jo['data']['list']
  116. for vod in vodList:
  117. aid = str(vod['aid']).strip()
  118. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  119. img = vod['pic'].strip()
  120. remark = str(vod['duration']).strip()
  121. videos.append({
  122. "vod_id":aid,
  123. "vod_name":title,
  124. "vod_pic":img,
  125. "vod_remarks":remark
  126. })
  127. result['list'] = videos
  128. result['page'] = pg
  129. result['pagecount'] = 9999
  130. result['limit'] = 90
  131. result['total'] = 999999
  132. return result
  133. def get_rank(self):
  134. result = {}
  135. url= 'https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all'
  136. rsp = self.fetch(url,cookies=self.getCookie())
  137. content = rsp.text
  138. jo = json.loads(content)
  139. if jo['code'] == 0:
  140. videos = []
  141. vodList = jo['data']['list']
  142. for vod in vodList:
  143. aid = str(vod['aid']).strip()
  144. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  145. img = vod['pic'].strip()
  146. remark = str(vod['duration']).strip()
  147. videos.append({
  148. "vod_id":aid,
  149. "vod_name":title,
  150. "vod_pic":img,
  151. "vod_remarks":remark
  152. })
  153. result['list'] = videos
  154. result['page'] = 1
  155. result['pagecount'] = 1
  156. result['limit'] = 90
  157. result['total'] = 999999
  158. return result
  159. def categoryContent(self,tid,pg,filter,extend):
  160. result = {}
  161. if tid == "热门":
  162. return self.get_hot(pg=pg)
  163. if tid == "排行榜" :
  164. return self.get_rank()
  165. if tid == '动态':
  166. return self.get_dynamic(pg=pg)
  167. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}'.format(tid,pg)
  168. if len(self.cookies) <= 0:
  169. self.getCookie()
  170. rsp = self.fetch(url,cookies=self.getCookie())
  171. content = rsp.text
  172. jo = json.loads(content)
  173. if jo['code'] != 0:
  174. rspRetry = self.fetch(url,cookies=self.getCookie())
  175. content = rspRetry.text
  176. jo = json.loads(content)
  177. videos = []
  178. vodList = jo['data']['result']
  179. for vod in vodList:
  180. aid = str(vod['aid']).strip()
  181. title = tid + ":" + vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  182. img = 'https:' + vod['pic'].strip()
  183. remark = str(vod['duration']).strip()
  184. videos.append({
  185. "vod_id":aid,
  186. "vod_name":title,
  187. "vod_pic":img,
  188. "vod_remarks":remark
  189. })
  190. result['list'] = videos
  191. result['page'] = pg
  192. result['pagecount'] = 9999
  193. result['limit'] = 90
  194. result['total'] = 999999
  195. return result
  196. def cleanSpace(self,str):
  197. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  198. def detailContent(self,array):
  199. aid = array[0]
  200. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  201. rsp = self.fetch(url,headers=self.header,cookies=self.getCookie())
  202. jRoot = json.loads(rsp.text)
  203. jo = jRoot['data']
  204. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  205. pic = jo['pic']
  206. desc = jo['desc']
  207. typeName = jo['tname']
  208. vod = {
  209. "vod_id":aid,
  210. "vod_name":title,
  211. "vod_pic":pic,
  212. "type_name":typeName,
  213. "vod_year":"",
  214. "vod_area":"bilidanmu",
  215. "vod_remarks":"",
  216. "vod_actor":jo['owner']['name'],
  217. "vod_director":jo['owner']['name'],
  218. "vod_content":desc
  219. }
  220. ja = jo['pages']
  221. playUrl = ''
  222. for tmpJo in ja:
  223. cid = tmpJo['cid']
  224. part = tmpJo['part']
  225. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  226. vod['vod_play_from'] = 'B站'
  227. vod['vod_play_url'] = playUrl
  228. result = {
  229. 'list':[
  230. vod
  231. ]
  232. }
  233. return result
  234. def searchContent(self,key,quick):
  235. search = self.categoryContent(tid=key,pg=1,filter=None,extend=None)
  236. result = {
  237. 'list':search['list']
  238. }
  239. return result
  240. def playerContent(self,flag,id,vipFlags):
  241. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  242. result = {}
  243. ids = id.split("_")
  244. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  245. rsp = self.fetch(url,cookies=self.getCookie())
  246. jRoot = json.loads(rsp.text)
  247. jo = jRoot['data']
  248. ja = jo['durl']
  249. maxSize = -1
  250. position = -1
  251. for i in range(len(ja)):
  252. tmpJo = ja[i]
  253. if maxSize < int(tmpJo['size']):
  254. maxSize = int(tmpJo['size'])
  255. position = i
  256. url = ''
  257. if len(ja) > 0:
  258. if position == -1:
  259. position = 0
  260. url = ja[position]['url']
  261. result["parse"] = 0
  262. result["playUrl"] = ''
  263. result["url"] = url
  264. result["header"] = {
  265. "Referer":"https://www.bilibili.com",
  266. "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"
  267. }
  268. result["contentType"] = 'video/x-flv'
  269. return result
  270. config = {
  271. "player": {},
  272. "filter": {}
  273. }
  274. header = {}
  275. def localProxy(self,param):
  276. return [200, "video/MP2T", action, ""]