2
0

py_QDqx.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. import requests
  10. class Spider(Spider): # 元类 默认的元类 type
  11. def getName(self):
  12. return "足坛巨星"
  13. def init(self,extend=""):
  14. print("============{0}============".format(extend))
  15. pass
  16. def isVideoFormat(self,url):
  17. pass
  18. def manualVideoCheck(self):
  19. pass
  20. def homeContent(self,filter):
  21. result = {}
  22. cateManual = {
  23. "梅西": "梅西",
  24. "C罗": "C罗",
  25. "天下足球": "天下足球",
  26. "罗纳尔多": "罗纳尔多",
  27. "亨利": "亨利",
  28. "小罗": "小罗",
  29. "齐达内": "齐达内",
  30. "贝克汉姆": "贝克汉姆",
  31. "内马尔": "内马尔",
  32. "德布劳内": "德布劳内",
  33. "欧冠": "欧冠",
  34. "世界杯": "世界杯",
  35. "西甲": "西甲",
  36. "英超": "英超",
  37. "意甲": "意甲",
  38. "德甲": "德甲",
  39. "国米": "国米",
  40. "皇马": "皇马",
  41. "巴萨": "巴萨",
  42. "巴黎圣日耳曼": "巴黎圣日耳曼",
  43. "曼联": "曼联",
  44. "曼城": "曼城",
  45. "NBA": "NBA",
  46. "詹姆斯": "詹姆斯",
  47. "库里": "库里",
  48. "杜兰特": "杜兰特",
  49. "UFC": "UFC",
  50. "斯诺克": "斯诺克",
  51. "网球": "网球",
  52. "F1": "F1",
  53. "高尔夫": "高尔夫"
  54. }
  55. classes = []
  56. for k in cateManual:
  57. classes.append({
  58. 'type_name':k,
  59. 'type_id':cateManual[k]
  60. })
  61. result['class'] = classes
  62. if(filter):
  63. result['filters'] = self.config['filter']
  64. return result
  65. def homeVideoContent(self):
  66. result = {
  67. 'list':[]
  68. }
  69. return result
  70. cookies = ''
  71. def getCookie(self):
  72. cookies_str = self.fetch("https://agit.ai/138001380000/MHQTV/raw/branch/master/bbcookie.txt").text
  73. cookies_dic = dict([co.strip().split('=') for co in cookies_str.split(';')])
  74. rsp = requests.session()
  75. cookies_jar = requests.utils.cookiejar_from_dict(cookies_dic)
  76. rsp.cookies = cookies_jar
  77. content = self.fetch("http://api.bilibili.com/x/web-interface/nav", cookies=rsp.cookies)
  78. res = json.loads(content.text)
  79. if res["code"] == 0:
  80. self.cookies = rsp.cookies
  81. else:
  82. rsp = self.fetch("https://www.bilibili.com/")
  83. self.cookies = rsp.cookies
  84. return rsp.cookies
  85. def categoryContent(self,tid,pg,filter,extend):
  86. result = {}
  87. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&duration=4&page={1}'.format(tid,pg)
  88. if len(self.cookies) <= 0:
  89. self.getCookie()
  90. rsp = self.fetch(url,cookies=self.cookies)
  91. content = rsp.text
  92. jo = json.loads(content)
  93. if jo['code'] != 0:
  94. rspRetry = self.fetch(url,cookies=self.getCookie())
  95. content = rspRetry.text
  96. jo = json.loads(content)
  97. videos = []
  98. vodList = jo['data']['result']
  99. for vod in vodList:
  100. aid = str(vod['aid']).strip()
  101. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  102. img = 'https:' + vod['pic'].strip()
  103. remark = str(vod['duration']).strip()
  104. videos.append({
  105. "vod_id":aid,
  106. "vod_name":title,
  107. "vod_pic":img,
  108. "vod_remarks":remark
  109. })
  110. result['list'] = videos
  111. result['page'] = pg
  112. result['pagecount'] = 9999
  113. result['limit'] = 90
  114. result['total'] = 999999
  115. return result
  116. def cleanSpace(self,str):
  117. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  118. def detailContent(self,array):
  119. aid = array[0]
  120. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  121. rsp = self.fetch(url,headers=self.header)
  122. jRoot = json.loads(rsp.text)
  123. jo = jRoot['data']
  124. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  125. pic = jo['pic']
  126. desc = jo['desc']
  127. typeName = jo['tname']
  128. vod = {
  129. "vod_id":aid,
  130. "vod_name":title,
  131. "vod_pic":pic,
  132. "type_name":typeName,
  133. "vod_year":"",
  134. "vod_area":"",
  135. "vod_remarks":"",
  136. "vod_actor":"",
  137. "vod_director":"",
  138. "vod_content":desc
  139. }
  140. ja = jo['pages']
  141. playUrl = ''
  142. for tmpJo in ja:
  143. cid = tmpJo['cid']
  144. part = tmpJo['part']
  145. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  146. vod['vod_play_from'] = 'B站'
  147. vod['vod_play_url'] = playUrl
  148. result = {
  149. 'list':[
  150. vod
  151. ]
  152. }
  153. return result
  154. def searchContent(self,key,quick):
  155. result = {
  156. 'list':[]
  157. }
  158. return result
  159. def playerContent(self,flag,id,vipFlags):
  160. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  161. result = {}
  162. ids = id.split("_")
  163. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  164. rsp = self.fetch(url, cookies=self.cookies)
  165. jRoot = json.loads(rsp.text)
  166. jo = jRoot['data']
  167. ja = jo['durl']
  168. maxSize = -1
  169. position = -1
  170. for i in range(len(ja)):
  171. tmpJo = ja[i]
  172. if maxSize < int(tmpJo['size']):
  173. maxSize = int(tmpJo['size'])
  174. position = i
  175. url = ''
  176. if len(ja) > 0:
  177. if position == -1:
  178. position = 0
  179. url = ja[position]['url']
  180. result["parse"] = 0
  181. result["playUrl"] = ''
  182. result["url"] = url
  183. result["header"] = {
  184. "Referer":"https://www.bilibili.com",
  185. "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"
  186. }
  187. result["contentType"] = 'video/x-flv'
  188. return result
  189. config = {
  190. "player": {},
  191. "filter": {}
  192. }
  193. header = {}
  194. def localProxy(self,param):
  195. return [200, "video/MP2T", action, ""]