歌手合集.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. "Beyond":"Beyond",
  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. "林俊杰":"林俊杰",
  71. "谭咏麟":"谭咏麟",
  72. "赵雷":"赵雷",
  73. "凤凰传奇":"凤凰传奇",
  74. "容祖儿":"容祖儿",
  75. "周传雄":"周传雄",
  76. "SHE":"SHE",
  77. "苏打绿":"苏打绿",
  78. "五月天":"五月天",
  79. "张国荣":"张国荣",
  80. "梅艳芳":"梅艳芳",
  81. "孙燕姿":"孙燕姿",
  82. "李健":"李健",
  83. "华晨宇":"华晨宇",
  84. "袁娅维":"袁娅维",
  85. "大张伟":"大张伟",
  86. "TFBOYS":"TFBOYS",
  87. "易烊千玺":"易烊千玺",
  88. "王俊凯":"王俊凯",
  89. "王源":"王源",
  90. "田馥甄":"田馥甄",
  91. "小虎队":"小虎队",
  92. "张杰":"张杰",
  93. "伍佰":"伍佰",
  94. "王菲":"王菲",
  95. "刀郎":"刀郎",
  96. "草蜢":"草蜢",
  97. "潘玮柏":"潘玮柏",
  98. "梁静茹":"梁静茹",
  99. "林宥嘉":"林宥嘉",
  100. "蔡徐坤":"蔡徐坤",
  101. "周慧敏":"周慧敏",
  102. "李圣杰":"李圣杰",
  103. "张惠妹":"张惠妹",
  104. "萧敬腾":"萧敬腾",
  105. "周笔畅":"周笔畅",
  106. "焦迈奇":"焦迈奇",
  107. "尤长靖":"尤长靖",
  108. "郑中基":"郑中基",
  109. "谭维维":"谭维维",
  110. "陈慧娴":"陈慧娴",
  111. "张艺兴":"张艺兴",
  112. "王嘉尔":"王嘉尔",
  113. "刘宪华":"刘宪华",
  114. "张敬轩":"张敬轩",
  115. "李克勤":"李克勤",
  116. "阿杜":"阿杜",
  117. "郭静":"郭静",
  118. "崔健":"崔健",
  119. "庾澄庆":"庾澄庆",
  120. "汪峰":"汪峰",
  121. "那英":"那英",
  122. "杨坤":"杨坤",
  123. "叶倩文":"叶倩文",
  124. "王心凌":"王心凌",
  125. "张震岳":"张震岳",
  126. "韩红":"韩红",
  127. "齐秦":"齐秦",
  128. "张雨生":"张雨生",
  129. "黄品源":"黄品源",
  130. "林忆莲":"林忆莲",
  131. "丁当":"丁当",
  132. "郑智化":"郑智化",
  133. "李玟":"李玟",
  134. "谢霆锋":"谢霆锋",
  135. "黄小琥":"黄小琥",
  136. "徐小凤":"徐小凤",
  137. "任嘉伦":"任嘉伦",
  138. "卓依婷":"卓依婷",
  139. "逃跑计划":"逃跑计划",
  140. "青鸟飞鱼":"青鸟飞鱼",
  141. "飞儿乐队":"飞儿乐队",
  142. "花儿乐队":"花儿乐队",
  143. "南拳妈妈":"南拳妈妈",
  144. "水木年华":"水木年华",
  145. "动力火车":"动力火车",
  146. "筷子兄弟":"筷子兄弟",
  147. "鹿先森乐队":"鹿先森乐队",
  148. "信乐队":"信乐队",
  149. "旅行团乐队":"旅行团乐队",
  150. "By2":"By2",
  151. "郁可唯":"郁可唯",
  152. "宋亚森":"宋亚森",
  153. "费玉清":"费玉清",
  154. "费翔":"费翔",
  155. "金志文":"金志文",
  156. "方大同":"方大同",
  157. "吴克群":"吴克群",
  158. "罗大佑":"罗大佑",
  159. "光良":"光良",
  160. "凤飞飞":"凤飞飞",
  161. "田震":"田震",
  162. "谭晶":"谭晶",
  163. "王杰":"王杰",
  164. "羽泉":"羽泉",
  165. "金池":"金池",
  166. "屠洪刚":"屠洪刚",
  167. "戴荃":"戴荃",
  168. "郭采洁":"郭采洁",
  169. "罗志祥":"罗志祥",
  170. "王力宏":"王力宏",
  171. "林肯公园":"林肯公园",
  172. "迈克尔杰克逊":"迈克尔杰克逊",
  173. "泰勒·斯威夫特":"泰勒·斯威夫特",
  174. "阿黛尔":"阿黛尔",
  175. "BIGBANG":"BIGBANG",
  176. "贾斯丁比伯":"贾斯丁比伯",
  177. "Lady Gaga":"Lady Gaga",
  178. "中岛美雪":"中岛美雪",
  179. "后街男孩":"后街男孩",
  180. "仓木麻衣":"仓木麻衣",
  181. "布兰妮":"布兰妮",
  182. "夜愿乐队":"夜愿乐队"
  183. }
  184. classes = []
  185. for k in cateManual:
  186. classes.append({
  187. 'type_name':k,
  188. 'type_id':cateManual[k]
  189. })
  190. result['class'] = classes
  191. if(filter):
  192. result['filters'] = self.config['filter']
  193. return result
  194. def homeVideoContent(self):
  195. result = {
  196. 'list':[]
  197. }
  198. return result
  199. cookies = ''
  200. def getCookie(self):
  201. import requests
  202. import http.cookies
  203. # 这里填cookie
  204. 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"
  205. simple_cookie = http.cookies.SimpleCookie(raw_cookie_line)
  206. cookie_jar = requests.cookies.RequestsCookieJar()
  207. cookie_jar.update(simple_cookie)
  208. return cookie_jar
  209. def get_dynamic(self,pg):
  210. result = {}
  211. url= 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=all&page={0}'.format(pg)
  212. rsp = self.fetch(url,cookies=self.getCookie())
  213. content = rsp.text
  214. jo = json.loads(content)
  215. if jo['code'] == 0:
  216. videos = []
  217. vodList = jo['data']['items']
  218. for vod in vodList:
  219. if vod['type'] == 'DYNAMIC_TYPE_AV':
  220. ivod = vod['modules']['module_dynamic']['major']['archive']
  221. aid = str(ivod['aid']).strip()
  222. title = ivod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  223. img = ivod['cover'].strip()
  224. remark = str(ivod['duration_text']).strip()
  225. videos.append({
  226. "vod_id":aid,
  227. "vod_name":title,
  228. "vod_pic":img,
  229. "vod_remarks":remark
  230. })
  231. result['list'] = videos
  232. result['page'] = pg
  233. result['pagecount'] = 9999
  234. result['limit'] = 90
  235. result['total'] = 999999
  236. return result
  237. def get_hot(self,pg):
  238. result = {}
  239. url= 'https://api.bilibili.com/x/web-interface/popular?ps=20&pn={0}'.format(pg)
  240. rsp = self.fetch(url,cookies=self.getCookie())
  241. content = rsp.text
  242. jo = json.loads(content)
  243. if jo['code'] == 0:
  244. videos = []
  245. vodList = jo['data']['list']
  246. for vod in vodList:
  247. aid = str(vod['aid']).strip()
  248. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  249. img = vod['pic'].strip()
  250. remark = str(vod['duration']).strip()
  251. videos.append({
  252. "vod_id":aid,
  253. "vod_name":title,
  254. "vod_pic":img,
  255. "vod_remarks":remark
  256. })
  257. result['list'] = videos
  258. result['page'] = pg
  259. result['pagecount'] = 9999
  260. result['limit'] = 90
  261. result['total'] = 999999
  262. return result
  263. def get_rank(self):
  264. result = {}
  265. url= 'https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all'
  266. rsp = self.fetch(url,cookies=self.getCookie())
  267. content = rsp.text
  268. jo = json.loads(content)
  269. if jo['code'] == 0:
  270. videos = []
  271. vodList = jo['data']['list']
  272. for vod in vodList:
  273. aid = str(vod['aid']).strip()
  274. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  275. img = vod['pic'].strip()
  276. remark = str(vod['duration']).strip()
  277. videos.append({
  278. "vod_id":aid,
  279. "vod_name":title,
  280. "vod_pic":img,
  281. "vod_remarks":remark
  282. })
  283. result['list'] = videos
  284. result['page'] = 1
  285. result['pagecount'] = 1
  286. result['limit'] = 90
  287. result['total'] = 999999
  288. return result
  289. def categoryContent(self,tid,pg,filter,extend):
  290. result = {}
  291. if tid == "热门":
  292. return self.get_hot(pg=pg)
  293. if tid == "排行榜" :
  294. return self.get_rank()
  295. if tid == '动态':
  296. return self.get_dynamic(pg=pg)
  297. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}'.format(tid,pg)
  298. if len(self.cookies) <= 0:
  299. self.getCookie()
  300. rsp = self.fetch(url,cookies=self.getCookie())
  301. content = rsp.text
  302. jo = json.loads(content)
  303. if jo['code'] != 0:
  304. rspRetry = self.fetch(url,cookies=self.getCookie())
  305. content = rspRetry.text
  306. jo = json.loads(content)
  307. videos = []
  308. vodList = jo['data']['result']
  309. for vod in vodList:
  310. aid = str(vod['aid']).strip()
  311. title = tid + ":" + vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  312. img = 'https:' + vod['pic'].strip()
  313. remark = str(vod['duration']).strip()
  314. videos.append({
  315. "vod_id":aid,
  316. "vod_name":title,
  317. "vod_pic":img,
  318. "vod_remarks":remark
  319. })
  320. result['list'] = videos
  321. result['page'] = pg
  322. result['pagecount'] = 9999
  323. result['limit'] = 90
  324. result['total'] = 999999
  325. return result
  326. def cleanSpace(self,str):
  327. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  328. def detailContent(self,array):
  329. aid = array[0]
  330. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  331. rsp = self.fetch(url,headers=self.header,cookies=self.getCookie())
  332. jRoot = json.loads(rsp.text)
  333. jo = jRoot['data']
  334. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  335. pic = jo['pic']
  336. desc = jo['desc']
  337. typeName = jo['tname']
  338. vod = {
  339. "vod_id":aid,
  340. "vod_name":title,
  341. "vod_pic":pic,
  342. "type_name":typeName,
  343. "vod_year":"",
  344. "vod_area":"bilidanmu",
  345. "vod_remarks":"",
  346. "vod_actor":jo['owner']['name'],
  347. "vod_director":jo['owner']['name'],
  348. "vod_content":desc
  349. }
  350. ja = jo['pages']
  351. playUrl = ''
  352. for tmpJo in ja:
  353. cid = tmpJo['cid']
  354. part = tmpJo['part']
  355. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  356. vod['vod_play_from'] = 'B站'
  357. vod['vod_play_url'] = playUrl
  358. result = {
  359. 'list':[
  360. vod
  361. ]
  362. }
  363. return result
  364. def searchContent(self,key,quick):
  365. search = self.categoryContent(tid=key,pg=1,filter=None,extend=None)
  366. result = {
  367. 'list':search['list']
  368. }
  369. return result
  370. def playerContent(self,flag,id,vipFlags):
  371. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  372. result = {}
  373. ids = id.split("_")
  374. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  375. rsp = self.fetch(url,cookies=self.getCookie())
  376. jRoot = json.loads(rsp.text)
  377. jo = jRoot['data']
  378. ja = jo['durl']
  379. maxSize = -1
  380. position = -1
  381. for i in range(len(ja)):
  382. tmpJo = ja[i]
  383. if maxSize < int(tmpJo['size']):
  384. maxSize = int(tmpJo['size'])
  385. position = i
  386. url = ''
  387. if len(ja) > 0:
  388. if position == -1:
  389. position = 0
  390. url = ja[position]['url']
  391. result["parse"] = 0
  392. result["playUrl"] = ''
  393. result["url"] = url
  394. result["header"] = {
  395. "Referer":"https://www.bilibili.com",
  396. "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"
  397. }
  398. result["contentType"] = 'video/x-flv'
  399. return result
  400. config = {
  401. "player": {},
  402. "filter": {}
  403. }
  404. header = {}
  405. def localProxy(self,param):
  406. return [200, "video/MP2T", action, ""]