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