m1905.py_old 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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):
  13. def getName(self):
  14. return "1905电影网"
  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. # pgc = math.ceil(numvL/15)
  82. for a in aList:
  83. aid = a.xpath("./@href")[0] #https://www.1905.com/vod/play/85646.shtml
  84. aid = self.regStr(reg=r'play/(.*?).sh', src=aid) # 85646
  85. img = a.xpath('./img/@src')[0]
  86. title = a.xpath('./@title')[0]
  87. videos.append({
  88. "vod_id": aid,
  89. "vod_name": title,
  90. "vod_pic": img,
  91. "vod_remarks": ''
  92. })
  93. result['list'] = videos
  94. result['page'] = pg
  95. result['pagecount'] = 100
  96. result['limit'] = limit
  97. result['total'] = 100 * limit
  98. return result
  99. def detailContent(self,array):
  100. aid = array[0]
  101. url = "https://www.1905.com/api/content/?callback=&m=Vod&a=getVodSidebar&id={0}&fomat=json".format(aid)
  102. rsp = self.fetch(url)
  103. root = json.loads(rsp.text)
  104. title = root['title']
  105. pic = root['thumb']
  106. remark = root['commendreason']
  107. content = root['description']
  108. actor = root['starring']
  109. direct = root['direct']
  110. vod = {
  111. "vod_id": aid,
  112. "vod_name": title,
  113. "vod_pic": pic,
  114. "type_name": "",
  115. "vod_year": "",
  116. "vod_area": "",
  117. "vod_remarks": remark,
  118. "vod_actor": actor,
  119. "vod_director":direct,
  120. "vod_content": content
  121. }
  122. vodItems = []
  123. vodItems.append(title + "$" + aid)
  124. #处理多集的电影
  125. series = root['info']['series_data']
  126. for ser in series:
  127. vodItems.append(ser['title'] + "$" + ser['contentid'])
  128. playList = []
  129. joinStr = '#'.join(vodItems)
  130. playList.append(joinStr)
  131. vod['vod_play_from'] = '默认最高画质'
  132. vod['vod_play_url'] = '$$$'.join(playList)
  133. result = {
  134. 'list': [
  135. vod
  136. ]
  137. }
  138. return result
  139. def searchContent(self,key,quick):
  140. result = {}
  141. return result
  142. def playerContent(self,flag,id,vipFlags):
  143. result = {}
  144. nonce = int(round(time.time() * 1000))
  145. expiretime = nonce + 600
  146. uid = str(uuid.uuid4())
  147. playerid = uid.replace("-", "")[5:20]
  148. 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)
  149. signature = hashlib.sha1(signature.encode()).hexdigest()
  150. 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)
  151. headers = {
  152. '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',
  153. 'Referer': 'https://www.1905.com/vod/list/n_1/o3p1.html',
  154. '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'
  155. }
  156. rsp = self.fetch(url,headers=headers)
  157. jo = json.loads(rsp.text.replace("(", "").replace(")", ""))
  158. data = jo['data']['sign']
  159. sign = ''
  160. qualityStr = ''
  161. if 'uhd' in data.keys():
  162. sign = data['uhd']['sign']
  163. qualityStr = 'uhd'
  164. elif 'hd' in data.keys():
  165. sign = data['hd']['sign']
  166. qualityStr = 'hd'
  167. elif 'sd' in data.keys():
  168. sign = data['sd']['sign']
  169. qualityStr = 'sd'
  170. host = jo['data']['quality'][qualityStr]['host']
  171. path = jo['data']['path'][qualityStr]['path']
  172. playUrl = host + sign + path
  173. result["parse"] = 0
  174. result["playUrl"] = ''
  175. result["url"] = playUrl
  176. result["header"] = ''
  177. return result
  178. def localProxy(self,param):
  179. action = {
  180. 'url':'',
  181. 'header':'',
  182. 'param':'',
  183. 'type':'string',
  184. 'after':''
  185. }
  186. return [200, "video/MP2T", action, ""]