py_zhaozy.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #coding=utf-8
  2. #!/usr/bin/python
  3. import sys
  4. import time
  5. import json
  6. import requests
  7. from base64 import b64encode
  8. from collections import OrderedDict
  9. sys.path.append('..')
  10. from base.spider import Spider
  11. class Spider(Spider):
  12. def getDependence(self):
  13. return ['py_ali']
  14. def getName(self):
  15. return "py_zhaozy"
  16. def init(self,extend):
  17. self.ali = extend[0]
  18. print("============py_zhaozy============")
  19. pass
  20. def isVideoFormat(self,url):
  21. pass
  22. def manualVideoCheck(self):
  23. pass
  24. def homeContent(self,filter):
  25. result = {}
  26. return result
  27. def homeVideoContent(self):
  28. result = {}
  29. return result
  30. def categoryContent(self,tid,pg,filter,extend):
  31. result = {}
  32. return result
  33. header = {
  34. "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36",
  35. "Referer": "https://zhaoziyuan.la/"
  36. }
  37. def detailContent(self,array):
  38. hashMap = {}
  39. dirname = ''
  40. ids = array[0].split('@@@')
  41. pattern = '(https://www.aliyundrive.com/s/[^\"]+)'
  42. url = self.regStr(ids[1], pattern)
  43. if len(url) > 0:
  44. self.listFiles(hashMap, dirname, [ids[1]])
  45. else:
  46. rsp = self.fetch('https://zhaoziyuan.la/' + ids[1])
  47. url = self.regStr(rsp.text, pattern)
  48. if len(url) == 0:
  49. return {}
  50. self.listFiles(hashMap, dirname, [url])
  51. if not hashMap:
  52. return {}
  53. sortedMap = sorted(hashMap.items(), key=lambda x: x[0])
  54. vod = {
  55. "vod_id": array[0],
  56. "vod_name": ids[0],
  57. "vod_pic": 'https://p2.itc.cn/q_70/images03/20211009/59c75745d3524163b9277c4006020ac0.jpeg',
  58. "type_name": "",
  59. "vod_year": "",
  60. "vod_area": "",
  61. "vod_remarks": "",
  62. "vod_actor": "",
  63. "vod_director": "",
  64. "vod_content": ""
  65. }
  66. vod['vod_play_from'] = '原画$$$超清'
  67. vod_play_url = ''
  68. YHplayurl = ''
  69. CQplayurl = ''
  70. subDict = {}
  71. nameList = []
  72. for sm in sortedMap:
  73. if 'subtitles' in sm:
  74. for subList in sm[1]:
  75. subDict.update({os.path.splitext(subList['name'])[0]: sm[1].index(subList)})
  76. else:
  77. name = sm[0]
  78. sm[1][0]['params']['downloader_switch'] = 'True'
  79. YHurl = 'Docker域名或IP:端口/ali_resolve?item=' + b64encode(
  80. json.dumps(sm[1][0]['params']).encode("utf-8")).decode("utf-8")
  81. CQurl = 'Docker域名或IP:端口/ali_resolve?item=' + b64encode(
  82. json.dumps(sm[1][1]['params']).encode("utf-8")).decode("utf-8")
  83. YHplayurl = '{}#{}${}'.format(YHplayurl, name, YHurl)
  84. CQplayurl = '{}#{}${}'.format(CQplayurl, name, CQurl)
  85. name = name.split('/')[0]
  86. if ']|' in name:
  87. name = name.split('|')[1]
  88. nameList.append(name)
  89. for nL in nameList:
  90. for sbkey in subDict:
  91. if os.path.splitext(nL)[0] in sbkey:
  92. value = json.dumps(sm[1][subDict[sbkey]]['params'])
  93. requests.post('Docker域名或IP:端口/cache', params={'key': 'alisub', }, data=value, headers={'Content-Length': str(len(value))})
  94. vod['vod_play_url'] = YHplayurl.strip('#') + '$$$' + CQplayurl.strip('#')
  95. result = {
  96. 'list': [vod]
  97. }
  98. return result
  99. def listFiles(self, map, dirname, list):
  100. header = {
  101. "User-Agent": "Mozilla/5.0 (Linux; Android 12; V2049A Build/SP1A.210812.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.129 Mobile Safari/537.36"
  102. }
  103. parent_item = {
  104. 'id': list[0],
  105. 'params': {}
  106. }
  107. url = 'Docker域名或IP:端口/ali_list?item=' + b64encode(json.dumps(parent_item).encode("utf-8")).decode("utf-8") + '&display_file_size=True'
  108. rsp = self.fetch(url, headers=header)
  109. while rsp.status_code != 200:
  110. time.sleep(1)
  111. rsp = self.fetch(url, headers=header)
  112. if rsp.text in ['Erro', 'Token', 'Session', 'Lapse', 'None']:
  113. return {}
  114. jo = json.loads(rsp.text)
  115. folderList = []
  116. dirnameList = []
  117. subtitlesList = []
  118. for info in jo:
  119. if dirname != '' and not dirname.startswith('['):
  120. dirname = '[' + dirname + ']|'
  121. if info['params']['file_type'] == 'folder':
  122. folderList.append(info['id'])
  123. dirnameList.append(info['name'])
  124. else:
  125. size = '/[{}]'.format(info['description'].split('\n')[0].split(':')[1])
  126. map[dirname + info['name'] + size] = info['sources']
  127. if info['subtitles'] != [] and info['subtitles'][0] not in subtitlesList:
  128. subtitlesList = subtitlesList + info['subtitles']
  129. if len(subtitlesList) > 0:
  130. map.update({'subtitles': subtitlesList})
  131. for folder in folderList:
  132. dirname = dirnameList[folderList.index(folder)]
  133. self.listFiles(map, dirname, [folder])
  134. def searchContent(self,key,quick):
  135. map = {
  136. '7':'文件夹',
  137. '1':'视频'
  138. }
  139. ja = []
  140. cookies_str = requests.get('https://getplayurl.lm317379829.repl.co/cache?key=cookies')
  141. if cookies_str.text == '':
  142. cookies = self.getCookie()
  143. else:
  144. cookies_dict = cookies_str.json()
  145. if cookies_dict['expires'] <= int(time.time()):
  146. cookies = self.getCookie()
  147. else:
  148. cookies = requests.cookies.RequestsCookieJar()
  149. for ckey, value in cookies_dict.items():
  150. if ckey == 'domain' or ckey == 'expires':
  151. continue
  152. c = requests.cookies.create_cookie(ckey, value)
  153. c.domain = cookies_dict['domain']
  154. c.expires = cookies_dict['expires']
  155. cookies.set_cookie(c)
  156. for tKey in map.keys():
  157. url = "https://zhaoziyuan.la/so?filename={0}&t={1}".format(key,tKey)
  158. rsp = self.fetch(url, headers=self.header, cookies=cookies)
  159. root = self.html(self.cleanText(rsp.text))
  160. aList = root.xpath("//li[@class='clear']/div/div[@class='news_text']/a")
  161. for a in aList:
  162. name = self.xpText(a,'./h3/text()')
  163. if len(name) > 15:
  164. name = ''.join(OrderedDict.fromkeys(name))
  165. remark = self.xpText(a,'./p/text()').split('|')[1].strip()
  166. jo = {
  167. 'vod_id': name + '@@@' + self.xpText(a,'@href'),
  168. 'vod_name': name,
  169. 'vod_pic': "https://inews.gtimg.com/newsapp_bt/0/13263837859/1000",
  170. "vod_remarks": remark
  171. }
  172. ja.append(jo)
  173. result = {
  174. 'list':ja
  175. }
  176. return result
  177. def getCookie(self):
  178. header = {
  179. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36",
  180. "Referer": "https://zhaoziyuan.la/login.html",
  181. "Origin": "https://zhaoziyuan.la/"
  182. }
  183. logininfo = {'username': 'Unbaked4136', 'password': '4hzxQkB9yxX5EP'}
  184. r = requests.post('https://zhaoziyuan.la/logiu.html', data=logininfo, headers=header, timeout=5)
  185. cookies = r.cookies.get_dict()
  186. cookies.update({'expires': int(time.time()) + 604200})
  187. cookies.update({'domain': 'zhaoziyuan.la'})
  188. requests.post('https://getplayurl.lm317379829.repl.co/cache?key=cookies', data=json.dumps(cookies))
  189. return r.cookies
  190. def playerContent(self,flag,id,vipFlags):
  191. result = {}
  192. token = requests.get('Token外链地址').text.replace('\n', '').replace(' ', '')
  193. url = id
  194. rsp = self.fetch(url=url)
  195. purl = '{}&token={}&connection={}' .format(rsp.text, token, '20')
  196. alisub = requests.get('Docker域名或IP:端口/cache',params={'key': 'alisub'}).text
  197. if alisub != '':
  198. requests.delete('Docker域名或IP:端口/cache', params={'key': 'alisub'})
  199. suburl = 'Docker域名或IP:端口/proxy_download_file?params={}&token={}&connection=1'.format(b64encode(alisub).encode("utf-8").decode("utf-8"), token)
  200. result['subt'] = suburl
  201. result["parse"] = 0
  202. result["playUrl"] = ''
  203. result["url"] = purl
  204. return result
  205. config = {
  206. "player": {},
  207. "filter": {}
  208. }
  209. def localProxy(self,param):
  210. return [200, "video/MP2T", action, ""]