m1905.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #coding=utf-8
  2. #!/usr/bin/python
  3. import sys
  4. sys.path.append('..')
  5. from base.spider import Spider
  6. import re
  7. import math
  8. import json
  9. import time
  10. import hashlib
  11. import uuid
  12. class Spider(Spider): # 元类 默认的元类 type
  13. def getName(self):
  14. return "哔哩哔哩"
  15. def init(self,extend=""):
  16. pass
  17. def isVideoFormat(self,url):
  18. pass
  19. def manualVideoCheck(self):
  20. pass
  21. def homeContent(self,filter):
  22. result = {}
  23. cateManual = {
  24. "电影": "n_1/o3p",
  25. "微电影": "n_1_c_922/o3p",
  26. "系列电影": "n_2/o3p",
  27. "记录片": "c_927/o3p",
  28. "晚会": "n_1_c_586/o3p",
  29. "独家": "n_1_c_178/o3p",
  30. "综艺": "n_1_c_1024/o3p",
  31. "体育": "n_1_c_1053/o3p"
  32. }
  33. classes = []
  34. for k in cateManual:
  35. classes.append({
  36. 'type_name':k,
  37. 'type_id':cateManual[k]
  38. })
  39. result['class'] = classes
  40. return result
  41. def homeVideoContent(self):
  42. result = {}
  43. url = 'https://www.1905.com/vod/cctv6/lst/'
  44. headers = {
  45. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.43',
  46. 'Referer': 'https://www.1905.com/vod/list/n_1/o3p1.html',
  47. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'
  48. }
  49. rsp = self.fetch(url, headers=headers)
  50. html = self.html(rsp.text)
  51. aList = html.xpath("//div[@class='grid-2x']/a")
  52. videos = []
  53. for a in aList:
  54. aid = a.xpath("./@href")[0] #https://www.1905.com/vod/play/85646.shtml
  55. if '//vip.1905.com' in str(aid):
  56. continue #跳过VIP视频
  57. aid = self.regStr(reg=r'play/(.*?).sh', src=aid) # 85646
  58. img = a.xpath('./img/@src')[0]
  59. title = a.xpath('./img/@alt')[0]
  60. videos.append({
  61. "vod_id": aid,
  62. "vod_name": title,
  63. "vod_pic": img,
  64. "vod_remarks": ''
  65. })
  66. result['list'] = videos
  67. return result
  68. def categoryContent(self,tid,pg,filter,extend):
  69. result = {}
  70. url = 'https://www.1905.com/vod/list/{}{}.html'.format(tid, pg)
  71. headers = {
  72. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.43',
  73. 'Referer': 'https://www.1905.com/vod/list/n_1/o3p1.html',
  74. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'
  75. }
  76. rsp = self.fetch(url, headers=headers)
  77. html = self.html(rsp.text)
  78. aList = html.xpath("//section[contains(@class,'search-list')]/div/a" if tid != u'n_2/o3p' else "//div[@class='mod']/div[1]/a")
  79. videos = []
  80. limit = len(aList)
  81. for a in aList:
  82. aid = a.xpath("./@href")[0] # https://www.1905.com/vod/play/85646.shtml
  83. aid = self.regStr(reg=r'play/(.*?).sh', src=aid) # 85646
  84. img = a.xpath('./img/@src')[0]
  85. title = a.xpath('./@title')[0]
  86. videos.append({
  87. "vod_id": aid,
  88. "vod_name": title,
  89. "vod_pic": img,
  90. "vod_remarks": ''
  91. })
  92. result['list'] = videos
  93. result['page'] = pg
  94. result['pagecount'] = 100
  95. result['limit'] = limit
  96. result['total'] = 100 * limit
  97. return result
  98. def detailContent(self,array):
  99. aid = array[0]
  100. url = "https://www.1905.com/api/content/?callback=&m=Vod&a=getVodSidebar&id={0}&fomat=json".format(aid)
  101. rsp = self.fetch(url)
  102. root = json.loads(rsp.text)
  103. title = root['title']
  104. pic = root['thumb']
  105. remark = root['commendreason']
  106. content = root['description']
  107. actor = root['starring']
  108. direct = root['direct']
  109. vod = {
  110. "vod_id": aid,
  111. "vod_name": title,
  112. "vod_pic": pic,
  113. "type_name": "",
  114. "vod_year": "",
  115. "vod_area": "",
  116. "vod_remarks": remark,
  117. "vod_actor": actor,
  118. "vod_director":direct,
  119. "vod_content": content
  120. }
  121. vodItems = []
  122. vodItems.append(title + "$" + aid)
  123. #处理多集的电影
  124. series = root['info']['series_data']
  125. for ser in series:
  126. vodItems.append(ser['title'] + "$" + ser['contentid'])
  127. playList = []
  128. joinStr = '#'.join(vodItems)
  129. playList.append(joinStr)
  130. vod['vod_play_from'] = '默认最高画质'
  131. vod['vod_play_url'] = '$$$'.join(playList)
  132. result = {
  133. 'list': [
  134. vod
  135. ]
  136. }
  137. return result
  138. def searchContent(self,key,quick):
  139. result = {}
  140. url = 'https://www.1905.com/search/index-p-type-all-q-{}.html'.format(key)
  141. headers = {
  142. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.43',
  143. 'Referer': 'https://www.1905.com/vod/list/n_1/o3p1.html',
  144. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'
  145. }
  146. rsp = self.fetch(url, headers=headers)
  147. html = self.html(rsp.text)
  148. aList = html.xpath("//div[contains(@class,'movie_box')]/div/div")
  149. videos = []
  150. for a in aList:
  151. aid = a.xpath("./div/ul/li[contains(@class,'paly-tab-icon')]/a/@href")[0] #https://www.1905.com/vod/play/85646.shtml
  152. if len(aid) == 0:
  153. continue
  154. aid = self.regStr(reg=r'play/(.*?).sh', src=aid) # 85646
  155. img = a.xpath('./div/div/a/img/@src')[0]
  156. title = a.xpath('./div/a/img/@alt')[0]
  157. videos.append({
  158. "vod_id": aid,
  159. "vod_name": title,
  160. "vod_pic": img,
  161. "vod_remarks": ''
  162. })
  163. result['list'] = videos
  164. return result
  165. def playerContent(self,flag,id,vipFlags):
  166. result = {}
  167. nonce = int(round(time.time() * 1000))
  168. expiretime = nonce + 600
  169. uid = str(uuid.uuid4())
  170. playerid = uid.replace("-", "")[5:20]
  171. signature = 'cid={0}&expiretime={1}&nonce={2}&page=https%3A%2F%2Fwww.1905.com%2Fvod%2Fplay%2F{3}.shtml&playerid={4}&type=hls&uuid={5}.dde3d61a0411511d'.format(id,expiretime,nonce,id,playerid,uid)
  172. signature = hashlib.sha1(signature.encode()).hexdigest()
  173. url = 'https://profile.m1905.com/mvod/getVideoinfo.php?nonce={0}&expiretime={1}&cid={2}&uuid={3}&playerid={4}&page=https%3A%2F%2Fwww.1905.com%2Fvod%2Fplay%2F{5}.shtml&type=hls&signature={6}&callback='.format(nonce,expiretime,id,uid,playerid,id,signature)
  174. headers = {
  175. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.43',
  176. 'Referer': 'https://www.1905.com/vod/list/n_1/o3p1.html',
  177. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'
  178. }
  179. rsp = self.fetch(url,headers=headers)
  180. jo = json.loads(rsp.text.replace("(", "").replace(")", ""))
  181. data = jo['data']['sign']
  182. sign = ''
  183. qualityStr = ''
  184. if 'uhd' in data.keys():
  185. sign = data['uhd']['sign']
  186. qualityStr = 'uhd'
  187. elif 'hd' in data.keys():
  188. sign = data['hd']['sign']
  189. qualityStr = 'hd'
  190. elif 'sd' in data.keys():
  191. sign = data['sd']['sign']
  192. qualityStr = 'sd'
  193. host = jo['data']['quality'][qualityStr]['host']
  194. path = jo['data']['path'][qualityStr]['path']
  195. playUrl = host + sign + path
  196. result["parse"] = 0
  197. result["playUrl"] = ''
  198. result["url"] = playUrl
  199. result["header"] = ''
  200. return result
  201. config = {
  202. "player": {},
  203. "filter": {}
  204. }
  205. header = {}
  206. def localProxy(self,param):
  207. return [200, "video/MP2T", action, ""]