mtv.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 "明星MV"
  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. "粤语":"粤语MV4k合集",
  23. "2022年热榜":"2022年热门MV4k合集",
  24. "KTV热门":"KTV热门MV4k合集",
  25. "滚石经典":"滚石MV4k合集",
  26. "经典老歌":"经典老歌",
  27. "古风MV":"古风MV4k合集",
  28. "闽南语MV":"闽南语MV4k合集",
  29. "印度歌舞":"印度歌舞MV4k合集",
  30. "网红翻唱":"网红翻唱MV4k合集",
  31. "韩国女团":"韩国女团MV4k合集",
  32. "A阿黛尔":"阿黛尔MV4k合集",
  33. "Blackpink":"blackpinkMV4k合集",
  34. "Beyond":"beyondMV超清合集",
  35. "B坂井泉水":"坂井泉水MV超清合集",
  36. "B宝丽金":"宝丽金MV超清合集",
  37. "B布兰妮":"布兰妮MV超清合集",
  38. "C崔健":"催件MV超清合集",
  39. "C草蜢":"草蜢MV超清合集",
  40. "Coldplay":"coldplayMV超清合集",
  41. "C陈慧娴":"陈慧娴MV超清合集",
  42. "C陈百强":"陈百强MV超清合集",
  43. "C陈淑桦":"陈淑桦MV超清合集",
  44. "C陈楚生":"陈楚生MV超清合集",
  45. "C陈慧琳":"陈慧琳MV超清合集",
  46. "D邓丽君":"邓丽君MV超清合集",
  47. "D邓紫棋":"邓紫棋MV超清合集",
  48. "D刀郎":"刀郎MV超清合集",
  49. "D达明一派":"刘以达MV超清合集",
  50. "F费玉清":"费玉清MV超清合集",
  51. "F飞图":"飞图MV超清合集",
  52. "G谷村新司":"谷村新司MV超清合集",
  53. "G郭富城":"郭富城MV超清合集",
  54. "G关淑怡":"关淑怡MV超清合集",
  55. "H黄凯芹":"黄凯芹MV超清合集",
  56. "J降央卓玛":"降央卓玛MV超清合集",
  57. "J江慧":"江慧MV超清合集",
  58. "J吉永小百合":"吉永小百合MV超清合集",
  59. "J金庸":"金庸影视MV超清合集",
  60. "K柯以敏":"柯以敏MV超清合集",
  61. "K邝美云":"邝美云MV超清合集",
  62. "L刘德华":"刘德华MV超清合集",
  63. "Lady Gaga":"Lady GagaMV超清合集",
  64. "L龙飘飘":"龙飘飘MV超清合集",
  65. "L罗大佑":"罗大佑MV",
  66. "L林志炫":"林志炫MV",
  67. "L林忆莲":"林忆莲MV",
  68. "L李知恩":"李知恩MV",
  69. "L梁静茹":"梁静茹MV",
  70. "L冷漠":"冷漠MV",
  71. "L李克勤":"李克勤MV",
  72. "L林子祥":"林子祥MV",
  73. "L黎明":"黎明MV",
  74. "L刘若英":"刘若英MV",
  75. "M莫文蔚":"莫文蔚MV",
  76. "M孟庭苇":"孟庭苇MV",
  77. "M麦当娜":"麦当娜MV",
  78. "M迈克杰克逊":"迈克杰克逊MV",
  79. "N雅尼紫禁城":"雅尼紫禁城MV",
  80. "P潘越云":"潘越云MV",
  81. "P潘美辰":"潘美辰MV",
  82. "Q齐秦":"齐秦MV",
  83. "R任贤齐":"任贤齐MV",
  84. "S苏慧伦":"苏慧伦MV",
  85. "T童安格":"童安格MV",
  86. "TFBOYS":"TFBOYSMV",
  87. "T太极乐队":"太极乐队MV",
  88. "T唐朝摇滚":"唐朝摇滚MV",
  89. "T谭咏麟":"谭咏麟MV",
  90. "W王琪":"王琪MV",
  91. "W伍珂玥":"伍珂玥MV",
  92. "W王杰":"王杰MV",
  93. "W伍佰":"伍佰MV",
  94. "W温兆伦":"温兆伦MV",
  95. "W王菲":"王菲MV",
  96. "X徐小凤":"徐小凤MV",
  97. "X席琳迪翁":"席琳迪翁MV",
  98. "X许嵩":"黄许嵩MV",
  99. "X许美静":"许美静MV",
  100. "X许冠杰":"许冠杰MV",
  101. "X熊天平":"熊天平MV",
  102. "X小虎队":"小虎队MV",
  103. "X许巍":"许巍MV",
  104. "Y叶启田":"叶启田MV",
  105. "Y杨钰莹":"杨钰莹MV",
  106. "Y叶玉卿":"叶玉卿MV",
  107. "Y杨千嬅":"杨千嬅MV",
  108. "Y怡正宵":"怡正宵MV",
  109. "Z左麟右李":"左麟右李MV",
  110. "Z张楚":"张楚MV",
  111. "Z张真":"张真MV",
  112. "Z张震岳":"张震岳MV",
  113. "Z赵传":"赵传MV",
  114. "Z周华健":"周华健MV",
  115. "Z周启生":"周启生MV",
  116. "Z张信哲":"张信哲MV",
  117. "Z张也":"张也MV",
  118. "Z周慧敏":"周慧敏MV",
  119. "Z张碧晨":"张碧晨MV",
  120. "Z中岛美雪":"中岛美雪MV",
  121. "Z张学友":"张学友MV",
  122. "Z猪哥亮":"猪哥亮MV",
  123. "Z周杰伦":"周杰伦MV",
  124. "Z周深":"周深MV",
  125. "Z张蔷":"张蔷MV",
  126. "Z张帝":"张帝MV",
  127. "Z张国荣":"张国荣MV",
  128. "Z周传雄":"周传雄MV"
  129. }
  130. classes = []
  131. for k in cateManual:
  132. classes.append({
  133. 'type_name':k,
  134. 'type_id':cateManual[k]
  135. })
  136. result['class'] = classes
  137. if(filter):
  138. result['filters'] = self.config['filter']
  139. return result
  140. def homeVideoContent(self):
  141. result = {
  142. 'list':[]
  143. }
  144. return result
  145. cookies = ''
  146. def getCookie(self):
  147. import requests
  148. import http.cookies
  149. # 这里填cookie
  150. 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"
  151. simple_cookie = http.cookies.SimpleCookie(raw_cookie_line)
  152. cookie_jar = requests.cookies.RequestsCookieJar()
  153. cookie_jar.update(simple_cookie)
  154. return cookie_jar
  155. def get_dynamic(self,pg):
  156. result = {}
  157. url= 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=all&page={0}'.format(pg)
  158. rsp = self.fetch(url,cookies=self.getCookie())
  159. content = rsp.text
  160. jo = json.loads(content)
  161. if jo['code'] == 0:
  162. videos = []
  163. vodList = jo['data']['items']
  164. for vod in vodList:
  165. if vod['type'] == 'DYNAMIC_TYPE_AV':
  166. ivod = vod['modules']['module_dynamic']['major']['archive']
  167. aid = str(ivod['aid']).strip()
  168. title = ivod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  169. img = ivod['cover'].strip()
  170. remark = str(ivod['duration_text']).strip()
  171. videos.append({
  172. "vod_id":aid,
  173. "vod_name":title,
  174. "vod_pic":img,
  175. "vod_remarks":remark
  176. })
  177. result['list'] = videos
  178. result['page'] = pg
  179. result['pagecount'] = 9999
  180. result['limit'] = 90
  181. result['total'] = 999999
  182. return result
  183. def get_hot(self,pg):
  184. result = {}
  185. url= 'https://api.bilibili.com/x/web-interface/popular?ps=20&pn={0}'.format(pg)
  186. rsp = self.fetch(url,cookies=self.getCookie())
  187. content = rsp.text
  188. jo = json.loads(content)
  189. if jo['code'] == 0:
  190. videos = []
  191. vodList = jo['data']['list']
  192. for vod in vodList:
  193. aid = str(vod['aid']).strip()
  194. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  195. img = vod['pic'].strip()
  196. remark = str(vod['duration']).strip()
  197. videos.append({
  198. "vod_id":aid,
  199. "vod_name":title,
  200. "vod_pic":img,
  201. "vod_remarks":remark
  202. })
  203. result['list'] = videos
  204. result['page'] = pg
  205. result['pagecount'] = 9999
  206. result['limit'] = 90
  207. result['total'] = 999999
  208. return result
  209. def get_rank(self):
  210. result = {}
  211. url= 'https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all'
  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']['list']
  218. for vod in vodList:
  219. aid = str(vod['aid']).strip()
  220. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  221. img = vod['pic'].strip()
  222. remark = str(vod['duration']).strip()
  223. videos.append({
  224. "vod_id":aid,
  225. "vod_name":title,
  226. "vod_pic":img,
  227. "vod_remarks":remark
  228. })
  229. result['list'] = videos
  230. result['page'] = 1
  231. result['pagecount'] = 1
  232. result['limit'] = 90
  233. result['total'] = 999999
  234. return result
  235. def categoryContent(self,tid,pg,filter,extend):
  236. result = {}
  237. if tid == "热门":
  238. return self.get_hot(pg=pg)
  239. if tid == "排行榜" :
  240. return self.get_rank()
  241. if tid == '动态':
  242. return self.get_dynamic(pg=pg)
  243. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}'.format(tid,pg)
  244. if len(self.cookies) <= 0:
  245. self.getCookie()
  246. rsp = self.fetch(url,cookies=self.getCookie())
  247. content = rsp.text
  248. jo = json.loads(content)
  249. if jo['code'] != 0:
  250. rspRetry = self.fetch(url,cookies=self.getCookie())
  251. content = rspRetry.text
  252. jo = json.loads(content)
  253. videos = []
  254. vodList = jo['data']['result']
  255. for vod in vodList:
  256. aid = str(vod['aid']).strip()
  257. title = tid + ":" + vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  258. img = 'https:' + vod['pic'].strip()
  259. remark = str(vod['duration']).strip()
  260. videos.append({
  261. "vod_id":aid,
  262. "vod_name":title,
  263. "vod_pic":img,
  264. "vod_remarks":remark
  265. })
  266. result['list'] = videos
  267. result['page'] = pg
  268. result['pagecount'] = 9999
  269. result['limit'] = 90
  270. result['total'] = 999999
  271. return result
  272. def cleanSpace(self,str):
  273. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  274. def detailContent(self,array):
  275. aid = array[0]
  276. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  277. rsp = self.fetch(url,headers=self.header,cookies=self.getCookie())
  278. jRoot = json.loads(rsp.text)
  279. jo = jRoot['data']
  280. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  281. pic = jo['pic']
  282. desc = jo['desc']
  283. typeName = jo['tname']
  284. vod = {
  285. "vod_id":aid,
  286. "vod_name":title,
  287. "vod_pic":pic,
  288. "type_name":typeName,
  289. "vod_year":"",
  290. "vod_area":"bilidanmu",
  291. "vod_remarks":"",
  292. "vod_actor":jo['owner']['name'],
  293. "vod_director":jo['owner']['name'],
  294. "vod_content":desc
  295. }
  296. ja = jo['pages']
  297. playUrl = ''
  298. for tmpJo in ja:
  299. cid = tmpJo['cid']
  300. part = tmpJo['part']
  301. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  302. vod['vod_play_from'] = 'B站'
  303. vod['vod_play_url'] = playUrl
  304. result = {
  305. 'list':[
  306. vod
  307. ]
  308. }
  309. return result
  310. def searchContent(self,key,quick):
  311. search = self.categoryContent(tid=key,pg=1,filter=None,extend=None)
  312. result = {
  313. 'list':search['list']
  314. }
  315. return result
  316. def playerContent(self,flag,id,vipFlags):
  317. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  318. result = {}
  319. ids = id.split("_")
  320. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  321. rsp = self.fetch(url,cookies=self.getCookie())
  322. jRoot = json.loads(rsp.text)
  323. jo = jRoot['data']
  324. ja = jo['durl']
  325. maxSize = -1
  326. position = -1
  327. for i in range(len(ja)):
  328. tmpJo = ja[i]
  329. if maxSize < int(tmpJo['size']):
  330. maxSize = int(tmpJo['size'])
  331. position = i
  332. url = ''
  333. if len(ja) > 0:
  334. if position == -1:
  335. position = 0
  336. url = ja[position]['url']
  337. result["parse"] = 0
  338. result["playUrl"] = ''
  339. result["url"] = url
  340. result["header"] = {
  341. "Referer":"https://www.bilibili.com",
  342. "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"
  343. }
  344. result["contentType"] = 'video/x-flv'
  345. return result
  346. config = {
  347. "player": {},
  348. "filter": {}
  349. }
  350. header = {}
  351. def localProxy(self,param):
  352. return [200, "video/MP2T", action, ""]