美食合集.py 10 KB

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