py_中医药.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. classes = []
  38. for k in cateManual:
  39. classes.append({
  40. 'type_name':k,
  41. 'type_id':cateManual[k]
  42. })
  43. result['class'] = classes
  44. if(filter):
  45. result['filters'] = self.config['filter']
  46. return result
  47. def homeVideoContent(self):
  48. result = {
  49. 'list':[]
  50. }
  51. return result
  52. cookies = ''
  53. def getCookie(self):
  54. rsp = self.fetch("https://www.bilibili.com/")
  55. self.cookies = rsp.cookies
  56. return rsp.cookies
  57. def categoryContent(self,tid,pg,filter,extend):
  58. result = {}
  59. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&duration=4&page={1}'.format(tid,pg)
  60. if len(self.cookies) <= 0:
  61. self.getCookie()
  62. rsp = self.fetch(url,cookies=self.cookies)
  63. content = rsp.text
  64. jo = json.loads(content)
  65. if jo['code'] != 0:
  66. rspRetry = self.fetch(url,cookies=self.getCookie())
  67. content = rspRetry.text
  68. jo = json.loads(content)
  69. videos = []
  70. vodList = jo['data']['result']
  71. for vod in vodList:
  72. aid = str(vod['aid']).strip()
  73. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  74. img = 'https:' + vod['pic'].strip()
  75. remark = str(vod['duration']).strip()
  76. videos.append({
  77. "vod_id":aid,
  78. "vod_name":title,
  79. "vod_pic":img,
  80. "vod_remarks":remark
  81. })
  82. result['list'] = videos
  83. result['page'] = pg
  84. result['pagecount'] = 9999
  85. result['limit'] = 90
  86. result['total'] = 999999
  87. return result
  88. def cleanSpace(self,str):
  89. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  90. def detailContent(self,array):
  91. aid = array[0]
  92. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  93. rsp = self.fetch(url,headers=self.header)
  94. jRoot = json.loads(rsp.text)
  95. jo = jRoot['data']
  96. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  97. pic = jo['pic']
  98. desc = jo['desc']
  99. typeName = jo['tname']
  100. vod = {
  101. "vod_id":aid,
  102. "vod_name":title,
  103. "vod_pic":pic,
  104. "type_name":typeName,
  105. "vod_year":"",
  106. "vod_area":"",
  107. "vod_remarks":"",
  108. "vod_actor":"",
  109. "vod_director":"",
  110. "vod_content":desc
  111. }
  112. ja = jo['pages']
  113. playUrl = ''
  114. for tmpJo in ja:
  115. cid = tmpJo['cid']
  116. part = tmpJo['part']
  117. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  118. vod['vod_play_from'] = 'B站'
  119. vod['vod_play_url'] = playUrl
  120. result = {
  121. 'list':[
  122. vod
  123. ]
  124. }
  125. return result
  126. def searchContent(self,key,quick):
  127. result = {
  128. 'list':[]
  129. }
  130. return result
  131. def playerContent(self,flag,id,vipFlags):
  132. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  133. result = {}
  134. ids = id.split("_")
  135. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  136. rsp = self.fetch(url)
  137. jRoot = json.loads(rsp.text)
  138. jo = jRoot['data']
  139. ja = jo['durl']
  140. maxSize = -1
  141. position = -1
  142. for i in range(len(ja)):
  143. tmpJo = ja[i]
  144. if maxSize < int(tmpJo['size']):
  145. maxSize = int(tmpJo['size'])
  146. position = i
  147. url = ''
  148. if len(ja) > 0:
  149. if position == -1:
  150. position = 0
  151. url = ja[position]['url']
  152. result["parse"] = 0
  153. result["playUrl"] = ''
  154. result["url"] = url
  155. result["header"] = {
  156. "Referer":"https://www.bilibili.com",
  157. "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"
  158. }
  159. result["contentType"] = 'video/x-flv'
  160. return result
  161. config = {
  162. "player": {},
  163. "filter": {}
  164. }
  165. header = {}
  166. def localProxy(self,param):
  167. return [200, "video/MP2T", action, ""]