meinv.py 10 KB

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