py_kunyu77.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #coding=utf-8
  2. #!/usr/bin/python
  3. import sys
  4. import json
  5. import time
  6. import hashlib
  7. import requests
  8. from urllib.parse import urlparse
  9. sys.path.append('..')
  10. from base.spider import Spider
  11. class Spider(Spider):
  12. def getName(self):
  13. return "77"
  14. def init(self,extend=""):
  15. print("============{0}============".format(extend))
  16. pass
  17. def homeContent(self,filter):
  18. result = {}
  19. url = 'http://api.tyun77.cn/api.php/provide/filter'
  20. rsp = self.fetch(url,headers=self.header)
  21. jo = json.loads(rsp.text)
  22. classes = []
  23. jData = jo['data']
  24. for cKey in jData.keys():
  25. classes.append({
  26. 'type_name':jData[cKey][0]['cat'].replace('电视剧', '剧集'),
  27. 'type_id':cKey
  28. })
  29. result['class'] = classes
  30. if(filter):
  31. result['filters'] = self.config['filter']
  32. return result
  33. def homeVideoContent(self):
  34. url = 'http://api.tyun77.cn/api.php/provide/homeBlock?type_id=0'
  35. rsp = self.fetch(url,headers=self.header)
  36. jo = json.loads(rsp.text)
  37. blockList = jo['data']['blocks']
  38. videos = []
  39. for block in blockList:
  40. vodList = block['contents']
  41. for vod in vodList:
  42. videos.append({
  43. "vod_id":vod['id'],
  44. "vod_name":vod['title'],
  45. "vod_pic":vod['videoCover'],
  46. "vod_remarks":vod['msg']
  47. })
  48. result = {
  49. 'list':videos
  50. }
  51. return result
  52. def categoryContent(self,tid,pg,filter,extend):
  53. result = {}
  54. ts = int(time.time())
  55. if 'type_id' not in extend.keys():
  56. extend['type_id'] = tid
  57. extend['pagenum'] = pg
  58. extend = {
  59. 'pcode': '010110002',
  60. 'version': '2.1.6',
  61. 'devid': hashlib.md5(str(time.time()).encode()).hexdigest(),
  62. 'package': 'com.sevenVideo.app.android',
  63. 'sys': 'android',
  64. 'sysver': 13,
  65. 'brand': 'Redmi',
  66. 'model': 'M2104K10AC',
  67. 'pagesize': 24
  68. }
  69. url = 'https://api.tyun77.cn/api.php/provide/searchFilter'
  70. header = self.header.copy()
  71. header['t'] = str(ts)
  72. header['TK'] = self.get_tk(url, extend, ts)
  73. rsp = requests.get(url, params=extend, headers=header, timeout=5)
  74. jo = json.loads(rsp.text)
  75. if jo['code'] == 1004:
  76. rsp = requests.get('http://api.tyun77.cn/api.php/provide/getDomain', params=extend, headers=header, timeout=5)
  77. if rsp.json()['code'] != 1:
  78. rsp = requests.get(url, params=extend, headers=header, timeout=5)
  79. jo = json.loads(rsp.text)
  80. else:
  81. return {}
  82. vodList = jo['data']['result']
  83. videos = []
  84. for vod in vodList:
  85. videos.append({
  86. "vod_id":vod['id'],
  87. "vod_name":vod['title'],
  88. "vod_pic":vod['videoCover'],
  89. "vod_remarks":vod['msg']
  90. })
  91. result['list'] = videos
  92. result['page'] = pg
  93. result['pagecount'] = 9999
  94. result['limit'] = 90
  95. result['total'] = 999999
  96. return result
  97. def detailContent(self,array):
  98. tid = array[0]
  99. ts = int(time.time())
  100. params = {
  101. 'pcode': '010110002',
  102. 'version': '2.1.6',
  103. 'devid': hashlib.md5(str(time.time()).encode()).hexdigest(),
  104. 'package': 'com.sevenVideo.app.android',
  105. 'sys': 'android',
  106. 'sysver': 13,
  107. 'brand': 'Redmi',
  108. 'model': 'M2104K10AC'
  109. }
  110. params['ids'] = tid
  111. url = 'http://api.tyun77.cn/api.php/provide/videoDetail'
  112. header = self.header.copy()
  113. header['t'] = str(ts)
  114. header['TK'] = self.get_tk(url, params, ts)
  115. rsp = requests.get(url, headers=header, params=params, timeout=5)
  116. jo = json.loads(rsp.text)
  117. if jo['code'] != 1:
  118. rsp = requests.get('http://api.tyun77.cn/api.php/provide/getDomain', params=params, headers=header, timeout=5)
  119. if rsp.json()['code'] == 1:
  120. rsp = requests.get(url, params=params, headers=header, timeout=5)
  121. jo = json.loads(rsp.text)
  122. else:
  123. return {}
  124. node = jo['data']
  125. vod = {
  126. "vod_id":node['id'],
  127. "vod_name":node['videoName'],
  128. "vod_pic":node['videoCover'],
  129. "type_name":node['subCategory'],
  130. "vod_year":node['year'],
  131. "vod_area":node['area'],
  132. "vod_remarks":node['msg'],
  133. "vod_actor":node['actor'],
  134. "vod_director":node['director'],
  135. "vod_content":node['brief'].strip()
  136. }
  137. listUrl = 'http://api.tyun77.cn/api.php/provide/videoPlaylist'
  138. header['TK'] = self.get_tk(listUrl, params, ts)
  139. listRsp = requests.get(listUrl, headers=header, params=params, timeout=5)
  140. listJo = json.loads(listRsp.text)
  141. playMap = {}
  142. episodes = listJo['data']['episodes']
  143. for ep in episodes:
  144. playurls = ep['playurls']
  145. for playurl in playurls:
  146. source = playurl['playfrom']
  147. if source not in playMap.keys():
  148. playMap[source] = []
  149. playMap[source].append(playurl['title'].strip() + '$' + playurl['playurl'])
  150. playFrom = []
  151. playList = []
  152. for key in playMap.keys():
  153. playFrom.append(key)
  154. playList.append('#'.join(playMap[key]))
  155. vod_play_from = '$$$'
  156. vod_play_from = vod_play_from.join(playFrom)
  157. vod_play_url = '$$$'
  158. vod_play_url = vod_play_url.join(playList)
  159. vod['vod_play_from'] = vod_play_from
  160. vod['vod_play_url'] = vod_play_url
  161. result = {
  162. 'list':[
  163. vod
  164. ]
  165. }
  166. return result
  167. def searchContent(self,key,quick):
  168. url = 'http://api.tyun77.cn/api.php/provide/searchVideo?searchName={0}'.format(key)
  169. rsp = self.fetch(url,headers=self.header)
  170. jo = json.loads(rsp.text)
  171. vodList = jo['data']
  172. videos = []
  173. for vod in vodList:
  174. videos.append({
  175. "vod_id":vod['id'],
  176. "vod_name":vod['videoName'],
  177. "vod_pic":vod['videoCover'],
  178. "vod_remarks":vod['msg']
  179. })
  180. result = {
  181. 'list':videos
  182. }
  183. return result
  184. config = {
  185. "player": {},
  186. "filter": {}
  187. }
  188. header = {
  189. 'User-Agent': 'okhttp/3.12.0'
  190. }
  191. def playerContent(self,flag,id,vipFlags):
  192. result = {}
  193. result = {
  194. 'parse':0,
  195. 'jx':0,
  196. 'playUrl':'',
  197. 'url':id,
  198. 'header':''
  199. }
  200. if flag != 'ppayun':
  201. result['parse'] = 1
  202. result['jx'] = 1
  203. return result
  204. def isVideoFormat(self,url):
  205. pass
  206. def manualVideoCheck(self):
  207. pass
  208. def get_tk(self, url, params, ts):
  209. keys = []
  210. for key in params:
  211. keys.append(key)
  212. keys.sort()
  213. src = urlparse(url).path
  214. for key in keys:
  215. src += str(params[key])
  216. src += str(ts)
  217. src += 'XSpeUFjJ'
  218. return hashlib.md5(src.encode()).hexdigest()
  219. def localProxy(self,param):
  220. return [200, "video/MP2T", action, ""]