py_中国文化.py 4.4 KB

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