高中教育.py 10 KB

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