2
0

py_ydgw.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. import requests
  10. class Spider(Spider): # 元类 默认的元类 type
  11. def getName(self):
  12. return "印度歌舞"
  13. def init(self,extend=""):
  14. print("============{0}============".format(extend))
  15. pass
  16. def isVideoFormat(self,url):
  17. pass
  18. def manualVideoCheck(self):
  19. pass
  20. def homeContent(self,filter):
  21. result = {}
  22. cateManual = {
  23. "印度歌舞": "印度歌舞",
  24. "印度电影歌舞": "印度电影歌舞",
  25. "DJ": "DJ",
  26. "钢管舞": "钢管舞",
  27. "脱衣舞": "脱衣舞",
  28. "肚皮舞": "肚皮舞",
  29. "街舞": "街舞",
  30. "MV合集": "MV合集",
  31. "夜店合集": "夜店合集",
  32. "抖音合集": "抖音合集",
  33. "音乐合集": "音乐合集"
  34. }
  35. classes = []
  36. for k in cateManual:
  37. classes.append({
  38. 'type_name':k,
  39. 'type_id':cateManual[k]
  40. })
  41. result['class'] = classes
  42. if(filter):
  43. result['filters'] = self.config['filter']
  44. return result
  45. def homeVideoContent(self):
  46. result = {
  47. 'list':[]
  48. }
  49. return result
  50. cookies = ''
  51. def getCookie(self):
  52. cookies_str = self.fetch("https://agit.ai/138001380000/MHQTV/raw/branch/master/bbcookie.txt").text
  53. cookies_dic = dict([co.strip().split('=') for co in cookies_str.split(';')])
  54. rsp = requests.session()
  55. cookies_jar = requests.utils.cookiejar_from_dict(cookies_dic)
  56. rsp.cookies = cookies_jar
  57. content = self.fetch("http://api.bilibili.com/x/web-interface/nav", cookies=rsp.cookies)
  58. res = json.loads(content.text)
  59. if res["code"] == 0:
  60. self.cookies = rsp.cookies
  61. else:
  62. rsp = self.fetch("https://www.bilibili.com/")
  63. self.cookies = rsp.cookies
  64. return rsp.cookies
  65. def categoryContent(self,tid,pg,filter,extend):
  66. result = {}
  67. url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&duration=4&page={1}'.format(tid,pg)
  68. if len(self.cookies) <= 0:
  69. self.getCookie()
  70. rsp = self.fetch(url,cookies=self.cookies)
  71. content = rsp.text
  72. jo = json.loads(content)
  73. if jo['code'] != 0:
  74. rspRetry = self.fetch(url,cookies=self.getCookie())
  75. content = rspRetry.text
  76. jo = json.loads(content)
  77. videos = []
  78. vodList = jo['data']['result']
  79. for vod in vodList:
  80. aid = str(vod['aid']).strip()
  81. title = vod['title'].strip().replace("<em class=\"keyword\">","").replace("</em>","")
  82. img = 'https:' + vod['pic'].strip()
  83. remark = str(vod['duration']).strip()
  84. videos.append({
  85. "vod_id":aid,
  86. "vod_name":title,
  87. "vod_pic":img,
  88. "vod_remarks":remark
  89. })
  90. result['list'] = videos
  91. result['page'] = pg
  92. result['pagecount'] = 9999
  93. result['limit'] = 90
  94. result['total'] = 999999
  95. return result
  96. def cleanSpace(self,str):
  97. return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','')
  98. def detailContent(self,array):
  99. aid = array[0]
  100. url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid)
  101. rsp = self.fetch(url,headers=self.header)
  102. jRoot = json.loads(rsp.text)
  103. jo = jRoot['data']
  104. title = jo['title'].replace("<em class=\"keyword\">","").replace("</em>","")
  105. pic = jo['pic']
  106. desc = jo['desc']
  107. typeName = jo['tname']
  108. vod = {
  109. "vod_id":aid,
  110. "vod_name":title,
  111. "vod_pic":pic,
  112. "type_name":typeName,
  113. "vod_year":"",
  114. "vod_area":"",
  115. "vod_remarks":"",
  116. "vod_actor":"",
  117. "vod_director":"",
  118. "vod_content":desc
  119. }
  120. ja = jo['pages']
  121. playUrl = ''
  122. for tmpJo in ja:
  123. cid = tmpJo['cid']
  124. part = tmpJo['part']
  125. playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid)
  126. vod['vod_play_from'] = 'B站'
  127. vod['vod_play_url'] = playUrl
  128. result = {
  129. 'list':[
  130. vod
  131. ]
  132. }
  133. return result
  134. def searchContent(self,key,quick):
  135. result = {
  136. 'list':[]
  137. }
  138. return result
  139. def playerContent(self,flag,id,vipFlags):
  140. # https://www.555dianying.cc/vodplay/static/js/playerconfig.js
  141. result = {}
  142. ids = id.split("_")
  143. url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1])
  144. rsp = self.fetch(url, cookies=self.cookies)
  145. jRoot = json.loads(rsp.text)
  146. jo = jRoot['data']
  147. ja = jo['durl']
  148. maxSize = -1
  149. position = -1
  150. for i in range(len(ja)):
  151. tmpJo = ja[i]
  152. if maxSize < int(tmpJo['size']):
  153. maxSize = int(tmpJo['size'])
  154. position = i
  155. url = ''
  156. if len(ja) > 0:
  157. if position == -1:
  158. position = 0
  159. url = ja[position]['url']
  160. result["parse"] = 0
  161. result["playUrl"] = ''
  162. result["url"] = url
  163. result["header"] = {
  164. "Referer":"https://www.bilibili.com",
  165. "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"
  166. }
  167. result["contentType"] = 'video/x-flv'
  168. return result
  169. config = {
  170. "player": {},
  171. "filter": {}
  172. }
  173. header = {}
  174. def localProxy(self,param):
  175. return [200, "video/MP2T", action, ""]