2
0

py_mstd.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. "美食": "美食",
  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. "汉堡": "汉堡",
  53. "小吃": "小吃",
  54. "素食": "素食",
  55. "韩国菜": "韩国菜",
  56. "泰国菜": "泰国菜",
  57. "穆斯林菜": "穆斯林菜",
  58. "土耳其菜系": "土耳其菜系",
  59. "法国菜": "法国菜",
  60. "意大利菜": "意大利菜",
  61. "希腊菜": "希腊菜",
  62. "德国菜": "德国菜",
  63. "西班牙菜": "西班牙菜",
  64. "阿拉伯菜": "阿拉伯菜",
  65. "伊朗菜": "伊朗菜",
  66. "中亚菜": "中亚菜",
  67. "糖尿病菜": "糖尿病菜",
  68. "早餐": "早餐"
  69. }
  70. classes = []
  71. for k in cateManual:
  72. classes.append({
  73. 'type_name':k,
  74. 'type_id':cateManual[k]
  75. })
  76. result['class'] = classes
  77. if(filter):
  78. result['filters'] = self.config['filter']
  79. return result
  80. def homeVideoContent(self):
  81. result = {
  82. 'list':[]
  83. }
  84. return result
  85. cookies = ''
  86. def getCookie(self):
  87. cookies_str = self.fetch("https://agit.ai/138001380000/MHQTV/raw/branch/master/bbcookie.txt").text
  88. cookies_dic = dict([co.strip().split('=') for co in cookies_str.split(';')])
  89. rsp = requests.session()
  90. cookies_jar = requests.utils.cookiejar_from_dict(cookies_dic)
  91. rsp.cookies = cookies_jar
  92. content = self.fetch("http://api.bilibili.com/x/web-interface/nav", cookies=rsp.cookies)
  93. res = json.loads(content.text)
  94. if res["code"] == 0:
  95. self.cookies = rsp.cookies
  96. else:
  97. rsp = self.fetch("https://www.bilibili.com/")
  98. self.cookies = rsp.cookies
  99. return rsp.cookies
  100. def categoryContent(self,tid,pg,filter,extend):
  101. result = {}
  102. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&duration=4&page={1}'.format(tid,pg)
  103. if len(self.cookies) <= 0:
  104. self.getCookie()
  105. rsp = self.fetch(url,cookies=self.cookies)
  106. content = rsp.text
  107. jo = json.loads(content)
  108. if jo['code'] != 0:
  109. rspRetry = self.fetch(url,cookies=self.getCookie())
  110. content = rspRetry.text
  111. jo = json.loads(content)
  112. videos = []
  113. vodList = jo['data']['result']
  114. for vod in vodList:
  115. aid = str(vod['aid']).strip()
  116. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  117. img = 'https:' + 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 cleanSpace(self,str):
  132. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  133. def detailContent(self,array):
  134. aid = array[0]
  135. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  136. rsp = self.fetch(url,headers=self.header)
  137. jRoot = json.loads(rsp.text)
  138. jo = jRoot['data']
  139. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  140. pic = jo['pic']
  141. desc = jo['desc']
  142. typeName = jo['tname']
  143. vod = {
  144. "vod_id":aid,
  145. "vod_name":title,
  146. "vod_pic":pic,
  147. "type_name":typeName,
  148. "vod_year":"",
  149. "vod_area":"",
  150. "vod_remarks":"",
  151. "vod_actor":"",
  152. "vod_director":"",
  153. "vod_content":desc
  154. }
  155. ja = jo['pages']
  156. playUrl = ''
  157. for tmpJo in ja:
  158. cid = tmpJo['cid']
  159. part = tmpJo['part']
  160. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  161. vod['vod_play_from'] = 'B站'
  162. vod['vod_play_url'] = playUrl
  163. result = {
  164. 'list':[
  165. vod
  166. ]
  167. }
  168. return result
  169. def searchContent(self,key,quick):
  170. result = {
  171. 'list':[]
  172. }
  173. return result
  174. def playerContent(self,flag,id,vipFlags):
  175. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  176. result = {}
  177. ids = id.split("_")
  178. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  179. rsp = self.fetch(url, cookies=self.cookies)
  180. jRoot = json.loads(rsp.text)
  181. jo = jRoot['data']
  182. ja = jo['durl']
  183. maxSize = -1
  184. position = -1
  185. for i in range(len(ja)):
  186. tmpJo = ja[i]
  187. if maxSize < int(tmpJo['size']):
  188. maxSize = int(tmpJo['size'])
  189. position = i
  190. url = ''
  191. if len(ja) > 0:
  192. if position == -1:
  193. position = 0
  194. url = ja[position]['url']
  195. result["parse"] = 0
  196. result["playUrl"] = ''
  197. result["url"] = url
  198. result["header"] = {
  199. "Referer":"https://www.bilibili.com",
  200. "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"
  201. }
  202. result["contentType"] = 'video/x-flv'
  203. return result
  204. config = {
  205. "player": {},
  206. "filter": {}
  207. }
  208. header = {}
  209. def localProxy(self,param):
  210. return [200, "video/MP2T", action, ""]