py_1080zyku.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #coding=utf-8
  2. #!/usr/bin/python
  3. import sys
  4. sys.path.append('..')
  5. from base.spider import Spider
  6. import json
  7. import time
  8. import re
  9. from urllib import request, parse
  10. import urllib
  11. import urllib.request
  12. from xml.etree.ElementTree import fromstring, ElementTree as et
  13. class Spider(Spider): # 元类 默认的元类 type
  14. def getName():
  15. return "高清资源"#除去少儿不宜的内容
  16. def init(self,extend=""):
  17. print("============{0}============".format(extend))
  18. pass
  19. def isVideoFormat(self,url):
  20. pass
  21. def manualVideoCheck(self):
  22. pass
  23. def homeContent(self,filter):
  24. result = {}
  25. cateManual ={
  26. '动作片':'5',
  27. '喜剧片':'6',
  28. '爱情片':'7',
  29. '科幻片':'8',
  30. '恐怖片':'9',
  31. '剧情片':'10',
  32. '战争片':'11',
  33. '国产剧':'12',
  34. '台湾剧':'13',
  35. '韩国剧':'14',
  36. '欧美剧':'15',
  37. '香港剧':'16',
  38. '泰国剧':'17',
  39. '日本剧':'18',
  40. '记录片':'20',
  41. '动画片':'41',
  42. '海外剧':'54',
  43. '大陆综艺':'62',
  44. '港台综艺':'63',
  45. '日韩综艺':'64',
  46. '欧美综艺':'65',
  47. '国产动漫':'66',
  48. '日韩动漫':'67',
  49. '欧美动漫':'68',
  50. '港台动漫':'69',
  51. }
  52. classes = []
  53. for k in cateManual:
  54. classes.append({
  55. 'type_name':k,
  56. 'type_id':cateManual[k]
  57. })
  58. result['class'] = classes
  59. if(filter):
  60. result['filters'] = self.config['filter']
  61. return result
  62. def homeVideoContent(self):
  63. xmlTxt=self.custom_webReadFile(urlStr='https://api.1080zyku.com/inc/api.php?ac=list&h=24')
  64. tree = et(fromstring(xmlTxt))
  65. root = tree.getroot()
  66. listXml=root.iter('list')
  67. videos = self.custom_list(html=listXml)
  68. result = {
  69. 'list':videos
  70. }
  71. return result
  72. def categoryContent(self,tid,pg,filter,extend):
  73. result = {}
  74. videos=[]
  75. pagecount=1
  76. limit=20
  77. total=9999
  78. Url='https://api.1080zyku.com/inc/api.php?ac=list&t={0}&pg={1}'.format(tid,pg)
  79. xmlTxt=self.custom_webReadFile(urlStr=Url)
  80. tree = et(fromstring(xmlTxt))
  81. root = tree.getroot()
  82. listXml=root.iter('list')
  83. for vod in listXml:
  84. pagecount=vod.attrib['pagecount']
  85. limit=vod.attrib['pagesize']
  86. total=vod.attrib['recordcount']
  87. videos = self.custom_list(html=root.iter('list'))
  88. result['list'] = videos
  89. result['page'] = pg
  90. result['pagecount'] = pagecount
  91. result['limit'] = limit
  92. result['total'] = total
  93. return result
  94. def detailContent(self,array):
  95. result = {}
  96. aid = array[0].split('###')
  97. id=aid[1]
  98. logo = aid[2]
  99. title = aid[0]
  100. vod_play_from=['1080zyk',]
  101. vod_year=''
  102. vod_actor=''
  103. vod_content=''
  104. vod_director=''
  105. type_name=''
  106. vod_area=''
  107. vod_lang=''
  108. vodItems=[]
  109. vod_play_url=[]
  110. try:
  111. url='https://api.1080zyku.com/inc/apijson.php?ac=detail&ids='+id
  112. xmlTxt=self.custom_webReadFile(urlStr=url)
  113. jRoot = json.loads(xmlTxt)
  114. if jRoot['code']!=1:
  115. return result
  116. jsonList=jRoot['list']
  117. for vod in jsonList:
  118. vodItems=self.custom_EpisodesList(vod['vod_play_url'])
  119. joinStr = "#".join(vodItems)
  120. vod_play_url.append(joinStr)
  121. vod_year=vod['vod_year']
  122. vod_actor=str(vod['vod_actor'])
  123. vod_content=vod['vod_content']
  124. vod_director=str(vod['vod_director'])
  125. type_name=str(vod['type_name'])
  126. vod_area=str(vod['vod_area'])
  127. except :
  128. pass
  129. vod = {
  130. "vod_id":array[0],
  131. "vod_name":title,
  132. "vod_pic":logo,
  133. "type_name":type_name,
  134. "vod_year":vod_year,
  135. "vod_area":vod_area,
  136. "vod_remarks":vod_lang,
  137. "vod_actor":vod_actor,
  138. "vod_director":vod_director,
  139. "vod_content":vod_content
  140. }
  141. vod['vod_play_from'] = "$$$".join(vod_play_from)
  142. vod['vod_play_url'] = "$$$".join(vod_play_url)
  143. result = {
  144. 'list':[
  145. vod
  146. ]
  147. }
  148. if self.custom_RegexGetText(Text=type_name,RegexText=r'(伦理|倫理|福利)',Index=1)!='':
  149. result={'list':[]}
  150. return result
  151. def searchContent(self,key,quick):
  152. Url='https://api.1080zyku.com/inc/api.php?ac=list&wd={0}&pg={1}'.format(urllib.parse.quote(key),'1')
  153. xmlTxt=self.custom_webReadFile(urlStr=Url)
  154. tree = et(fromstring(xmlTxt))
  155. root = tree.getroot()
  156. listXml=root.iter('list')
  157. videos = self.custom_list(html=listXml)
  158. result = {
  159. 'list':videos
  160. }
  161. return result
  162. def playerContent(self,flag,id,vipFlags):
  163. result = {}
  164. result["parse"] = 0#0=直接播放、1=嗅探
  165. result["playUrl"] =''
  166. result["url"] = id
  167. result['jx'] = 0#VIP解析,0=不解析、1=解析
  168. result["header"] = ''
  169. return result
  170. config = {
  171. "player": {},
  172. "filter": {}
  173. }
  174. header = {}
  175. def localProxy(self,param):
  176. return [200, "video/MP2T", action, ""]
  177. #-----------------------------------------------自定义函数-----------------------------------------------
  178. #正则取文本
  179. def custom_RegexGetText(self,Text,RegexText,Index):
  180. returnTxt=""
  181. Regex=re.search(RegexText, Text, re.M|re.S)
  182. if Regex is None:
  183. returnTxt=""
  184. else:
  185. returnTxt=Regex.group(Index)
  186. return returnTxt
  187. #分类取结果
  188. def custom_list(self,html):
  189. ListRe=html
  190. videos = []
  191. temporary=[]
  192. for vod in ListRe:
  193. for value in vod:
  194. for x in value:
  195. if x.tag=='name':
  196. title=x.text
  197. if x.tag=='id':
  198. id=x.text
  199. if x.tag=='type':
  200. tid=x.text
  201. if x.tag=='last':
  202. last=x.text
  203. temporary.append({
  204. "name":title,
  205. "id":id,
  206. "last":last
  207. })
  208. if len(temporary)>0:
  209. idTxt=''
  210. for vod in temporary:
  211. idTxt=idTxt+vod['id']+','
  212. if len(idTxt)>1:
  213. idTxt=idTxt[0:-1]
  214. url='https://api.1080zyku.com/inc/apijson.php?ac=detail&ids='+idTxt
  215. xmlTxt=self.custom_webReadFile(urlStr=url)
  216. jRoot = json.loads(xmlTxt)
  217. if jRoot['code']!=1:
  218. return videos
  219. jsonList=jRoot['list']
  220. for vod in jsonList:
  221. title=vod['vod_name']
  222. vod_id=vod['vod_id']
  223. img=vod['vod_pic']
  224. remarks=vod['vod_remarks']
  225. type_name=vod['type_name']
  226. vod_year=vod['vod_year']
  227. if self.custom_RegexGetText(Text=type_name,RegexText=r'(伦理|倫理|福利)',Index=1)!='':
  228. continue
  229. vod_id='{0}###{1}###{2}'.format(title,vod_id,img)
  230. # vod_id='{0}###{1}###{2}###{3}###{4}###{5}###{6}###{7}###{8}###{9}###{10}'.format(title,vod_id,img,vod_actor,vod_director,'/'.join(type_name),'/'.join(vod_time),'/'.join(vod_area),vod_lang,vod_content,vod_play_url)
  231. # print(vod_id)
  232. videos.append({
  233. "vod_id":vod_id,
  234. "vod_name":title,
  235. "vod_pic":img,
  236. "vod_year":vod_year,
  237. "vod_remarks":remarks
  238. })
  239. return videos
  240. #访问网页
  241. def custom_webReadFile(self,urlStr,header=None,codeName='utf-8'):
  242. html=''
  243. if header==None:
  244. header={
  245. "Referer":urlStr,
  246. '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',
  247. "Host":self.custom_RegexGetText(Text=urlStr,RegexText='https*://(.*?)(/|$)',Index=1)
  248. }
  249. # import ssl
  250. # ssl._create_default_https_context = ssl._create_unverified_context#全局取消证书验证
  251. req=urllib.request.Request(url=urlStr,headers=header)#,headers=header
  252. with urllib.request.urlopen(req) as response:
  253. html = response.read().decode(codeName)
  254. return html
  255. #取剧集区
  256. def custom_lineList(self,Txt,mark,after):
  257. circuit=[]
  258. origin=Txt.find(mark)
  259. while origin>8:
  260. end=Txt.find(after,origin)
  261. circuit.append(Txt[origin:end])
  262. origin=Txt.find(mark,end)
  263. return circuit
  264. #正则取文本,返回数组
  265. def custom_RegexGetTextLine(self,Text,RegexText,Index):
  266. returnTxt=[]
  267. pattern = re.compile(RegexText, re.M|re.S)
  268. ListRe=pattern.findall(Text)
  269. if len(ListRe)<1:
  270. return returnTxt
  271. for value in ListRe:
  272. returnTxt.append(value)
  273. return returnTxt
  274. #取集数
  275. def custom_EpisodesList(self,html):
  276. ListRe=html.split('#')
  277. videos = []
  278. for vod in ListRe:
  279. t= vod.split('$')
  280. url =t[1]
  281. title =t[0]
  282. if len(url) == 0:
  283. continue
  284. videos.append(title+"$"+url)
  285. return videos
  286. #取分类
  287. def custom_classification(self):
  288. xmlTxt=self.custom_webReadFile(urlStr='https://api.1080zyku.com/inc/api.php?ac=list')
  289. tree = et(fromstring(xmlTxt))
  290. root = tree.getroot()
  291. classXml=root.iter('class')
  292. temporaryClass={}
  293. for vod in classXml:
  294. for value in vod:
  295. if self.custom_RegexGetText(Text=value.text,RegexText=r'(福利|倫理片|伦理片)',Index=1)!='':
  296. continue
  297. temporaryClass[value.text]=value.attrib['id']
  298. print("'{0}':'{1}',".format(value.text,value.attrib['id']))
  299. return temporaryClass
  300. # T=Spider()
  301. # l=T.homeVideoContent()
  302. # # l=T.searchContent(key='柯南',quick='')
  303. # # l=T.categoryContent(tid='12',pg='1',filter=False,extend={})
  304. # for x in l['list']:
  305. # print(x['vod_name'])
  306. # mubiao= l['list'][1]['vod_id']
  307. # print(mubiao)
  308. # playTabulation=T.detailContent(array=[mubiao,])
  309. # print(playTabulation)