爱看.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #coding=utf-8
  2. #!/usr/bin/python
  3. import sys
  4. sys.path.append('..')
  5. from base.spider import Spider
  6. import base64
  7. import math
  8. import json
  9. import requests
  10. class Spider(Spider):
  11. def getName(self):
  12. return "爱看影视"
  13. def init(self,extend=""):
  14. pass
  15. def isVideoFormat(self,url):
  16. pass
  17. def manualVideoCheck(self):
  18. pass
  19. def homeContent(self,filter):
  20. result = {}
  21. cateManual = {
  22. "电影": "1",
  23. "剧集": "2",
  24. "综艺": "3",
  25. "动漫": "4",
  26. "美剧": "16",
  27. "日韩剧": "15",
  28. }
  29. classes = []
  30. for k in cateManual:
  31. classes.append({
  32. 'type_name': k,
  33. 'type_id': cateManual[k]
  34. })
  35. result['class'] = classes
  36. if (filter):
  37. result['filters'] = self.config['filter']
  38. return result
  39. def homeVideoContent(self):
  40. result = {}
  41. return result
  42. def categoryContent(self,tid,pg,filter,extend):
  43. result = {}
  44. url = 'https://ikan6.vip/vodtype/{0}-{1}/'.format(tid,pg)
  45. rsp = self.fetch(url)
  46. html = self.html(rsp.text)
  47. aList = html.xpath("//ul[contains(@class, 'myui-vodlist')]/li")
  48. videos = []
  49. numvL = len(aList)
  50. pgc = math.ceil(numvL/15)
  51. for a in aList:
  52. aid = a.xpath("./div[contains(@class, 'myui-vodlist__box')]/a/@href")[0]
  53. aid = self.regStr(reg=r'/voddetail/(.*?)/', src=aid)
  54. img = a.xpath(".//div[contains(@class, 'myui-vodlist__box')]/a/@data-original")[0]
  55. name = a.xpath(".//div[contains(@class, 'myui-vodlist__box')]/a/@title")[0]
  56. remark = a.xpath(".//span[contains(@class, 'pic-text text-right')]/text()")[0]
  57. videos.append({
  58. "vod_id": aid,
  59. "vod_name": name,
  60. "vod_pic": img,
  61. "vod_remarks": remark
  62. })
  63. result['list'] = videos
  64. result['page'] = pg
  65. result['pagecount'] = pgc
  66. result['limit'] = numvL
  67. result['total'] = numvL
  68. return result
  69. def detailContent(self,array):
  70. aid = array[0]
  71. url = 'https://ikan6.vip/voddetail/{0}/'.format(aid)
  72. rsp = self.fetch(url)
  73. html = self.html(rsp.text)
  74. node = html.xpath("//div[@class='myui-content__detail']")[0]
  75. title = node.xpath("./h1/text()")[0]
  76. pic = html.xpath("//a[@class='myui-vodlist__thumb picture']/img/@src")[0]
  77. cont = html.xpath("//div[@class='col-pd text-collapse content']/span[@class='data']/p/text()")[0].replace('\u3000','')
  78. infoList = node.xpath("./p[@class='data']")
  79. for info in infoList:
  80. content = info.xpath('string(.)').replace('\t','').replace('\r','').replace('\n','').strip()
  81. if content.startswith('导演:'):
  82. dir = content.replace('导演:','').strip()
  83. if content.startswith('主演:'):
  84. act = content.replace('主演:','').replace('\xa0','/').strip()
  85. if content.startswith('分类:'):
  86. infos = content.split(':')
  87. for i in range(0, len(infos)):
  88. if infos[i] == '分类':
  89. typeName = infos[i + 1][:-2]
  90. if infos[i][-2:] == '地区':
  91. area = infos[i + 1][:-2]
  92. if infos[i][-2:] == '年份':
  93. year = infos[i + 1]
  94. vod = {
  95. "vod_id": aid,
  96. "vod_name": title,
  97. "vod_pic": pic,
  98. "type_name": typeName,
  99. "vod_year": year,
  100. "vod_area": area,
  101. "vod_remarks": '',
  102. "vod_actor": act,
  103. "vod_director": dir,
  104. "vod_content": cont
  105. }
  106. urlList = html.xpath("//div[@class='tab-content myui-panel_bd']/div/ul/li")
  107. playUrl = ''
  108. for url in urlList:
  109. purl = url.xpath("./a/@href")[0]
  110. purl = self.regStr(reg=r'/vodplay/(.*?)/', src=purl)
  111. name = url.xpath("./a/text()")[0]
  112. playUrl = playUrl + '{0}${1}#'.format(name, purl)
  113. vod['vod_play_from'] = '爱看影视'
  114. vod['vod_play_url'] = playUrl
  115. result = {
  116. 'list': [
  117. vod
  118. ]
  119. }
  120. return result
  121. def verifyCode(self):
  122. retry = 10
  123. header = {
  124. "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"}
  125. while retry:
  126. try:
  127. session = requests.session()
  128. img = session.get('https://ikan6.vip/index.php/verify/index.html?', headers=header).content
  129. code = session.post('https://api.nn.ci/ocr/b64/text', data=base64.b64encode(img).decode()).text
  130. res = session.post(url=f"https://ikan6.vip/index.php/ajax/verify_check?type=search&verify={code}",
  131. headers=header).json()
  132. if res["msg"] == "ok":
  133. return session
  134. except Exception as e:
  135. print(e)
  136. finally:
  137. retry = retry - 1
  138. def searchContent(self,key,quick):
  139. result = {}
  140. url = 'https://ikan6.vip/vodsearch/-------------/?wd={0}&submit='.format(key)
  141. session = self.verifyCode()
  142. rsp = session.get(url)
  143. root = self.html(rsp.text)
  144. vodList = root.xpath("//ul[@class='myui-vodlist__media clearfix']/li")
  145. videos = []
  146. for vod in vodList:
  147. name = vod.xpath("./div/h4/a/text()")[0]
  148. pic = vod.xpath("./div[@class='thumb']/a/@data-original")[0]
  149. mark = vod.xpath("./div[@class='thumb']/a/span[@class='pic-text text-right']/text()")[0]
  150. sid = vod.xpath("./div[@class='thumb']/a/@href")[0]
  151. sid = self.regStr(sid,"/voddetail/(\\S+)/")
  152. videos.append({
  153. "vod_id":sid,
  154. "vod_name":name,
  155. "vod_pic":pic,
  156. "vod_remarks":mark
  157. })
  158. result = {
  159. 'list': videos
  160. }
  161. return result
  162. def playerContent(self,flag,id,vipFlags):
  163. result = {}
  164. url = 'https://ikan6.vip/vodplay/{0}/'.format(id)
  165. rsp = self.fetch(url)
  166. info = json.loads(self.regStr(reg=r'var player_data=(.*?)</script>', src=rsp.text))
  167. if info['encrypt'] == 1:
  168. str = info['url'].replace('%u', '\\u').encode('utf-8').decode('unicode_escape')
  169. elif info['encrypt'] == 2:
  170. str = base64.b64decode(info['url'].replace('%u', '\\u').encode('utf-8').decode('unicode_escape')).decode(
  171. 'UTF-8')
  172. elif info['encrypt'] == 3:
  173. string = info['url'][8:len(info['url'])]
  174. substr = base64.b64decode(string).decode('UTF-8')
  175. str = substr[8:len(substr) - 8].split('_')[-1]
  176. purl = 'https://weiyunsha.ikan6.vip/tsjmjson/play.php?sign={0}'.format(str)
  177. result["parse"] = 0
  178. result["playUrl"] = ''
  179. result["url"] = purl
  180. result["header"] = ''
  181. return result
  182. config = {
  183. "player": {},
  184. "filter": {}
  185. }
  186. header = {}
  187. def localProxy(self,param):
  188. action = {
  189. 'url':'',
  190. 'header':'',
  191. 'param':'',
  192. 'type':'string',
  193. 'after':''
  194. }
  195. return [200, "video/MP2T", action, ""]