创艺.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 base64
  9. from Crypto.Cipher import AES
  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 homeContent(self, filter):
  17. result = {}
  18. cateManual = {
  19. "电影": "1",
  20. "剧集": "2",
  21. "动漫": "4",
  22. "综艺": "3",
  23. "纪录片": "30"
  24. }
  25. classes = []
  26. for k in cateManual:
  27. classes.append({
  28. 'type_name': k,
  29. 'type_id': cateManual[k]
  30. })
  31. result['class'] = classes
  32. if (filter):
  33. result['filters'] = self.config['filter']
  34. return result
  35. def homeVideoContent(self):
  36. result = {
  37. 'list': []
  38. }
  39. return result
  40. def categoryContent(self, tid, pg, filter, extend):
  41. result = {}
  42. 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"}
  43. url = 'https://www.30dian.cn/vodtype/{0}-{1}.html'.format(tid, pg)
  44. rsp = self.fetch(url,headers=header)
  45. root = self.html(self.cleanText(rsp.text))
  46. aList = root.xpath("//div[@class='myui-panel myui-panel-bg clearfix']/div/div/ul/li")
  47. videos = []
  48. for a in aList:
  49. name = a.xpath('./div/a/@title')[0]
  50. pic = a.xpath('./div/a/@data-original')[0]
  51. mark = a.xpath("./div/a/span/span[@class='tag']/text()")[0]
  52. sid = a.xpath("./div/a/@href")[0].replace("/", "").replace("voddetail", "").replace(".html", "")
  53. videos.append({
  54. "vod_id": sid,
  55. "vod_name": name,
  56. "vod_pic": pic,
  57. "vod_remarks": mark
  58. })
  59. result['list'] = videos
  60. result['page'] = pg
  61. result['pagecount'] = 999
  62. result['limit'] = 5
  63. result['total'] = 9999
  64. return result
  65. def detailContent(self, array):
  66. tid = array[0]
  67. url = 'https://www.30dian.cn/voddetail/{0}.html'.format(tid)
  68. 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"}
  69. rsp = self.fetch(url,headers=header)
  70. root = self.html(self.cleanText(rsp.text))
  71. divContent = root.xpath("//div[@class='col-lg-wide-75 col-md-wide-7 col-xs-1 padding-0']")[0]
  72. title = divContent.xpath(".//div[@class='myui-content__detail']/h1/text()")[0]
  73. pic = divContent.xpath(".//div[@class='myui-content__thumb']/a/img/@data-original")[0]
  74. det = divContent.xpath(".//div[@class='col-pd text-collapse content']/span[@class='data']")[0]
  75. if det.text is None:
  76. detail = det.xpath(".//p/text()")[0]
  77. else:
  78. detail = det.text
  79. vod = {
  80. "vod_id": tid,
  81. "vod_name": title,
  82. "vod_pic": pic,
  83. "type_name": "",
  84. "vod_year": "",
  85. "vod_area": "",
  86. "vod_remarks": "",
  87. "vod_actor": "",
  88. "vod_director": "",
  89. "vod_content": detail
  90. }
  91. infoArray = divContent.xpath(".//div[@class='myui-content__detail']/p[contains(@class,'data')]")
  92. for info in infoArray:
  93. content = info.xpath('string(.)')
  94. flag = "分类" in content
  95. if flag == True:
  96. infon = content.replace("\t","").replace("\n","").strip().split('\r')
  97. for inf in infon:
  98. if inf.startswith('分类'):
  99. vod['type_name'] = inf.replace("分类:", "")
  100. if inf.startswith('地区'):
  101. vod['vod_area'] = inf.replace("地区:", "")
  102. if inf.startswith('年份'):
  103. vod['vod_year'] = inf.replace("年份:", "")
  104. if content.startswith('主演'):
  105. vod['vod_actor'] = content.replace("\xa0", "/").replace("主演:", "").strip('/')
  106. if content.startswith('更新'):
  107. vod['vod_remarks'] = content.replace("更新:", "")
  108. if content.startswith('导演'):
  109. vod['vod_director'] = content.replace("\xa0", "").replace("导演:", "").strip('/')
  110. vod_play_from = '$$$'
  111. playFrom = []
  112. vodHeader = divContent.xpath(".//div[@class='myui-panel_hd']/div/ul/li/a[contains(@href,'playlist')]/text()")
  113. for v in vodHeader:
  114. playFrom.append(v.replace(" ", ""))
  115. vod_play_from = vod_play_from.join(playFrom)
  116. vod_play_url = '$$$'
  117. playList = []
  118. vodList = divContent.xpath(".//div[contains(@id,'playlist')]")
  119. for vl in vodList:
  120. vodItems = []
  121. aList = vl.xpath('./ul/li/a')
  122. if len(aList) <= 0:
  123. name = '无法找到播放源'
  124. tId = '00000'
  125. vodItems.append(name + "$" + tId)
  126. else:
  127. for tA in aList:
  128. href = tA.xpath('./@href')[0]
  129. name = tA.xpath("./text()")[0].replace(" ", "")
  130. tId = self.regStr(href, '/vodplay/(\\S+).html')
  131. vodItems.append(name + "$" + tId)
  132. joinStr = '#'
  133. joinStr = joinStr.join(vodItems)
  134. playList.append(joinStr)
  135. vod_play_url = vod_play_url.join(playList)
  136. vod['vod_play_from'] = vod_play_from
  137. vod['vod_play_url'] = vod_play_url
  138. result = {
  139. 'list': [
  140. vod
  141. ]
  142. }
  143. return result
  144. def searchContent(self, key, quick):
  145. url = 'https://www.30dian.cn/vodsearch/-------------.html?wd={0}'.format(key)
  146. header = {
  147. "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"}
  148. rsp = self.fetch(url, headers=header)
  149. root = self.html(self.cleanText(rsp.text))
  150. aList = root.xpath("//ul[contains(@class,'myui-vodlist__media clearfix')]/li")
  151. videos = []
  152. for a in aList:
  153. name = a.xpath(".//div[@class='detail']/h4/a/text()")[0]
  154. pic = a.xpath(".//a[contains(@class,'myui-vodlist__thumb')]//@data-original")[0]
  155. mark = a.xpath(".//span[@class='tag']/text()")[0]
  156. sid = a.xpath(".//div[@class='detail']/h4/a/@href")[0]
  157. sid = self.regStr(sid,'/voddetail/(\\S+).html')
  158. videos.append({
  159. "vod_id": sid,
  160. "vod_name": name,
  161. "vod_pic": pic,
  162. "vod_remarks": mark
  163. })
  164. result = {
  165. 'list': videos
  166. }
  167. return result
  168. def parseCBC(self, enc, key, iv):
  169. keyBytes = key.encode("utf-8")
  170. ivBytes = iv.encode("utf-8")
  171. cipher = AES.new(keyBytes, AES.MODE_CBC, ivBytes)
  172. msg = cipher.decrypt(enc)
  173. paddingLen = msg[len(msg) - 1]
  174. return msg[0:-paddingLen]
  175. def playerContent(self, flag, id, vipFlags):
  176. result = {}
  177. header = {
  178. "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"}
  179. if id == '00000':
  180. return {}
  181. url = 'https://www.30dian.cn/vodplay/{0}.html'.format(id)
  182. rsp = self.fetch(url,headers=header)
  183. root = self.html(self.cleanText(rsp.text))
  184. scripts = root.xpath("//div[@class='embed-responsive clearfix']/script[@type='text/javascript']/text()")[0]
  185. ukey = re.findall(r"url(.*)url_next", scripts)[0].replace('"', "").replace(',', "").replace(':', "")
  186. pf = re.findall(r'\"from\":\"(.*?)\"', scripts)[0]
  187. purl = urllib.parse.unquote(ukey)
  188. if purl.startswith('http'):
  189. purl = purl
  190. if pf == 'wjm3u8':
  191. prsp = self.fetch(purl, headers=header)
  192. purle = prsp.text.strip('\n').split('\n')[-1]
  193. purls = re.findall(r"http.*://.*?/", purl)[0].strip('/')
  194. purl = purls + purle
  195. else:
  196. scrurl = 'https://vip.30dian.cn/?url={0}'.format(purl)
  197. script = self.fetch(scrurl,headers=header)
  198. html = script.text
  199. pat = 'var le_token = \\"([\\d\\w]+)\\"'
  200. cpat = 'getVideoInfo\\(\\"(.*)\\"\\)'
  201. content = self.regStr(html, cpat)
  202. iv = self.regStr(html, pat)
  203. key = 'A42EAC0C2B408472'
  204. purl = self.parseCBC(base64.b64decode(content), key, iv).decode()
  205. result["parse"] = 0
  206. result["playUrl"] = ''
  207. result["url"] = purl
  208. 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"}
  209. return result
  210. config = {
  211. "player": {},
  212. "filter": {}
  213. }
  214. header = {}
  215. def isVideoFormat(self, url):
  216. pass
  217. def manualVideoCheck(self):
  218. pass
  219. def localProxy(self, param):
  220. action = {
  221. 'url': '',
  222. 'header': '',
  223. 'param': '',
  224. 'type': 'string',
  225. 'after': ''
  226. }
  227. return [200, "video/MP2T", action, ""]