创艺.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # coding=utf-8
  2. # !/usr/bin/python
  3. import sys
  4. import re
  5. sys.path.append('..')
  6. from base.spider import Spider
  7. import urllib.parse
  8. import json
  9. import base64
  10. from Crypto.Cipher import AES
  11. class Spider(Spider): # 元类 默认的元类 type
  12. def getName(self):
  13. return "创艺影视"
  14. def init(self, extend=""):
  15. print("============{0}============".format(extend))
  16. pass
  17. def homeContent(self, filter):
  18. result = {}
  19. cateManual = {
  20. "电影": "1",
  21. "剧集": "2",
  22. "动漫": "4",
  23. "综艺": "3",
  24. "纪录片": "30"
  25. }
  26. classes = []
  27. for k in cateManual:
  28. classes.append({
  29. 'type_name': k,
  30. 'type_id': cateManual[k]
  31. })
  32. result['class'] = classes
  33. if (filter):
  34. result['filters'] = self.config['filter']
  35. return result
  36. def homeVideoContent(self):
  37. result = {
  38. 'list': []
  39. }
  40. return result
  41. def categoryContent(self, tid, pg, filter, extend):
  42. result = {}
  43. header = {"User-Agent": "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36"}
  44. url = 'https://www.30dian.cn/vodtype/{0}-{1}.html'.format(tid, pg)
  45. rsp = self.fetch(url,headers=header)
  46. root = self.html(self.cleanText(rsp.text))
  47. aList = root.xpath("//div[@class='module-list module-lines-list']/div/div")
  48. videos = []
  49. for a in aList:
  50. name = name = a.xpath("./div[@class='module-item-cover']/div/a/@title")[0]
  51. pic = a.xpath("./div[@class='module-item-cover']/div/img/@data-src")[0]
  52. mark = a.xpath("./div[@class='module-item-text']/text()")[0]
  53. sid = self.regStr(reg=r'voddetail\/(.*?).html', src=a.xpath("./div[@class='module-item-cover']/div/a/@href")[0])
  54. videos.append({
  55. "vod_id": sid,
  56. "vod_name": name,
  57. "vod_pic": pic,
  58. "vod_remarks": mark
  59. })
  60. result['list'] = videos
  61. result['page'] = pg
  62. result['pagecount'] = 999
  63. result['limit'] = 5
  64. result['total'] = 9999
  65. return result
  66. def detailContent(self, array):
  67. tid = array[0]
  68. url = 'https://www.30dian.cn/voddetail/{0}.html'.format(tid)
  69. header = {"User-Agent": "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36"}
  70. rsp = self.fetch(url,headers=header)
  71. root = self.html(self.cleanText(rsp.text))
  72. divContent = root.xpath("//div[@class='box view-heading']")[0]
  73. title = divContent.xpath(".//div[@class='video-info-header']/h1/text()")[0].strip()
  74. pic = divContent.xpath(".//div[@class='module-item-pic']/img/@data-src")[0]
  75. vod = {
  76. "vod_id": tid,
  77. "vod_name": title,
  78. "vod_pic": pic,
  79. "type_name": "",
  80. "vod_year": "",
  81. "vod_area": "",
  82. "vod_remarks": "",
  83. "vod_actor": "",
  84. "vod_director": "",
  85. "vod_content": ""
  86. }
  87. vod_play_from = '$$$'
  88. playFrom = []
  89. titles = root.xpath(".//div[contains(@class,'module-player-tab')]/div[@class='module-tab-items']/div[@class='module-tab-content']")[0]
  90. vodHeader = titles.xpath("./div/span/text()")
  91. for v in vodHeader:
  92. playFrom.append(self.cleanText(v).replace(" ", ""))
  93. vod_play_from = vod_play_from.join(playFrom)
  94. vod_play_url = '$$$'
  95. playList = []
  96. vodList = root.xpath(".//div[@class='module']/div[contains(@id,'glist-')]")
  97. for vl in vodList:
  98. vodItems = []
  99. aList = vl.xpath(".//div[@class='scroll-content']/a")
  100. if len(aList) <= 0:
  101. name = '无法找到播放源'
  102. tId = '00000'
  103. vodItems.append(name + "$" + tId)
  104. else:
  105. for tA in aList:
  106. href = tA.xpath('./@href')[0]
  107. name = tA.xpath("./span/text()")[0].strip()
  108. tId = self.regStr(href, '/vodplay/(\\S+).html')
  109. vodItems.append(name + "$" + tId)
  110. joinStr = '#'
  111. joinStr = joinStr.join(vodItems)
  112. playList.append(joinStr)
  113. vod_play_url = vod_play_url.join(playList)
  114. vod['vod_play_from'] = vod_play_from
  115. vod['vod_play_url'] = vod_play_url
  116. result = {
  117. 'list': [
  118. vod
  119. ]
  120. }
  121. return result
  122. def searchContent(self, key, quick):
  123. url = 'https://www.30dian.cn/vodsearch/-------------.html?wd={0}'.format(key)
  124. header = {
  125. "User-Agent": "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36"}
  126. rsp = self.fetch(url, headers=header)
  127. root = self.html(self.cleanText(rsp.text))
  128. aList = root.xpath("//div[@class='module-items']/div")
  129. videos = []
  130. for a in aList:
  131. name = a.xpath(".//div[@class='module-item-pic']/img/@alt")[0]
  132. pic = a.xpath(".//div[@class='module-item-pic']/img/@data-src")[0]
  133. sid = a.xpath(".//div[@class='video-info']/div[@class='video-info-header']/a/@href")[0]
  134. sid = self.regStr(sid,'/voddetail/(\\S+).html')
  135. videos.append({
  136. "vod_id": sid,
  137. "vod_name": name,
  138. "vod_pic": pic,
  139. "vod_remarks": ''
  140. })
  141. result = {
  142. 'list': videos
  143. }
  144. return result
  145. def parseCBC(self, enc, key, iv):
  146. keyBytes = key.encode("utf-8")
  147. ivBytes = iv.encode("utf-8")
  148. cipher = AES.new(keyBytes, AES.MODE_CBC, ivBytes)
  149. msg = cipher.decrypt(enc)
  150. paddingLen = msg[len(msg) - 1]
  151. return msg[0:-paddingLen]
  152. def playerContent(self, flag, id, vipFlags):
  153. result = {}
  154. header = {
  155. "User-Agent": "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36"}
  156. if id == '00000':
  157. return {}
  158. url = 'https://www.30dian.cn/vodplay/{0}.html'.format(id)
  159. rsp = self.fetch(url, headers=header)
  160. jo = self.regStr(reg='var player_data=(.*?)</script>', src=self.cleanText(rsp.text))
  161. scripts = json.loads(jo)
  162. ukey = scripts['url']
  163. pf = scripts['from']
  164. purl = urllib.parse.unquote(ukey)
  165. if purl.startswith('http'):
  166. purl = purl
  167. if pf == 'wjm3u8':
  168. prsp = self.fetch(purl, headers=header)
  169. purle = prsp.text.strip('\n').split('\n')[-1]
  170. purls = re.findall(r"http.*://.*?/", purl)[0].strip('/')
  171. purl = purls + purle
  172. else:
  173. scrurl = 'https://vip.30dian.cn/?url={0}'.format(purl)
  174. script = self.fetch(scrurl,headers=header)
  175. html = script.text
  176. pat = 'var le_token = \\"([\\d\\w]+)\\"'
  177. cpat = 'getVideoInfo\\(\\"(.*)\\"\\)'
  178. content = self.regStr(html, cpat)
  179. iv = self.regStr(html, pat)
  180. key = 'A42EAC0C2B408472'
  181. purl = self.parseCBC(base64.b64decode(content), key, iv).decode()
  182. result["parse"] = 0
  183. result["playUrl"] = ''
  184. result["url"] = purl
  185. result["header"] = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"}
  186. return result
  187. config = {
  188. "player": {},
  189. "filter": {}
  190. }
  191. header = {}
  192. def isVideoFormat(self, url):
  193. pass
  194. def manualVideoCheck(self):
  195. pass
  196. def localProxy(self, param):
  197. action = {
  198. 'url': '',
  199. 'header': '',
  200. 'param': '',
  201. 'type': 'string',
  202. 'after': ''
  203. }
  204. return [200, "video/MP2T", action, ""]