1
0

中国文化.txt 10.0 KB

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