py_yhdm6.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 base64
  9. import re
  10. from urllib import request, parse
  11. import urllib
  12. import urllib.request
  13. import time
  14. class Spider(Spider): # 元类 默认的元类 type
  15. def getName(self):
  16. return "樱花动漫6"#6才是本体
  17. def init(self,extend=""):
  18. print("============{0}============".format(extend))
  19. pass
  20. def isVideoFormat(self,url):
  21. pass
  22. def manualVideoCheck(self):
  23. pass
  24. def homeContent(self,filter):
  25. result = {}
  26. cateManual = {
  27. "日本动漫": "1",
  28. "国产动漫":"4",
  29. "动漫电影":"2",
  30. "欧美动漫":"3"
  31. }
  32. classes = []
  33. for k in cateManual:
  34. classes.append({
  35. 'type_name':k,
  36. 'type_id':cateManual[k]
  37. })
  38. result['class'] = classes
  39. if(filter):
  40. result['filters'] = self.config['filter']
  41. return result
  42. def homeVideoContent(self):
  43. htmlTxt=self.custom_webReadFile(urlStr='https://yhdm6.top/')
  44. videos = self.custom_list(html=htmlTxt,patternTxt=r'<a class="vodlist_thumb lazyload" href="(?P<url>.+?)" title="(?P<title>.+?)" data-original="(?P<img>.+?)".+?><span class=".*?<span class="pic_text text_right">(?P<renew>.+?)</span></a>')
  45. result = {
  46. 'list':videos
  47. }
  48. return result
  49. def categoryContent(self,tid,pg,filter,extend):
  50. result = {}
  51. videos=[]
  52. if 'types' in extend.keys():
  53. if extend['types'].find('全部')<0:
  54. types='class/{0}/'.format(urllib.parse.quote(extend['types']))
  55. letter=''
  56. if 'letter' in extend.keys():
  57. if extend['letter'].find('全部')<0:
  58. letter='letter/{0}/'.format(extend['letter'])
  59. year=''
  60. if 'year' in extend.keys():
  61. if extend['year'].find('全部')<0:
  62. year='/year/{0}'.format(extend['year'])
  63. by=''
  64. if 'by' in extend.keys():
  65. by='by/{0}/'.format(extend['by'])
  66. Url='https://yhdm6.top/index.php/vod/show/{2}{3}id/{0}/{5}{1}{4}.html'.format(tid,'page/'+pg,by,types,year,letter)
  67. #https://yhdm6.top/index.php/vod/show/by/score/class/%E7%A7%91%E5%B9%BB/id/3/letter/W/year/2022.html
  68. htmlTxt=self.custom_webReadFile(urlStr=Url)
  69. videos = self.custom_list(html=htmlTxt,patternTxt=r'<a class="vodlist_thumb lazyload" href="(?P<url>.+?)" title="(?P<title>.+?)" data-original="(?P<img>.+?)"><span class="play hidden_xs"></span><span class="pic_text text_right">(?P<renew>.+?)</span></a>')
  70. result['list'] = videos
  71. result['page'] = pg
  72. result['pagecount'] = pg if len(videos)<60 else int(pg)+1
  73. result['limit'] = 90
  74. result['total'] = 999999
  75. return result
  76. def detailContent(self,array):
  77. aid = array[0].split('###')
  78. idUrl=aid[1]
  79. title=aid[0]
  80. pic=aid[2]
  81. url=idUrl
  82. htmlTxt = self.custom_webReadFile(urlStr=url,codeName='utf-8')
  83. line=self.custom_RegexGetTextLine(Text=htmlTxt,RegexText=r'<a href="javascript:void\(0\);" alt="(.+?)">',Index=1)
  84. if len(line)<1:
  85. return {'list': []}
  86. playFrom = []
  87. videoList=[]
  88. vodItems = []
  89. circuit=self.custom_lineList(Txt=htmlTxt,mark=r'<ul class="content_playlist',after='</ul>')
  90. playFrom=line
  91. for v in circuit:
  92. vodItems = self.custom_EpisodesList(html=v,RegexText=r'<li><a href="(?P<url>.+?)">(?P<title>.+?)</a></li>')
  93. joinStr = "#".join(vodItems)
  94. videoList.append(joinStr)
  95. vod_play_from='$$$'.join(playFrom)
  96. vod_play_url = "$$$".join(videoList)
  97. typeName=self.custom_RegexGetText(Text=htmlTxt,RegexText=r'<a href="/index.php/vod/search/class/.+?" target="_blank">(.+?)</a>',Index=1)
  98. year=self.custom_RegexGetText(Text=htmlTxt,RegexText=r'<a href="/index.php/vod/search/year/\d{4}.html" target="_blank">(\d{4})</a>',Index=1)
  99. area=typeName
  100. act=self.custom_RegexGetText(Text=htmlTxt,RegexText=r'<a href="/index.php/vod/search/actor/.+?.html" target="_blank">(.+?)</a>',Index=1)
  101. temporary=self.custom_RegexGetTextLine(Text=htmlTxt,RegexText=r'<a href="/index.php/vod/search/director/.+?.html" target="_blank">(.+?)</a>',Index=1)
  102. dir='/'.join(temporary)
  103. cont=self.custom_RegexGetText(Text=htmlTxt,RegexText=r'剧情介绍</h2>(.+?)</span>',Index=1)
  104. vod = {
  105. "vod_id": array[0],
  106. "vod_name": title,
  107. "vod_pic": pic,
  108. "type_name":self.custom_removeHtml(txt=typeName),
  109. "vod_year": self.custom_removeHtml(txt=year),
  110. "vod_area": area,
  111. "vod_remarks": '',
  112. "vod_actor": self.custom_removeHtml(txt=act),
  113. "vod_director": self.custom_removeHtml(txt=dir),
  114. "vod_content": self.custom_removeHtml(txt=cont)
  115. }
  116. vod['vod_play_from'] = vod_play_from
  117. vod['vod_play_url'] = vod_play_url
  118. result = {
  119. 'list': [
  120. vod
  121. ]
  122. }
  123. return result
  124. def searchContent(self,key,quick):
  125. url='https://yhdm6.top/index.php/vod/search.html?wd={0}&submit='.format(urllib.parse.quote(key))
  126. htmlTxt=self.custom_webReadFile(urlStr=url)
  127. videos = self.custom_list(html=htmlTxt,patternTxt=r'<a class="vodlist_thumb lazyload" href="(?P<url>.+?)" title="(?P<title>.+?)" data-original="(?P<img>.+?)".+?><span class=".*?<span class="pic_text text_right">(?P<renew>.+?)</span></a>')
  128. result = {
  129. 'list':videos
  130. }
  131. return result
  132. def playerContent(self,flag,id,vipFlags):
  133. result = {}
  134. Url=id
  135. htmlTxt =self.custom_webReadFile(urlStr=Url,codeName='utf-8')
  136. parse=0
  137. UrlStr=''
  138. temporary=self.custom_lineList(Txt=htmlTxt,mark=r'var player_aaaa=',after=r'}</script>')
  139. if len(temporary)==1:
  140. jo=json.loads(temporary[0][16:]+"}")
  141. UrlStr=urllib.parse.unquote(jo['url'])
  142. if UrlStr.find('.m3u8')<2:
  143. Url=id
  144. parse=1
  145. else:
  146. Url=UrlStr
  147. result["parse"] = parse#0=直接播放、1=嗅探
  148. result["playUrl"] =''
  149. result["url"] = Url
  150. # result['jx'] = jx#VIP解析,0=不解析、1=解析
  151. result["header"] = ''
  152. return result
  153. config = {
  154. "player": {},
  155. "filter": {
  156. "1":[
  157. {"key":"types","name":"类型:","value":[{"n":"全部","v":"全部"},{"n":"喜剧","v":"喜剧"},{"n":"爱情","v":"爱情"},{"n":"恐怖","v":"恐怖"},{"n":"动作","v":"动作"},{"n":"科幻","v":"科幻"},{"n":"剧情","v":"剧情"},{"n":"战争","v":"战争"},{"n":"犯罪","v":"犯罪"},{"n":"奇幻","v":"奇幻"},{"n":"冒险","v":"冒险"},{"n":"悬疑","v":"悬疑"},{"n":"惊悚","v":"惊悚"},{"n":"古装","v":"古装"},{"n":"历史","v":"历史"},{"n":"运动","v":"运动"},{"n":"儿童","v":"儿童"}]},
  158. {"key":"year","name":"年份:","value":[{"n":"全部","v":"全部"},{"n":"2023","v":"2023"},{"n":"2022","v":"2022"},{"n":"2021","v":"2021"},{"n":"2020","v":"2020"},{"n":"2019","v":"2019"},{"n":"2018","v":"2018"},{"n":"2017","v":"2017"},{"n":"2016","v":"2016"},{"n":"2015","v":"2015"},{"n":"2014","v":"2014"},{"n":"2013","v":"2013"},{"n":"2012","v":"2012"},{"n":"2011","v":"2011"},{"n":"2010","v":"2010"},{"n":"2009","v":"2009"},{"n":"2008","v":"2008"},{"n":"2007","v":"2007"},{"n":"2006","v":"2006"},{"n":"2005","v":"2005"},{"n":"2004","v":"2004"},{"n":"2003","v":"2003"},{"n":"2002","v":"2002"},{"n":"2001","v":"2001"},{"n":"2000","v":"2000"}]},
  159. {"key":"letter","name":"字母:","value":[{"n":"全部","v":"全部"},{"n":"A","v":"A"},{"n":"B","v":"B"},{"n":"C","v":"C"},{"n":"D","v":"D"},{"n":"E","v":"E"},{"n":"F","v":"F"},{"n":"G","v":"G"},{"n":"H","v":"H"},{"n":"I","v":"I"},{"n":"J","v":"J"},{"n":"K","v":"K"},{"n":"L","v":"L"},{"n":"M","v":"M"},{"n":"N","v":"N"},{"n":"O","v":"O"},{"n":"P","v":"P"},{"n":"Q","v":"Q"},{"n":"R","v":"R"},{"n":"S","v":"S"},{"n":"T","v":"T"},{"n":"U","v":"U"},{"n":"V","v":"V"},{"n":"W","v":"W"},{"n":"X","v":"X"},{"n":"Y","v":"Y"},{"n":"Z","v":"Z"},{"n":"0-9","v":"0-9"}]},
  160. {"key":"by","name":"排序:","value":[{"n":"按最新","v":"time"},{"n":"按最热","v":"按最热"},{"n":"按评分","v":"按评分"}]}
  161. ],
  162. "4":[
  163. {"key":"types","name":"类型:","value":[{"n":"全部","v":"全部"},{"n":"喜剧","v":"喜剧"},{"n":"爱情","v":"爱情"},{"n":"恐怖","v":"恐怖"},{"n":"动作","v":"动作"},{"n":"科幻","v":"科幻"},{"n":"剧情","v":"剧情"},{"n":"战争","v":"战争"},{"n":"犯罪","v":"犯罪"},{"n":"奇幻","v":"奇幻"},{"n":"冒险","v":"冒险"},{"n":"悬疑","v":"悬疑"},{"n":"惊悚","v":"惊悚"},{"n":"古装","v":"古装"},{"n":"历史","v":"历史"},{"n":"运动","v":"运动"},{"n":"儿童","v":"儿童"}]},
  164. {"key":"year","name":"年份:","value":[{"n":"全部","v":"全部"},{"n":"2023","v":"2023"},{"n":"2022","v":"2022"},{"n":"2021","v":"2021"},{"n":"2020","v":"2020"},{"n":"2019","v":"2019"},{"n":"2018","v":"2018"},{"n":"2017","v":"2017"},{"n":"2016","v":"2016"},{"n":"2015","v":"2015"},{"n":"2014","v":"2014"},{"n":"2013","v":"2013"},{"n":"2012","v":"2012"},{"n":"2011","v":"2011"},{"n":"2010","v":"2010"},{"n":"2009","v":"2009"},{"n":"2008","v":"2008"},{"n":"2007","v":"2007"},{"n":"2006","v":"2006"},{"n":"2005","v":"2005"},{"n":"2004","v":"2004"},{"n":"2003","v":"2003"},{"n":"2002","v":"2002"},{"n":"2001","v":"2001"},{"n":"2000","v":"2000"}]},
  165. {"key":"letter","name":"字母:","value":[{"n":"全部","v":"全部"},{"n":"A","v":"A"},{"n":"B","v":"B"},{"n":"C","v":"C"},{"n":"D","v":"D"},{"n":"E","v":"E"},{"n":"F","v":"F"},{"n":"G","v":"G"},{"n":"H","v":"H"},{"n":"I","v":"I"},{"n":"J","v":"J"},{"n":"K","v":"K"},{"n":"L","v":"L"},{"n":"M","v":"M"},{"n":"N","v":"N"},{"n":"O","v":"O"},{"n":"P","v":"P"},{"n":"Q","v":"Q"},{"n":"R","v":"R"},{"n":"S","v":"S"},{"n":"T","v":"T"},{"n":"U","v":"U"},{"n":"V","v":"V"},{"n":"W","v":"W"},{"n":"X","v":"X"},{"n":"Y","v":"Y"},{"n":"Z","v":"Z"},{"n":"0-9","v":"0-9"}]},
  166. {"key":"by","name":"排序:","value":[{"n":"按最新","v":"time"},{"n":"按最热","v":"hits"},{"n":"按评分","v":"score"}]}
  167. ],
  168. "2":[
  169. {"key":"types","name":"类型:","value":[{"n":"全部","v":"全部"},{"n":"喜剧","v":"喜剧"},{"n":"爱情","v":"爱情"},{"n":"恐怖","v":"恐怖"},{"n":"动作","v":"动作"},{"n":"科幻","v":"科幻"},{"n":"剧情","v":"剧情"},{"n":"战争","v":"战争"},{"n":"犯罪","v":"犯罪"},{"n":"奇幻","v":"奇幻"},{"n":"冒险","v":"冒险"},{"n":"悬疑","v":"悬疑"},{"n":"惊悚","v":"惊悚"},{"n":"古装","v":"古装"},{"n":"历史","v":"历史"},{"n":"运动","v":"运动"},{"n":"儿童","v":"儿童"}]},
  170. {"key":"year","name":"年份:","value":[{"n":"全部","v":"全部"},{"n":"2023","v":"2023"},{"n":"2022","v":"2022"},{"n":"2021","v":"2021"},{"n":"2020","v":"2020"},{"n":"2019","v":"2019"},{"n":"2018","v":"2018"},{"n":"2017","v":"2017"},{"n":"2016","v":"2016"},{"n":"2015","v":"2015"},{"n":"2014","v":"2014"},{"n":"2013","v":"2013"},{"n":"2012","v":"2012"},{"n":"2011","v":"2011"},{"n":"2010","v":"2010"},{"n":"2009","v":"2009"},{"n":"2008","v":"2008"},{"n":"2007","v":"2007"},{"n":"2006","v":"2006"},{"n":"2005","v":"2005"},{"n":"2004","v":"2004"},{"n":"2003","v":"2003"},{"n":"2002","v":"2002"},{"n":"2001","v":"2001"},{"n":"2000","v":"2000"}]},
  171. {"key":"letter","name":"字母:","value":[{"n":"全部","v":"全部"},{"n":"A","v":"A"},{"n":"B","v":"B"},{"n":"C","v":"C"},{"n":"D","v":"D"},{"n":"E","v":"E"},{"n":"F","v":"F"},{"n":"G","v":"G"},{"n":"H","v":"H"},{"n":"I","v":"I"},{"n":"J","v":"J"},{"n":"K","v":"K"},{"n":"L","v":"L"},{"n":"M","v":"M"},{"n":"N","v":"N"},{"n":"O","v":"O"},{"n":"P","v":"P"},{"n":"Q","v":"Q"},{"n":"R","v":"R"},{"n":"S","v":"S"},{"n":"T","v":"T"},{"n":"U","v":"U"},{"n":"V","v":"V"},{"n":"W","v":"W"},{"n":"X","v":"X"},{"n":"Y","v":"Y"},{"n":"Z","v":"Z"},{"n":"0-9","v":"0-9"}]},
  172. {"key":"by","name":"排序:","value":[{"n":"按最新","v":"time"},{"n":"按最热","v":"hits"},{"n":"按评分","v":"score"}]}
  173. ],
  174. "3":[
  175. {"key":"types","name":"类型:","value":[{"n":"全部","v":"全部"},{"n":"喜剧","v":"喜剧"},{"n":"爱情","v":"爱情"},{"n":"恐怖","v":"恐怖"},{"n":"动作","v":"动作"},{"n":"科幻","v":"科幻"},{"n":"剧情","v":"剧情"},{"n":"战争","v":"战争"},{"n":"犯罪","v":"犯罪"},{"n":"奇幻","v":"奇幻"},{"n":"冒险","v":"冒险"},{"n":"悬疑","v":"悬疑"},{"n":"惊悚","v":"惊悚"},{"n":"古装","v":"古装"},{"n":"历史","v":"历史"},{"n":"运动","v":"运动"},{"n":"儿童","v":"儿童"}]},
  176. {"key":"year","name":"年份:","value":[{"n":"全部","v":"全部"},{"n":"2023","v":"2023"},{"n":"2022","v":"2022"},{"n":"2021","v":"2021"},{"n":"2020","v":"2020"},{"n":"2019","v":"2019"},{"n":"2018","v":"2018"},{"n":"2017","v":"2017"},{"n":"2016","v":"2016"},{"n":"2015","v":"2015"},{"n":"2014","v":"2014"},{"n":"2013","v":"2013"},{"n":"2012","v":"2012"},{"n":"2011","v":"2011"},{"n":"2010","v":"2010"},{"n":"2009","v":"2009"},{"n":"2008","v":"2008"},{"n":"2007","v":"2007"},{"n":"2006","v":"2006"},{"n":"2005","v":"2005"},{"n":"2004","v":"2004"},{"n":"2003","v":"2003"},{"n":"2002","v":"2002"},{"n":"2001","v":"2001"},{"n":"2000","v":"2000"}]},
  177. {"key":"letter","name":"字母:","value":[{"n":"全部","v":"全部"},{"n":"A","v":"A"},{"n":"B","v":"B"},{"n":"C","v":"C"},{"n":"D","v":"D"},{"n":"E","v":"E"},{"n":"F","v":"F"},{"n":"G","v":"G"},{"n":"H","v":"H"},{"n":"I","v":"I"},{"n":"J","v":"J"},{"n":"K","v":"K"},{"n":"L","v":"L"},{"n":"M","v":"M"},{"n":"N","v":"N"},{"n":"O","v":"O"},{"n":"P","v":"P"},{"n":"Q","v":"Q"},{"n":"R","v":"R"},{"n":"S","v":"S"},{"n":"T","v":"T"},{"n":"U","v":"U"},{"n":"V","v":"V"},{"n":"W","v":"W"},{"n":"X","v":"X"},{"n":"Y","v":"Y"},{"n":"Z","v":"Z"},{"n":"0-9","v":"0-9"}]},
  178. {"key":"by","name":"排序:","value":[{"n":"按最新","v":"time"},{"n":"按最热","v":"hits"},{"n":"按评分","v":"score"}]}
  179. ]
  180. }
  181. }
  182. header = {
  183. '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'
  184. }
  185. def localProxy(self,param):
  186. return [200, "video/MP2T", action, ""]
  187. #-----------------------------------------------自定义函数-----------------------------------------------
  188. #正则取文本
  189. def custom_RegexGetText(self,Text,RegexText,Index):
  190. returnTxt=""
  191. Regex=re.search(RegexText, Text, re.M|re.S)
  192. if Regex is None:
  193. returnTxt=""
  194. else:
  195. returnTxt=Regex.group(Index)
  196. return returnTxt
  197. #分类取结果
  198. def custom_list(self,html,patternTxt):
  199. ListRe=re.finditer(patternTxt, html, re.M|re.S)
  200. videos = []
  201. head="https://yhdm6.top"
  202. for vod in ListRe:
  203. url = vod.group('url')
  204. title =self.custom_removeHtml(txt=vod.group('title'))
  205. img =vod.group('img')
  206. renew=vod.group('renew')
  207. if len(url) == 0:
  208. continue
  209. # print(renew)
  210. videos.append({
  211. "vod_id":"{0}###{1}###{2}".format(title,head+url,img),
  212. "vod_name":title,
  213. "vod_pic":img,
  214. "vod_remarks":renew
  215. })
  216. return videos
  217. #删除html标签
  218. def custom_removeHtml(self,txt):
  219. soup = re.compile(r'<[^>]+>',re.S)
  220. txt =soup.sub('', txt)
  221. return txt.replace("&nbsp;"," ")
  222. #访问网页
  223. def custom_webReadFile(self,urlStr,header=None,codeName='utf-8'):
  224. html=''
  225. if header==None:
  226. header={
  227. "Referer":urlStr,
  228. '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',
  229. "Host":self.custom_RegexGetText(Text=urlStr,RegexText='https*://(.*?)(/|$)',Index=1)
  230. }
  231. # import ssl
  232. # ssl._create_default_https_context = ssl._create_unverified_context#全局取消证书验证
  233. req=urllib.request.Request(url=urlStr,headers=header)#,headers=header
  234. with urllib.request.urlopen(req) as response:
  235. html = response.read().decode(codeName)
  236. return html
  237. #判断是否要调用vip解析
  238. def ifJx(self,urlTxt):
  239. Isjiexi=0
  240. RegexTxt=r'(youku.com|v.qq|bilibili|iqiyi.com)'
  241. if self.get_RegexGetText(Text=urlTxt,RegexText=RegexTxt,Index=1)!='':
  242. Isjiexi=1
  243. return Isjiexi
  244. #取集数
  245. def custom_EpisodesList(self,html,RegexText):
  246. ListRe=re.finditer(RegexText, html, re.M|re.S)
  247. videos = []
  248. head="https://yhdm6.top"
  249. for vod in ListRe:
  250. url = vod.group('url')
  251. title =vod.group('title')
  252. if len(url) == 0:
  253. continue
  254. videos.append(title+"$"+head+url)
  255. return videos
  256. #取剧集区
  257. def custom_lineList(self,Txt,mark,after):
  258. circuit=[]
  259. origin=Txt.find(mark)
  260. while origin>8:
  261. end=Txt.find(after,origin)
  262. circuit.append(Txt[origin:end])
  263. origin=Txt.find(mark,end)
  264. return circuit
  265. #正则取文本,返回数组
  266. def custom_RegexGetTextLine(self,Text,RegexText,Index):
  267. returnTxt=[]
  268. pattern = re.compile(RegexText, re.M|re.S)
  269. ListRe=pattern.findall(Text)
  270. if len(ListRe)<1:
  271. return returnTxt
  272. for value in ListRe:
  273. returnTxt.append(value)
  274. return returnTxt
  275. # T=Spider()
  276. # l=T.searchContent(key='柯南',quick='')
  277. # l=T.homeVideoContent()
  278. # extend={'types':'科幻',"by":"score"}
  279. # l=T.categoryContent(tid='1',pg='1',filter=False,extend=extend)
  280. # for x in l['list']:
  281. # print(x['vod_name'])
  282. # mubiao= '机动警察###https://yhdm6.top/index.php/vod/detail/id/18293.html###https://pic.lzzypic.com/upload/vod/20230825-1/c4b3a6eb89c83879b81e5aa996d5e212.jpg'
  283. # playTabulation=T.detailContent(array=[mubiao,])
  284. # print(playTabulation)
  285. # m3u8=T.playerContent(flag='',id='https://yhdm6.top/index.php/vod/play/id/18293/sid/1/nid/6.html',vipFlags=True)
  286. # print(m3u8)
  287. # print(T.config['filter'])