1905.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 base64
  8. import re
  9. import math
  10. import time
  11. import uuid
  12. import hashlib
  13. from urllib import request, parse
  14. import urllib
  15. import urllib.request
  16. class Spider(Spider): # 元类 默认的元类 type
  17. def getName(self):
  18. return "1905电影"
  19. def init(self,extend=""):
  20. print("============{0}============".format(extend))
  21. pass
  22. def isVideoFormat(self,url):
  23. pass
  24. def manualVideoCheck(self):
  25. pass
  26. def homeContent(self,filter):
  27. result = {}
  28. cateManual = {
  29. "电影": "n_1",
  30. "微电影":"n_1_c_922",
  31. "系列电影":"n_2",
  32. "纪录片":"c_927",
  33. "晚会":"n_1_c_586",
  34. "独家":"n_1_c_178",
  35. "综艺":"n_1_c_1024"
  36. # ,"体育":"n_1_c_1053"
  37. }
  38. classes = []
  39. for k in cateManual:
  40. classes.append({
  41. 'type_name':k,
  42. 'type_id':cateManual[k]
  43. })
  44. result['class'] = classes
  45. if(filter):
  46. result['filters'] = self.config['filter']
  47. return result
  48. def homeVideoContent(self):
  49. url = 'https://www.1905.com/vod/cctv6/lst/'
  50. rsp = self.fetch(url, headers=self.header)
  51. html = self.html(rsp.text)
  52. aList = html.xpath("//div[@class='grid-2x']/a")
  53. videos = self.custom_list(aList=aList)
  54. result = {
  55. 'list':videos
  56. }
  57. return result
  58. def categoryContent(self,tid,pg,filter,extend):
  59. result = {}
  60. videos=[]
  61. by='/o1p'
  62. if 'by' in extend.keys():
  63. by='/{0}p'.format(extend['by'])
  64. url = 'https://www.1905.com/vod/list/{0}{2}{1}.html'.format(tid, pg,by)
  65. rsp = self.fetch(url, headers=self.header)
  66. HtmlTxt=rsp.text
  67. html = self.html(HtmlTxt)
  68. aList = html.xpath("//section[contains(@class,'search-list')]/div/a" if tid != u'n_2' else "//div[@class='mod']/div[1]/a")
  69. videos = self.custom_list(aList=aList)
  70. limit = len(aList)
  71. result['list'] = videos
  72. result['page'] = pg
  73. result['pagecount'] = 100
  74. result['limit'] = limit
  75. result['total'] = 100 * limit
  76. return result
  77. def detailContent(self,array):
  78. result = {}
  79. aid = array[0]
  80. vodItems=[]
  81. playList=[]
  82. vod_play_from=['1905电影',]
  83. if aid.isdigit()==False:
  84. rsp = self.fetch(aid, headers=self.header)
  85. HtmlTxt=rsp.text
  86. url=self.regStr(reg=r'<a class="iconBanner-playBtn icon-banner btn-play"\s*href="(.+?)"',src=HtmlTxt)
  87. if url=='':
  88. url=self.regStr(reg=r'property="og:url"\scontent="(.+?)"',src=HtmlTxt)
  89. if len(self.regStr(reg=r'(vip.1905)',src=url))>3:
  90. vod_play_from=['1905电影(需要vip解析)',]
  91. aid=url
  92. else:
  93. aid=self.regStr(reg=r'play/(.*?)\.sh',src=url)
  94. if aid=='':
  95. return {'list': []}
  96. elif aid.isdigit() and vod_play_from[0].find('需要vip解析')<0:
  97. url = "https://www.1905.com/api/content/?callback=&m=Vod&a=getVodSidebar&id={0}&fomat=json".format(aid)
  98. rsp = self.fetch(url, headers=self.header)
  99. HtmlTxt=rsp.text
  100. root = json.loads(HtmlTxt)
  101. title = root['title']
  102. pic = root['thumb']
  103. remark = root['commendreason']
  104. content = root['description']
  105. actor = root['starring']
  106. direct = root['direct']
  107. vodItems.append(title + "$" + aid)
  108. series = root['info']['series_data']
  109. series = root['info']['series_data']
  110. for ser in series:
  111. vodItems.append(ser['title'] + "$" + ser['contentid'])
  112. joinStr = '#'.join(vodItems)
  113. playList.append(joinStr)
  114. else:
  115. rsp = self.fetch(array[0], headers=self.header)
  116. HtmlTxt=rsp.text
  117. title=self.regStr(reg=r'<div class="container-right">\s*\r*\n*\t*<h1>(.+?)<',src=HtmlTxt).replace(' ','')
  118. pic=self.regStr(reg=r'<img class="poster" src="(.+?)"',src=HtmlTxt)
  119. remark=''
  120. actor=''
  121. direct=''
  122. content=self.regStr(reg=r'<p>(.+?)</p>',src=HtmlTxt)
  123. vodItems.append(title + "$" + aid)
  124. joinStr = '#'.join(vodItems)
  125. playList.append(joinStr)
  126. vod = {
  127. "vod_id":array[0],
  128. "vod_name":title,
  129. "vod_pic":pic,
  130. "type_name":'',
  131. "vod_year":"",
  132. "vod_area":"",
  133. "vod_remarks":remark,
  134. "vod_actor":actor,
  135. "vod_director":direct,
  136. "vod_content":content
  137. }
  138. vod['vod_play_from'] = "$$$".join(vod_play_from)
  139. vod['vod_play_url'] = "$$$".join(playList)
  140. result = {
  141. 'list':[
  142. vod
  143. ]
  144. }
  145. return result
  146. def searchContent(self,key,quick):
  147. url = 'https://www.1905.com/search/index-p-type-film-q-{}.html?envod=1&year=0&score=0&order=0'.format(key)#只搜索能看电影,想搜其它的可以把html之后的字符删掉
  148. #https://www.1905.com/search/index-p-type-all-q-{}.html
  149. rsp = self.fetch(url, headers=self.header)
  150. html = self.html(rsp.text)
  151. aList = html.xpath("//div/div[contains(@class,'new_content')]/div/div/div/a")
  152. videos = self.custom_list(aList=aList)
  153. result = {
  154. 'list':videos
  155. }
  156. return result
  157. def playerContent(self,flag,id,vipFlags):
  158. result = {}
  159. if flag.find('vip解析')>0:
  160. result["parse"] = 1#0=直接播放、1=嗅探
  161. result["playUrl"] =''
  162. result["url"] = id
  163. result['jx'] = 1#1=VIP解析,0=不解析
  164. result["header"] = ''
  165. else:
  166. nonce = int(round(time.time() * 1000))
  167. expiretime = nonce + 600
  168. uid = str(uuid.uuid4())
  169. playerid = uid.replace("-", "")[5:20]
  170. 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)
  171. signature = hashlib.sha1(signature.encode()).hexdigest()
  172. 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)
  173. rsp = self.fetch(url, headers=self.header)
  174. HtmlTxt=rsp.text
  175. jo = json.loads(HtmlTxt.replace("(", "").replace(")", ""))
  176. data = jo['data']['sign']
  177. sign = ''
  178. qualityStr = ''
  179. if 'uhd' in data.keys():
  180. sign = data['uhd']['sign']
  181. qualityStr = 'uhd'
  182. elif 'hd' in data.keys():
  183. sign = data['hd']['sign']
  184. qualityStr = 'hd'
  185. elif 'sd' in data.keys():
  186. sign = data['sd']['sign']
  187. qualityStr = 'sd'
  188. host = jo['data']['quality'][qualityStr]['host']
  189. path = jo['data']['path'][qualityStr]['path']
  190. playUrl = host + sign + path
  191. result["parse"] = 1#0=直接播放、1=嗅探
  192. result["playUrl"] =''
  193. result["url"] = playUrl
  194. result["header"] = self.header
  195. return result
  196. config = {
  197. "player": {},
  198. "filter": {
  199. "n_1":[
  200. {"key":"by","name":"排序:","value":[{"n":"默认(最新)","v":"o1"},{"n":"最热","v":"o3"},{"n":"好评","v":"o4"}]}
  201. ],
  202. "n_1_c_922":[
  203. {"key":"by","name":"排序:","value":[{"n":"默认(最新)","v":"o1"},{"n":"最热","v":"o3"},{"n":"好评","v":"o4"}]}
  204. ],
  205. "n_2":[
  206. {"key":"by","name":"排序:","value":[{"n":"默认(最新)","v":"o1"},{"n":"最热","v":"o3"},{"n":"好评","v":"o4"}]}
  207. ],
  208. "c_927":[
  209. {"key":"by","name":"排序:","value":[{"n":"默认(最新)","v":"o1"},{"n":"最热","v":"o3"},{"n":"好评","v":"o4"}]}
  210. ],
  211. "n_1_c_586":[
  212. {"key":"by","name":"排序:","value":[{"n":"默认(最新)","v":"o1"},{"n":"最热","v":"o3"},{"n":"好评","v":"o4"}]}
  213. ],
  214. "n_1_c_178":[
  215. {"key":"by","name":"排序:","value":[{"n":"默认(最新)","v":"o1"},{"n":"最热","v":"o3"},{"n":"好评","v":"o4"}]}
  216. ],
  217. "n_1_c_1024":[
  218. {"key":"by","name":"排序:","value":[{"n":"默认(最新)","v":"o1"},{"n":"最热","v":"o3"},{"n":"好评","v":"o4"}]}
  219. ]
  220. }
  221. }
  222. header = {
  223. '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',
  224. 'Referer': 'https://www.1905.com/vod/list/n_1/o3p1.html',
  225. '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'
  226. }
  227. def localProxy(self,param):
  228. return [200, "video/MP2T", action, ""]
  229. #-----------------------------------------------自定义函数-----------------------------------------------
  230. #分类取结果
  231. def custom_list(self,aList):
  232. videos = []
  233. for a in aList:
  234. img=a.xpath('./img/@src')[0]
  235. title=a.xpath('./img/@alt')[0]
  236. url=a.xpath("./@href")[0]
  237. if url.find('vip.1905')>1:#可以除掉
  238. continue
  239. if self.regStr(reg=r'(play)',src=url)=='':
  240. vod_id="{0}".format(url)
  241. else:
  242. id=self.regStr(reg=r'play/(.*?)\.sh',src=url)
  243. vod_id="{0}".format(id)
  244. videos.append({
  245. "vod_id":vod_id,
  246. "vod_name":title,
  247. "vod_pic":img,
  248. "vod_remarks":''
  249. })
  250. return videos