py_央视少儿.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. class Spider(Spider): # 元类 默认的元类 type
  11. def getName(self):
  12. return "央视片库"
  13. def init(self,extend=""):
  14. print("============{0}============".format(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. "动画片": "动画片",
  24. #"特别节目": "特别节目"
  25. }
  26. classes = []
  27. for k in cateManual:
  28. classes.append({
  29. 'type_name':k,
  30. 'type_id':cateManual[k]
  31. })
  32. result['class'] = classes
  33. if(filter):
  34. result['filters'] = self.config['filter']
  35. return result
  36. def homeVideoContent(self):
  37. result = {
  38. 'list':[]
  39. }
  40. return result
  41. def categoryContent(self,tid,pg,filter,extend):
  42. result = {}
  43. month = ""
  44. year = ""
  45. if 'month' in extend.keys():
  46. month = extend['month']
  47. if 'year' in extend.keys():
  48. year = extend['year']
  49. if year == '':
  50. month = ''
  51. prefix = year + month
  52. url="https://api.cntv.cn/list/getVideoAlbumList?channelid=CHAL1460955899450127&area=&sc=&fc=%E5%8A%A8%E7%94%BB%E7%89%87&letter=&p={0}&n=24&serviceId=tvcctv&topv=1&t=json"
  53. if tid=="电视剧":
  54. url="https://api.cntv.cn/list/getVideoAlbumList?channelid=CHAL1460955853485115&area=&sc=&fc=%E7%94%B5%E8%A7%86%E5%89%A7&year=&letter=&p={0}&n=24&serviceId=tvcctv&topv=1&t=json"
  55. elif tid=="纪录片":
  56. url="https://api.cntv.cn/list/getVideoAlbumList?channelid=CHAL1460955924871139&fc=%E7%BA%AA%E5%BD%95%E7%89%87&channel=&sc=&year=&letter=&p={0}&n=24&serviceId=tvcctv&topv=1&t=json"
  57. elif tid=="4":
  58. url="https://api.cntv.cn/list/getVideoAlbumList?channelid=CHAL1460955953877151&channel=&sc=&fc=%E7%89%B9%E5%88%AB%E8%8A%82%E7%9B%AE&bigday=&letter=&p={0}&n=24&serviceId=tvcctv&topv=1&t=json"
  59. suffix = ""
  60. jo = self.fetch(url.format(pg),headers=self.header).json()
  61. vodList=jo["data"]["list"]
  62. videos = []
  63. for vod in vodList:
  64. lastVideo =vod['url']
  65. brief=vod['brief']
  66. if len(brief) == 0:
  67. brief = ' '
  68. if len(lastVideo) == 0:
  69. lastVideo = '_'
  70. guid = tid+'###'+vod["title"]+'###'+lastVideo+'###'+vod['image']+'###'+brief
  71. title = vod["title"]
  72. img = vod['image']
  73. videos.append({
  74. "vod_id":guid,
  75. "vod_name":title,
  76. "vod_pic":img,
  77. "vod_remarks":''
  78. })
  79. result['list'] = videos
  80. result['page'] = pg
  81. result['pagecount'] = 9999
  82. result['limit'] = 90
  83. result['total'] = 999999
  84. return result
  85. def detailContent(self,array):
  86. aid = array[0].split('###')
  87. if aid[2].find("http")<0:
  88. return {}
  89. tid = aid[0]
  90. logo = aid[3]
  91. lastVideo = aid[2]
  92. title = aid[1]
  93. date = aid[0]
  94. if lastVideo == '_':
  95. return {}
  96. rsp = self.fetch(lastVideo)
  97. htmlTxt=rsp.text
  98. column_id = ""
  99. videoList = []
  100. patternTxt=r"'title':\s*'(.+?)',\n{0,1}\s*'img':\s*'(.+?)',\n{0,1}\s*'brief':\s*'(.+?)',\n{0,1}\s*'url':\s*'(.+?)'"
  101. titleIndex=0
  102. UrlIndex=3
  103. if tid=="电视剧" or tid=="纪录片":
  104. patternTxt=r"'title':\s*'(.+?)',\n{0,1}\s*'brief':\s*'(.+?)',\n{0,1}\s*'img':\s*'(.+?)',\n{0,1}\s*'url':\s*'(.+?)'"
  105. titleIndex=0
  106. UrlIndex=3
  107. elif tid=="特别节目":
  108. patternTxt=r'class="tp1"><a\s*href="(https://.+?)"\s*target="_blank"\s*title="(.+?)"></a></div>'
  109. titleIndex=1
  110. UrlIndex=0
  111. #https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?id=VIDA3YcIusJ9mh4c9mw5XHyx230113&serviceId=tvcctv//由于方式不同暂时不做
  112. pattern = re.compile(patternTxt)
  113. ListRe=pattern.findall(htmlTxt)
  114. for value in ListRe:
  115. videoList.append(value[titleIndex]+"$"+value[UrlIndex])
  116. if len(videoList) == 0:
  117. return {}
  118. vod = {
  119. "vod_id":array[0],
  120. "vod_name":title,
  121. "vod_pic":logo,
  122. "type_name":tid,
  123. "vod_year":date,
  124. "vod_area":"",
  125. "vod_remarks":date,
  126. "vod_actor":"",
  127. "vod_director":column_id,
  128. "vod_content":aid[4]
  129. }
  130. vod['vod_play_from'] = '🌸荷城茶秀接口🌸CCTV频道'
  131. vod['vod_play_url'] = "#".join(videoList)
  132. result = {
  133. 'list':[
  134. vod
  135. ]
  136. }
  137. return result
  138. def searchContent(self,key,quick):
  139. result = {
  140. 'list':[]
  141. }
  142. return result
  143. def playerContent(self,flag,id,vipFlags):
  144. result = {}
  145. rsp = self.fetch(id)
  146. htmlTxt=rsp.text
  147. pattern = re.compile(r'var\sguid\s*=\s*"(.+?)";')
  148. ListRe=pattern.findall(htmlTxt)
  149. if ListRe==[]:
  150. return result
  151. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(ListRe[0])
  152. jo = self.fetch(url,headers=self.header).json()
  153. link = jo['hls_url'].strip()
  154. rsp = self.fetch(link,headers=self.header)
  155. content = rsp.text.strip()
  156. arr = content.split('\n')
  157. urlPrefix = self.regStr(link,'(http[s]?://[a-zA-z0-9.]+)/')
  158. subUrl = arr[-1].split('/')
  159. subUrl[3] = '1200'
  160. subUrl[-1] = '1200.m3u8'
  161. hdUrl = urlPrefix + '/'.join(subUrl)
  162. url = urlPrefix + arr[-1]
  163. hdRsp = self.fetch(hdUrl,headers=self.header)
  164. if hdRsp.status_code == 200:
  165. url = hdUrl
  166. result["parse"] = 0
  167. result["playUrl"] = ''
  168. result["url"] = url
  169. result["header"] = ''
  170. return result
  171. config = {
  172. "player": {},
  173. "filter": {"CCTV":[{"key":"cid","name":"频道","value":[{"n":"全部","v":""},{"n":"CCTV-1综合","v":"EPGC1386744804340101"},{"n":"CCTV-2财经","v":"EPGC1386744804340102"},{"n":"CCTV-3综艺","v":"EPGC1386744804340103"},{"n":"CCTV-4中文国际","v":"EPGC1386744804340104"},{"n":"CCTV-5体育","v":"EPGC1386744804340107"},{"n":"CCTV-6电影","v":"EPGC1386744804340108"},{"n":"CCTV-7国防军事","v":"EPGC1386744804340109"},{"n":"CCTV-8电视剧","v":"EPGC1386744804340110"},{"n":"CCTV-9纪录","v":"EPGC1386744804340112"},{"n":"CCTV-10科教","v":"EPGC1386744804340113"},{"n":"CCTV-11戏曲","v":"EPGC1386744804340114"},{"n":"CCTV-12社会与法","v":"EPGC1386744804340115"},{"n":"CCTV-13新闻","v":"EPGC1386744804340116"},{"n":"CCTV-14少儿","v":"EPGC1386744804340117"},{"n":"CCTV-15音乐","v":"EPGC1386744804340118"},{"n":"CCTV-16奥林匹克","v":"EPGC1634630207058998"},{"n":"CCTV-17农业农村","v":"EPGC1563932742616872"},{"n":"CCTV-5+体育赛事","v":"EPGC1468294755566101"}]},{"key":"fc","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":"影视"}]},{"key":"fl","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"}]},{"key":"year","name":"年份","value":[{"n":"全部","v":""},{"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"}]},{"key":"month","name":"月份","value":[{"n":"全部","v":""},{"n":"12","v":"12"},{"n":"11","v":"11"},{"n":"10","v":"10"},{"n":"09","v":"09"},{"n":"08","v":"08"},{"n":"07","v":"07"},{"n":"06","v":"06"},{"n":"05","v":"05"},{"n":"04","v":"04"},{"n":"03","v":"03"},{"n":"02","v":"02"},{"n":"01","v":"01"}]}]}
  174. }
  175. header = {
  176. "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",
  177. "Origin": "https://tv.cctv.com",
  178. "Referer": "https://tv.cctv.com/"
  179. }
  180. def localProxy(self,param):
  181. return [200, "video/MP2T", action, ""]