py_cyys1.py 8.2 KB

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