美女热舞.py 10 KB

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