nvtuan.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. "中国女团":"中国女团4K",
  23. "日本女团":"日本女团4K",
  24. "韩国女团":"韩国女团4K",
  25. "SNH48":"SNH48MV合集",
  26. "S.H.E":"S.H.EMV合集",
  27. "Twins":"TwinsMV合集",
  28. "火箭少女101":"火箭少女101MV合集",
  29. "BY2":"BY2MV合集",
  30. "S.I.N.G":"S.I.N.GMV合集",
  31. "3unshine":"3unshineMV合集",
  32. "蜜蜂少女队":"蜜蜂少女队MV合集",
  33. "七朵组合":"七朵组合MV合集",
  34. "GNZ48":"GNZ48MV合集",
  35. "TWICE":"TWICEMV合集",
  36. "4MINUTE":"4MINUTEMV合集",
  37. "EXID":"EXIDMV合集",
  38. "KARA":"KARAMV合集",
  39. "TARA":"TARAMV合集",
  40. "BLACKPINK":"BLACKPINKMV合集",
  41. "LOONA":"LOONAMV合集",
  42. "ITZY":"ITZYMV合集",
  43. "RedVelvet":"RedVelvetMV合集",
  44. "Everglow":"EverglowMV合集",
  45. "Mamamoo":"MamamooMV合集",
  46. "少女时代":"少女时代MV合集",
  47. "S.E.S":"S.E.SMV合集",
  48. "FIN.K.L":"FIN.K.LMV合集",
  49. "2NE1":"2NE1MV合集",
  50. "WonderGirls":"WonderGirlsMV合集",
  51. "IZ*ONE":"IZ*ONEMV合集",
  52. "Sistar":"SistarMV合集",
  53. "Apink":"ApinkMV合集",
  54. "AOA":"AOAMV合集",
  55. "GFRIEND":"GFRIENDMV合集",
  56. "f(x)":"f(x)MV合集",
  57. "(G)I-DLE":"(G)I-DLEMV合集",
  58. "Itzy":"ItzyMV合集",
  59. "Oh!GG":"Oh!GGMV合集",
  60. "GirlCrush":"GirlCrushMV合集",
  61. "AKB48":"AKB48MV合集",
  62. "SKE48":"SKE48MV合集",
  63. "NMB48":"NMB48MV合集",
  64. "JKT48":"JKT48MV合集",
  65. "HKT48":"HKT48MV合集",
  66. "AKB48TeamTP":"AKB48TeamTPMV合集",
  67. "Perfume":"PerfumeMV合集",
  68. "桃色幸运草Z":"桃色幸运草ZMV合集",
  69. "乃木坂46乃":"乃木坂46乃MV合集",
  70. "樱坂46":"樱坂46MV合集",
  71. "日向坂46":"日向坂46MV合集",
  72. "E-girls":"E-girlsMV合集",
  73. "NiziU":"NiziUMV合集",
  74. "BiSH":"BiSHMV合集",
  75. "早安少女组":"早安少女组MV合集"
  76. }
  77. classes = []
  78. for k in cateManual:
  79. classes.append({
  80. 'type_name':k,
  81. 'type_id':cateManual[k]
  82. })
  83. result['class'] = classes
  84. if(filter):
  85. result['filters'] = self.config['filter']
  86. return result
  87. def homeVideoContent(self):
  88. result = {
  89. 'list':[]
  90. }
  91. return result
  92. cookies = ''
  93. def getCookie(self):
  94. import requests
  95. import http.cookies
  96. # 这里填cookie
  97. raw_cookie_line = "SESSDATA=7624af93%2C1696008331%2C862c8%2A42; bili_jct=141a474ef3ce8cf2fedf384e68f6625d; DedeUserID=3493271303096985; DedeUserID__ckMd5=212a836c164605b7"
  98. simple_cookie = http.cookies.SimpleCookie(raw_cookie_line)
  99. cookie_jar = requests.cookies.RequestsCookieJar()
  100. cookie_jar.update(simple_cookie)
  101. return cookie_jar
  102. def get_dynamic(self,pg):
  103. result = {}
  104. url= 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=all&page={0}'.format(pg)
  105. rsp = self.fetch(url,cookies=self.getCookie())
  106. content = rsp.text
  107. jo = json.loads(content)
  108. if jo['code'] == 0:
  109. videos = []
  110. vodList = jo['data']['items']
  111. for vod in vodList:
  112. if vod['type'] == 'DYNAMIC_TYPE_AV':
  113. ivod = vod['modules']['module_dynamic']['major']['archive']
  114. aid = str(ivod['aid']).strip()
  115. title = ivod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  116. img = ivod['cover'].strip()
  117. remark = str(ivod['duration_text']).strip()
  118. videos.append({
  119. "vod_id":aid,
  120. "vod_name":title,
  121. "vod_pic":img,
  122. "vod_remarks":remark
  123. })
  124. result['list'] = videos
  125. result['page'] = pg
  126. result['pagecount'] = 9999
  127. result['limit'] = 90
  128. result['total'] = 999999
  129. return result
  130. def get_hot(self,pg):
  131. result = {}
  132. url= 'https://api.bilibili.com/x/web-interface/popular?ps=20&pn={0}'.format(pg)
  133. rsp = self.fetch(url,cookies=self.getCookie())
  134. content = rsp.text
  135. jo = json.loads(content)
  136. if jo['code'] == 0:
  137. videos = []
  138. vodList = jo['data']['list']
  139. for vod in vodList:
  140. aid = str(vod['aid']).strip()
  141. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  142. img = vod['pic'].strip()
  143. remark = str(vod['duration']).strip()
  144. videos.append({
  145. "vod_id":aid,
  146. "vod_name":title,
  147. "vod_pic":img,
  148. "vod_remarks":remark
  149. })
  150. result['list'] = videos
  151. result['page'] = pg
  152. result['pagecount'] = 9999
  153. result['limit'] = 90
  154. result['total'] = 999999
  155. return result
  156. def get_rank(self):
  157. result = {}
  158. url= 'https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all'
  159. rsp = self.fetch(url,cookies=self.getCookie())
  160. content = rsp.text
  161. jo = json.loads(content)
  162. if jo['code'] == 0:
  163. videos = []
  164. vodList = jo['data']['list']
  165. for vod in vodList:
  166. aid = str(vod['aid']).strip()
  167. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  168. img = vod['pic'].strip()
  169. remark = str(vod['duration']).strip()
  170. videos.append({
  171. "vod_id":aid,
  172. "vod_name":title,
  173. "vod_pic":img,
  174. "vod_remarks":remark
  175. })
  176. result['list'] = videos
  177. result['page'] = 1
  178. result['pagecount'] = 1
  179. result['limit'] = 90
  180. result['total'] = 999999
  181. return result
  182. def categoryContent(self,tid,pg,filter,extend):
  183. result = {}
  184. if tid == "热门":
  185. return self.get_hot(pg=pg)
  186. if tid == "排行榜" :
  187. return self.get_rank()
  188. if tid == '动态':
  189. return self.get_dynamic(pg=pg)
  190. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}'.format(tid,pg)
  191. if len(self.cookies) <= 0:
  192. self.getCookie()
  193. rsp = self.fetch(url,cookies=self.getCookie())
  194. content = rsp.text
  195. jo = json.loads(content)
  196. if jo['code'] != 0:
  197. rspRetry = self.fetch(url,cookies=self.getCookie())
  198. content = rspRetry.text
  199. jo = json.loads(content)
  200. videos = []
  201. vodList = jo['data']['result']
  202. for vod in vodList:
  203. aid = str(vod['aid']).strip()
  204. title = tid + ":" + vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  205. img = 'https:' + vod['pic'].strip()
  206. remark = str(vod['duration']).strip()
  207. videos.append({
  208. "vod_id":aid,
  209. "vod_name":title,
  210. "vod_pic":img,
  211. "vod_remarks":remark
  212. })
  213. result['list'] = videos
  214. result['page'] = pg
  215. result['pagecount'] = 9999
  216. result['limit'] = 90
  217. result['total'] = 999999
  218. return result
  219. def cleanSpace(self,str):
  220. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  221. def detailContent(self,array):
  222. aid = array[0]
  223. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  224. rsp = self.fetch(url,headers=self.header,cookies=self.getCookie())
  225. jRoot = json.loads(rsp.text)
  226. jo = jRoot['data']
  227. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  228. pic = jo['pic']
  229. desc = jo['desc']
  230. typeName = jo['tname']
  231. vod = {
  232. "vod_id":aid,
  233. "vod_name":title,
  234. "vod_pic":pic,
  235. "type_name":typeName,
  236. "vod_year":"",
  237. "vod_area":"bilidanmu",
  238. "vod_remarks":"",
  239. "vod_actor":jo['owner']['name'],
  240. "vod_director":jo['owner']['name'],
  241. "vod_content":desc
  242. }
  243. ja = jo['pages']
  244. playUrl = ''
  245. for tmpJo in ja:
  246. cid = tmpJo['cid']
  247. part = tmpJo['part']
  248. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  249. vod['vod_play_from'] = 'B站'
  250. vod['vod_play_url'] = playUrl
  251. result = {
  252. 'list':[
  253. vod
  254. ]
  255. }
  256. return result
  257. def searchContent(self,key,quick):
  258. search = self.categoryContent(tid=key,pg=1,filter=None,extend=None)
  259. result = {
  260. 'list':search['list']
  261. }
  262. return result
  263. def playerContent(self,flag,id,vipFlags):
  264. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  265. result = {}
  266. ids = id.split("_")
  267. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  268. rsp = self.fetch(url,cookies=self.getCookie())
  269. jRoot = json.loads(rsp.text)
  270. jo = jRoot['data']
  271. ja = jo['durl']
  272. maxSize = -1
  273. position = -1
  274. for i in range(len(ja)):
  275. tmpJo = ja[i]
  276. if maxSize < int(tmpJo['size']):
  277. maxSize = int(tmpJo['size'])
  278. position = i
  279. url = ''
  280. if len(ja) > 0:
  281. if position == -1:
  282. position = 0
  283. url = ja[position]['url']
  284. result["parse"] = 0
  285. result["playUrl"] = ''
  286. result["url"] = url
  287. result["header"] = {
  288. "Referer":"https://www.bilibili.com",
  289. "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"
  290. }
  291. result["contentType"] = 'video/x-flv'
  292. return result
  293. config = {
  294. "player": {},
  295. "filter": {}
  296. }
  297. header = {}
  298. def localProxy(self,param):
  299. return [200, "video/MP2T", action, ""]