py_ikan.py 6.4 KB

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