py_bilibili.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. "POPPING":"POPPING",
  43. "极乐净土":"极乐净土",
  44. "桃源恋歌":"桃源恋歌",
  45. "新宝岛":"新宝岛",
  46. "拉丁舞":"拉丁舞",
  47. "蹦迪":"蹦迪",
  48. "民族舞":"民族舞",
  49. "抖肩舞":"抖肩舞",
  50. "齐舞":"齐舞",
  51. "机械舞":"机械舞",
  52. "广场舞":"广场舞",
  53. "BDF":"BDF",
  54. "练习室":"练习室",
  55. "美女舞蹈":"美女舞蹈",
  56. "牛仔裤":"牛仔裤",
  57. "黑丝":"黑丝",
  58. "超短裤":"超短裤",
  59. "超短裙":"超短裙",
  60. "舞蹈综合":"舞蹈综合",
  61. "舞蹈教程":"舞蹈教程",
  62. "华语现场":"华语现场",
  63. "欧美现场":"欧美现场",
  64. "日语现场":"日语现场",
  65. "韩语现场":"韩语现场",
  66. "国语现场":"国语现场",
  67. "粤语现场":"粤语现场",
  68. "live":"live",
  69. "音乐剧":"音乐剧",
  70. "演唱会":"演唱会",
  71. "音乐节":"音乐节",
  72. "MV":"MV",
  73. "华语MV":"华语MV",
  74. "欧美MV":"欧美MV",
  75. "日语MV":"日语MV",
  76. "韩语MV":"韩语MV",
  77. "国语MV":"国语MV",
  78. "粤语MV":"粤语MV",
  79. "闽南语MV":"闽南语MV",
  80. "东南亚MV":"东南亚MV",
  81. "英语MV":"英语MV",
  82. "俄语MV":"俄语MV",
  83. "印度MV":"印度MV",
  84. "自制MV":"自制MV",
  85. "韩国女星MV":"韩国女星MV",
  86. "李孝利MV":"李孝利MV",
  87. "李知恩MV":"李知恩MV",
  88. "林允儿MV":"林允儿MV",
  89. "金泫雅MV":"金泫雅MV",
  90. "金泰妍MV":"金泰妍MV",
  91. "李宣美MV":"李宣美MV",
  92. "崔雪莉MV":"崔雪莉MV",
  93. "安喜延MV":"安喜延MV",
  94. "金亚荣MV":"金亚荣MV",
  95. "李知恩MV":"李知恩MV",
  96. "李贞贤MV":"李贞贤MV",
  97. "洪真英MV":"洪真英MV",
  98. "日本女星MV":"日本女星MV",
  99. "YUIMV":"YUIMV",
  100. "幸田来未MV":"幸田来未MV",
  101. "安室奈美惠MV":"安室奈美惠MV",
  102. "滨崎步MV":"滨崎步MV",
  103. "古谷仁美MV":"古谷仁美MV",
  104. "宇多田光MV":"宇多田光MV",
  105. "伊藤由奈MV":"伊藤由奈MV",
  106. "玉置成实MV":"玉置成实MV",
  107. "仓木麻衣MV":"仓木麻衣MV",
  108. "AngelaAkiMV":"AngelaMV",
  109. "中岛美雪MV":"中岛美雪MV",
  110. "女星MV":"女星MV",
  111. "戴佩妮MV":"戴佩妮MV",
  112. "邓紫棋MV":"邓紫棋MV",
  113. "张韶涵MV":"张韶涵MV",
  114. "蔡健雅MV":"蔡健雅MV",
  115. "莫文蔚MV":"莫文蔚MV",
  116. "刘若英MV":"刘若英MV",
  117. "邓丽君MV":"邓丽君MV",
  118. "蔡依林MV":"蔡依林MV",
  119. "李宇春MV":"李宇春MV",
  120. "徐佳莹MV":"徐佳莹MV",
  121. "杨千嬅MV":"杨千嬅MV",
  122. "张靓颖MV":"张靓颖MV",
  123. "杨丞琳MV":"杨丞琳MV",
  124. "萧亚轩MV":"萧亚轩MV",
  125. "容祖儿MV":"容祖儿MV",
  126. "梅艳芳MV":"梅艳芳MV",
  127. "孙燕姿MV":"孙燕姿MV",
  128. "袁娅维MV":"袁娅维MV",
  129. "王菲MV":"王菲MV",
  130. "梁静茹MV":"梁静茹MV",
  131. "周慧敏MV":"周慧敏MV",
  132. "张惠妹MV":"张惠妹MV",
  133. "周笔畅MV":"周笔畅MV",
  134. "谭维维MV":"谭维维MV",
  135. "陈慧娴MV":"陈慧娴MV",
  136. "郭静MV":"郭静MV",
  137. "那英MV":"那英MV",
  138. "韩红MV":"韩红MV",
  139. "林忆莲MV":"林忆莲MV",
  140. "李玟MV":"李玟MV",
  141. "徐小凤MV":"徐小凤MV",
  142. "卓依婷MV":"卓依婷MV",
  143. "郁可唯MV":"郁可唯MV",
  144. "田震MV":"田震MV",
  145. "凤飞飞MV":"凤飞飞MV",
  146. "谭晶MV":"谭晶MV",
  147. "叶倩文MV":"叶倩文MV",
  148. "王心凌MV":"王心凌MV",
  149. "郭采洁MV":"郭采洁MV",
  150. "阿黛尔MV":"阿黛尔MV",
  151. "LadyGagaMV":"LadyGagaMV",
  152. "布兰妮MV":"布兰妮MV",
  153. "洛天依MV":"洛天依MV",
  154. "初音未来MV":"初音未来MV",
  155. "女团":"女团",
  156. "中国女团":"中国女团",
  157. "SNH48":"SNH48",
  158. "S.H.E":"S.H.E",
  159. "Twins":"Twins",
  160. "火箭少女101":"火箭少女101",
  161. "BY2":"BY2",
  162. "S.I.N.G":"S.I.N.G",
  163. "3unshine":"3unshine",
  164. "蜜蜂少女队":"蜜蜂少女队",
  165. "七朵组合":"七朵组合",
  166. "GNZ48":"GNZ48",
  167. "韩国女团":"韩国女团",
  168. "TWICE":"TWICE",
  169. "4MINUTE":"4MINUTE",
  170. "EXID":"EXID",
  171. "KARA":"KARA",
  172. "TARA":"TARA",
  173. "BLACKPINK":"BLACKPINK",
  174. "LOONA":"LOONA",
  175. "ITZY":"ITZY",
  176. "RedVelvet":"RedVelvet",
  177. "Everglow":"Everglow",
  178. "Mamamoo":"Mamamoo",
  179. "少女时代":"少女时代",
  180. "S.E.S":"S.E.S",
  181. "FIN.K.L":"FIN.K.L",
  182. "2NE1":"2NE1",
  183. "WonderGirls":"WonderGirls",
  184. "IZ*ONE":"IZ*ONE",
  185. "Sistar":"Sistar",
  186. "Apink":"Apink",
  187. "AOA":"AOA",
  188. "GFRIEND":"GFRIEND",
  189. "f(x)":"f(x)",
  190. "(G)I-DLE":"(G)I-DLE",
  191. "Itzy":"Itzy",
  192. "Oh!GG":"Oh!GG",
  193. "GirlCrush":"GirlCrush",
  194. "日本女团":"日本女团",
  195. "AKB48":"AKB48",
  196. "SKE48":"SKE48",
  197. "NMB48":"NMB48",
  198. "JKT48":"JKT48",
  199. "HKT48":"HKT48",
  200. "AKB48TeamTP":"AKB48TeamTP",
  201. "Perfume":"Perfume",
  202. "桃色幸运草Z":"桃色幸运草Z",
  203. "乃木坂46乃":"乃木坂46乃",
  204. "樱坂46":"樱坂46",
  205. "日向坂46":"日向坂46",
  206. "E-girls":"E-girls",
  207. "NiziU":"NiziU",
  208. "BiSH":"BiSH",
  209. "早安少女组":"早安少女组",
  210. "戏曲":"戏曲",
  211. "演唱会":"演唱会",
  212. "相声小品":"相声小品",
  213. "动物世界":"动物世界",
  214. "儿童少儿":"儿童少儿"
  215. }
  216. classes = []
  217. for k in cateManual:
  218. classes.append({
  219. 'type_name':k,
  220. 'type_id':cateManual[k]
  221. })
  222. result['class'] = classes
  223. if(filter):
  224. result['filters'] = self.config['filter']
  225. return result
  226. def homeVideoContent(self):
  227. result = {
  228. 'list':[]
  229. }
  230. return result
  231. cookies = ''
  232. def getCookie(self):
  233. rsp = self.fetch("https://www.bilibili.com/")
  234. self.cookies = rsp.cookies
  235. return rsp.cookies
  236. def categoryContent(self,tid,pg,filter,extend):
  237. result = {}
  238. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&duration=4&page={1}'.format(tid,pg)
  239. if len(self.cookies) <= 0:
  240. self.getCookie()
  241. rsp = self.fetch(url,cookies=self.cookies)
  242. content = rsp.text
  243. jo = json.loads(content)
  244. if jo['code'] != 0:
  245. rspRetry = self.fetch(url,cookies=self.getCookie())
  246. content = rspRetry.text
  247. jo = json.loads(content)
  248. videos = []
  249. vodList = jo['data']['result']
  250. for vod in vodList:
  251. aid = str(vod['aid']).strip()
  252. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  253. img = 'https:' + vod['pic'].strip()
  254. remark = str(vod['duration']).strip()
  255. videos.append({
  256. "vod_id":aid,
  257. "vod_name":title,
  258. "vod_pic":img,
  259. "vod_remarks":remark
  260. })
  261. result['list'] = videos
  262. result['page'] = pg
  263. result['pagecount'] = 9999
  264. result['limit'] = 90
  265. result['total'] = 999999
  266. return result
  267. def cleanSpace(self,str):
  268. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  269. def detailContent(self,array):
  270. aid = array[0]
  271. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  272. rsp = self.fetch(url,headers=self.header)
  273. jRoot = json.loads(rsp.text)
  274. jo = jRoot['data']
  275. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  276. pic = jo['pic']
  277. desc = jo['desc']
  278. typeName = jo['tname']
  279. vod = {
  280. "vod_id":aid,
  281. "vod_name":title,
  282. "vod_pic":pic,
  283. "type_name":typeName,
  284. "vod_year":"",
  285. "vod_area":"",
  286. "vod_remarks":"",
  287. "vod_actor":"",
  288. "vod_director":"",
  289. "vod_content":desc
  290. }
  291. ja = jo['pages']
  292. playUrl = ''
  293. for tmpJo in ja:
  294. cid = tmpJo['cid']
  295. part = tmpJo['part']
  296. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  297. vod['vod_play_from'] = 'B站'
  298. vod['vod_play_url'] = playUrl
  299. result = {
  300. 'list':[
  301. vod
  302. ]
  303. }
  304. return result
  305. def searchContent(self,key,quick):
  306. result = {
  307. 'list':[]
  308. }
  309. return result
  310. def playerContent(self,flag,id,vipFlags):
  311. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  312. result = {}
  313. ids = id.split("_")
  314. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  315. rsp = self.fetch(url)
  316. jRoot = json.loads(rsp.text)
  317. jo = jRoot['data']
  318. ja = jo['durl']
  319. maxSize = -1
  320. position = -1
  321. for i in range(len(ja)):
  322. tmpJo = ja[i]
  323. if maxSize < int(tmpJo['size']):
  324. maxSize = int(tmpJo['size'])
  325. position = i
  326. url = ''
  327. if len(ja) > 0:
  328. if position == -1:
  329. position = 0
  330. url = ja[position]['url']
  331. result["parse"] = 0
  332. result["playUrl"] = ''
  333. result["url"] = url
  334. result["header"] = {
  335. "Referer":"https://www.bilibili.com",
  336. "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"
  337. }
  338. result["contentType"] = 'video/x-flv'
  339. return result
  340. config = {
  341. "player": {},
  342. "filter": {}
  343. }
  344. header = {}
  345. def localProxy(self,param):
  346. return [200, "video/MP2T", action, ""]