体育健身.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. "广场舞":"广场舞",
  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. classes = []
  57. for k in cateManual:
  58. classes.append({
  59. 'type_name':k,
  60. 'type_id':cateManual[k]
  61. })
  62. result['class'] = classes
  63. if(filter):
  64. result['filters'] = self.config['filter']
  65. return result
  66. def homeVideoContent(self):
  67. result = {
  68. 'list':[]
  69. }
  70. return result
  71. cookies = ''
  72. def getCookie(self):
  73. import requests
  74. import http.cookies
  75. # 这里填cookie
  76. 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"
  77. simple_cookie = http.cookies.SimpleCookie(raw_cookie_line)
  78. cookie_jar = requests.cookies.RequestsCookieJar()
  79. cookie_jar.update(simple_cookie)
  80. return cookie_jar
  81. def get_dynamic(self,pg):
  82. result = {}
  83. url= 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=all&page={0}'.format(pg)
  84. rsp = self.fetch(url,cookies=self.getCookie())
  85. content = rsp.text
  86. jo = json.loads(content)
  87. if jo['code'] == 0:
  88. videos = []
  89. vodList = jo['data']['items']
  90. for vod in vodList:
  91. if vod['type'] == 'DYNAMIC_TYPE_AV':
  92. ivod = vod['modules']['module_dynamic']['major']['archive']
  93. aid = str(ivod['aid']).strip()
  94. title = ivod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  95. img = ivod['cover'].strip()
  96. remark = str(ivod['duration_text']).strip()
  97. videos.append({
  98. "vod_id":aid,
  99. "vod_name":title,
  100. "vod_pic":img,
  101. "vod_remarks":remark
  102. })
  103. result['list'] = videos
  104. result['page'] = pg
  105. result['pagecount'] = 9999
  106. result['limit'] = 90
  107. result['total'] = 999999
  108. return result
  109. def get_hot(self,pg):
  110. result = {}
  111. url= 'https://api.bilibili.com/x/web-interface/popular?ps=20&pn={0}'.format(pg)
  112. rsp = self.fetch(url,cookies=self.getCookie())
  113. content = rsp.text
  114. jo = json.loads(content)
  115. if jo['code'] == 0:
  116. videos = []
  117. vodList = jo['data']['list']
  118. for vod in vodList:
  119. aid = str(vod['aid']).strip()
  120. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  121. img = vod['pic'].strip()
  122. remark = str(vod['duration']).strip()
  123. videos.append({
  124. "vod_id":aid,
  125. "vod_name":title,
  126. "vod_pic":img,
  127. "vod_remarks":remark
  128. })
  129. result['list'] = videos
  130. result['page'] = pg
  131. result['pagecount'] = 9999
  132. result['limit'] = 90
  133. result['total'] = 999999
  134. return result
  135. def get_rank(self):
  136. result = {}
  137. url= 'https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all'
  138. rsp = self.fetch(url,cookies=self.getCookie())
  139. content = rsp.text
  140. jo = json.loads(content)
  141. if jo['code'] == 0:
  142. videos = []
  143. vodList = jo['data']['list']
  144. for vod in vodList:
  145. aid = str(vod['aid']).strip()
  146. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  147. img = vod['pic'].strip()
  148. remark = str(vod['duration']).strip()
  149. videos.append({
  150. "vod_id":aid,
  151. "vod_name":title,
  152. "vod_pic":img,
  153. "vod_remarks":remark
  154. })
  155. result['list'] = videos
  156. result['page'] = 1
  157. result['pagecount'] = 1
  158. result['limit'] = 90
  159. result['total'] = 999999
  160. return result
  161. def categoryContent(self,tid,pg,filter,extend):
  162. result = {}
  163. if tid == "热门":
  164. return self.get_hot(pg=pg)
  165. if tid == "排行榜" :
  166. return self.get_rank()
  167. if tid == '动态':
  168. return self.get_dynamic(pg=pg)
  169. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}'.format(tid,pg)
  170. if len(self.cookies) <= 0:
  171. self.getCookie()
  172. rsp = self.fetch(url,cookies=self.getCookie())
  173. content = rsp.text
  174. jo = json.loads(content)
  175. if jo['code'] != 0:
  176. rspRetry = self.fetch(url,cookies=self.getCookie())
  177. content = rspRetry.text
  178. jo = json.loads(content)
  179. videos = []
  180. vodList = jo['data']['result']
  181. for vod in vodList:
  182. aid = str(vod['aid']).strip()
  183. title = tid + ":" + vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  184. img = 'https:' + vod['pic'].strip()
  185. remark = str(vod['duration']).strip()
  186. videos.append({
  187. "vod_id":aid,
  188. "vod_name":title,
  189. "vod_pic":img,
  190. "vod_remarks":remark
  191. })
  192. result['list'] = videos
  193. result['page'] = pg
  194. result['pagecount'] = 9999
  195. result['limit'] = 90
  196. result['total'] = 999999
  197. return result
  198. def cleanSpace(self,str):
  199. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  200. def detailContent(self,array):
  201. aid = array[0]
  202. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  203. rsp = self.fetch(url,headers=self.header,cookies=self.getCookie())
  204. jRoot = json.loads(rsp.text)
  205. jo = jRoot['data']
  206. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  207. pic = jo['pic']
  208. desc = jo['desc']
  209. typeName = jo['tname']
  210. vod = {
  211. "vod_id":aid,
  212. "vod_name":title,
  213. "vod_pic":pic,
  214. "type_name":typeName,
  215. "vod_year":"",
  216. "vod_area":"bilidanmu",
  217. "vod_remarks":"",
  218. "vod_actor":jo['owner']['name'],
  219. "vod_director":jo['owner']['name'],
  220. "vod_content":desc
  221. }
  222. ja = jo['pages']
  223. playUrl = ''
  224. for tmpJo in ja:
  225. cid = tmpJo['cid']
  226. part = tmpJo['part']
  227. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  228. vod['vod_play_from'] = 'B站'
  229. vod['vod_play_url'] = playUrl
  230. result = {
  231. 'list':[
  232. vod
  233. ]
  234. }
  235. return result
  236. def searchContent(self,key,quick):
  237. search = self.categoryContent(tid=key,pg=1,filter=None,extend=None)
  238. result = {
  239. 'list':search['list']
  240. }
  241. return result
  242. def playerContent(self,flag,id,vipFlags):
  243. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  244. result = {}
  245. ids = id.split("_")
  246. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  247. rsp = self.fetch(url,cookies=self.getCookie())
  248. jRoot = json.loads(rsp.text)
  249. jo = jRoot['data']
  250. ja = jo['durl']
  251. maxSize = -1
  252. position = -1
  253. for i in range(len(ja)):
  254. tmpJo = ja[i]
  255. if maxSize < int(tmpJo['size']):
  256. maxSize = int(tmpJo['size'])
  257. position = i
  258. url = ''
  259. if len(ja) > 0:
  260. if position == -1:
  261. position = 0
  262. url = ja[position]['url']
  263. result["parse"] = 0
  264. result["playUrl"] = ''
  265. result["url"] = url
  266. result["header"] = {
  267. "Referer":"https://www.bilibili.com",
  268. "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"
  269. }
  270. result["contentType"] = 'video/x-flv'
  271. return result
  272. config = {
  273. "player": {},
  274. "filter": {}
  275. }
  276. header = {}
  277. def localProxy(self,param):
  278. return [200, "video/MP2T", action, ""]