py_GLjc.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. import requests
  10. class Spider(Spider): # 元类 默认的元类 type
  11. def getName(self):
  12. return "教程"
  13. def init(self,extend=""):
  14. print("============{0}============".format(extend))
  15. pass
  16. def isVideoFormat(self,url):
  17. pass
  18. def manualVideoCheck(self):
  19. pass
  20. def homeContent(self,filter):
  21. result = {}
  22. cateManual = {
  23. "WPS文字": "WPS文字",
  24. "WPS表格": "WPS表格",
  25. "WPS演示": "WPS演示",
  26. "word": "word",
  27. "PPT": "PPT",
  28. "MT管理器": "MT管理器",
  29. "网盘挂载": "网盘挂载",
  30. "EXCEL": "EXCEL",
  31. "Git入门到精通": "Git入门到精通",
  32. "java": "java",
  33. "phyton": "phyton",
  34. "xml": "xml",
  35. "PR": "PR",
  36. "AE": "AE",
  37. "C4D": "C4D",
  38. "alist+WebDav": "alist+WebDav",
  39. "Photoshop": "Photoshop",
  40. "EXCEL": "EXCEL",
  41. "office": "office",
  42. "WPS": "WPS",
  43. "Studioone": "Studioone",
  44. "声卡调试": "声卡调试"
  45. }
  46. classes = []
  47. for k in cateManual:
  48. classes.append({
  49. 'type_name':k,
  50. 'type_id':cateManual[k]
  51. })
  52. result['class'] = classes
  53. if(filter):
  54. result['filters'] = self.config['filter']
  55. return result
  56. def homeVideoContent(self):
  57. result = {
  58. 'list':[]
  59. }
  60. return result
  61. cookies = ''
  62. def getCookie(self):
  63. cookies_str = self.fetch("https://agit.ai/138001380000/MHQTV/raw/branch/master/bbcookie.txt").text
  64. cookies_dic = dict([co.strip().split('=') for co in cookies_str.split(';')])
  65. rsp = requests.session()
  66. cookies_jar = requests.utils.cookiejar_from_dict(cookies_dic)
  67. rsp.cookies = cookies_jar
  68. content = self.fetch("http://api.bilibili.com/x/web-interface/nav", cookies=rsp.cookies)
  69. res = json.loads(content.text)
  70. if res["code"] == 0:
  71. self.cookies = rsp.cookies
  72. else:
  73. rsp = self.fetch("https://www.bilibili.com/")
  74. self.cookies = rsp.cookies
  75. return rsp.cookies
  76. def categoryContent(self,tid,pg,filter,extend):
  77. result = {}
  78. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&duration=4&page={1}'.format(tid,pg)
  79. if len(self.cookies) <= 0:
  80. self.getCookie()
  81. rsp = self.fetch(url,cookies=self.cookies)
  82. content = rsp.text
  83. jo = json.loads(content)
  84. if jo['code'] != 0:
  85. rspRetry = self.fetch(url,cookies=self.getCookie())
  86. content = rspRetry.text
  87. jo = json.loads(content)
  88. videos = []
  89. vodList = jo['data']['result']
  90. for vod in vodList:
  91. aid = str(vod['aid']).strip()
  92. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  93. img = 'https:' + vod['pic'].strip()
  94. remark = str(vod['duration']).strip()
  95. videos.append({
  96. "vod_id":aid,
  97. "vod_name":title,
  98. "vod_pic":img,
  99. "vod_remarks":remark
  100. })
  101. result['list'] = videos
  102. result['page'] = pg
  103. result['pagecount'] = 9999
  104. result['limit'] = 90
  105. result['total'] = 999999
  106. return result
  107. def cleanSpace(self,str):
  108. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  109. def detailContent(self,array):
  110. aid = array[0]
  111. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  112. rsp = self.fetch(url,headers=self.header)
  113. jRoot = json.loads(rsp.text)
  114. jo = jRoot['data']
  115. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  116. pic = jo['pic']
  117. desc = jo['desc']
  118. typeName = jo['tname']
  119. vod = {
  120. "vod_id":aid,
  121. "vod_name":title,
  122. "vod_pic":pic,
  123. "type_name":typeName,
  124. "vod_year":"",
  125. "vod_area":"",
  126. "vod_remarks":"",
  127. "vod_actor":"",
  128. "vod_director":"",
  129. "vod_content":desc
  130. }
  131. ja = jo['pages']
  132. playUrl = ''
  133. for tmpJo in ja:
  134. cid = tmpJo['cid']
  135. part = tmpJo['part']
  136. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  137. vod['vod_play_from'] = 'B站'
  138. vod['vod_play_url'] = playUrl
  139. result = {
  140. 'list':[
  141. vod
  142. ]
  143. }
  144. return result
  145. def searchContent(self,key,quick):
  146. result = {
  147. 'list':[]
  148. }
  149. return result
  150. def playerContent(self,flag,id,vipFlags):
  151. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  152. result = {}
  153. ids = id.split("_")
  154. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  155. rsp = self.fetch(url, cookies=self.cookies)
  156. jRoot = json.loads(rsp.text)
  157. jo = jRoot['data']
  158. ja = jo['durl']
  159. maxSize = -1
  160. position = -1
  161. for i in range(len(ja)):
  162. tmpJo = ja[i]
  163. if maxSize < int(tmpJo['size']):
  164. maxSize = int(tmpJo['size'])
  165. position = i
  166. url = ''
  167. if len(ja) > 0:
  168. if position == -1:
  169. position = 0
  170. url = ja[position]['url']
  171. result["parse"] = 0
  172. result["playUrl"] = ''
  173. result["url"] = url
  174. result["header"] = {
  175. "Referer":"https://www.bilibili.com",
  176. "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"
  177. }
  178. result["contentType"] = 'video/x-flv'
  179. return result
  180. config = {
  181. "player": {},
  182. "filter": {}
  183. }
  184. header = {}
  185. def localProxy(self,param):
  186. return [200, "video/MP2T", action, ""]