戏曲合集.py 11 KB

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