栏目.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. class Spider(Spider): # 元类 默认的元类 type
  10. def getName(self):
  11. return "央视大全"
  12. def init(self,extend=""):
  13. print("============{0}============".format(extend))
  14. pass
  15. def isVideoFormat(self,url):
  16. pass
  17. def manualVideoCheck(self):
  18. pass
  19. def homeContent(self,filter):
  20. result = {}
  21. cateManual = {
  22. "央视大全": "CCTV"
  23. }
  24. classes = []
  25. for k in cateManual:
  26. classes.append({
  27. 'type_name':k,
  28. 'type_id':cateManual[k]
  29. })
  30. result['class'] = classes
  31. if(filter):
  32. result['filters'] = self.config['filter']
  33. return result
  34. def homeVideoContent(self):
  35. result = {
  36. 'list':[]
  37. }
  38. return result
  39. def categoryContent(self,tid,pg,filter,extend):
  40. result = {}
  41. month = ""
  42. year = ""
  43. if 'month' in extend.keys():
  44. month = extend['month']
  45. if 'year' in extend.keys():
  46. year = extend['year']
  47. if year == '':
  48. month = ''
  49. prefix = year + month
  50. extend['p'] = pg
  51. filterMap = {
  52. "fl":"",
  53. "fc":"",
  54. "cid":"",
  55. "p":"1"
  56. }
  57. suffix = ""
  58. for key in filterMap.keys():
  59. if key in extend.keys():
  60. filterMap[key] = extend[key]
  61. suffix = suffix + '&' + key + '=' + filterMap[key]
  62. url = 'https://api.cntv.cn/lanmu/columnSearch?{0}&n=20&serviceId=tvcctv&t=json'.format(suffix)
  63. jo = self.fetch(url,headers=self.header).json()
  64. vodList = jo['response']['docs']
  65. videos = []
  66. for vod in vodList:
  67. lastVideo = vod['lastVIDE']['videoSharedCode']
  68. if len(lastVideo) == 0:
  69. lastVideo = '_'
  70. guid = prefix+'###'+vod['column_name']+'###'+lastVideo+'###'+vod['column_logo']
  71. # guid = prefix+'###'+vod['column_website']+'###'+vod['column_logo']
  72. title = vod['column_name']
  73. img = vod['column_logo']
  74. videos.append({
  75. "vod_id":guid,
  76. "vod_name":title,
  77. "vod_pic":img,
  78. "vod_remarks":''
  79. })
  80. result['list'] = videos
  81. result['page'] = pg
  82. result['pagecount'] = 9999
  83. result['limit'] = 90
  84. result['total'] = 999999
  85. return result
  86. def detailContent(self,array):
  87. aid = array[0].split('###')
  88. tid = aid[0]
  89. logo = aid[3]
  90. lastVideo = aid[2]
  91. title = aid[1]
  92. date = aid[0]
  93. if lastVideo == '_':
  94. return {}
  95. lastUrl = 'https://api.cntv.cn/video/videoinfoByGuid?guid={0}&serviceId=tvcctv'.format(lastVideo)
  96. lastJo = self.fetch(lastUrl,headers=self.header).json()
  97. topicId = lastJo['ctid']
  98. url = "https://api.cntv.cn/NewVideo/getVideoListByColumn?id={0}&d={1}&p=1&n=100&sort=desc&mode=0&serviceId=tvcctv&t=json".format(topicId,date)
  99. jo = self.fetch(url,headers=self.header).json()
  100. vodList = jo['data']['list']
  101. videoList = []
  102. for video in vodList:
  103. videoList.append(video['title']+"$"+video['guid'])
  104. if len(videoList) == 0:
  105. return {}
  106. if len(date) == 0:
  107. date = time.strftime("%Y", time.localtime(time.time()))
  108. vod = {
  109. "vod_id":array[0],
  110. "vod_name":date +" "+title,
  111. "vod_pic":logo,
  112. "type_name":lastJo['channel'],
  113. "vod_year":date,
  114. "vod_area":"",
  115. "vod_remarks":date,
  116. "vod_actor":"",
  117. "vod_director":topicId,
  118. "vod_content":"当前页面默认只展示最新100期的内容,可在分类页面选择年份和月份进行往期节目查看。年份和月份仅影响当前页面内容,不参与分类过滤。视频默认播放可以获取到的最高帧率。"
  119. }
  120. vod['vod_play_from'] = 'CCTV'
  121. vod['vod_play_url'] = "#".join(videoList)
  122. result = {
  123. 'list':[
  124. vod
  125. ]
  126. }
  127. return result
  128. # def detailContent(self,array):
  129. # aid = array[0].split('###')
  130. # tid = aid[0]
  131. # logo = aid[2]
  132. # webSite = aid[1]
  133. # date = aid[0]
  134. # rsp = self.fetch(webSite,headers=self.header)
  135. # topicId = ''
  136. # root = self.html(rsp.text)
  137. # topicId = self.regStr(rsp.text,"(TOPC[0-9]{16})")
  138. # title = root.xpath('.//title/text()')[0]
  139. # if len(topicId) <= 0:
  140. # return {}
  141. # url = "https://api.cntv.cn/NewVideo/getVideoListByColumn?id={0}&d={1}&p=1&n=100&sort=desc&mode=0&serviceId=tvcctv&t=json".format(topicId,date)
  142. # jo = self.fetch(url,headers=self.header).json()
  143. # vodList = jo['data']['list']
  144. # videoList = []
  145. # for video in vodList:
  146. # videoList.append(video['title']+"$"+video['guid'])
  147. # if len(videoList) == 0:
  148. # return {}
  149. # if len(date) == 0:
  150. # date = '近期'
  151. # vod = {
  152. # "vod_id":array[0],
  153. # "vod_name":date +" "+title,
  154. # "vod_pic":logo,
  155. # "type_name":'',
  156. # "vod_year":date,
  157. # "vod_area":"",
  158. # "vod_remarks":date,
  159. # "vod_actor":"",
  160. # "vod_director":"",
  161. # "vod_content":"详情页面默认只展示最新100期的内容,可以在分类页面选择年份和月份进行往期节目查看。年份和月份仅影响视频详情内容,不参与分类过滤。视频默认播放最高帧率。"
  162. # }
  163. # vod['vod_play_from'] = 'CCTV'
  164. # vod['vod_play_url'] = "#".join(videoList)
  165. # result = {
  166. # 'list':[
  167. # vod
  168. # ]
  169. # }
  170. # return result
  171. def searchContent(self,key,quick):
  172. result = {
  173. 'list':[]
  174. }
  175. return result
  176. def playerContent(self,flag,id,vipFlags):
  177. result = {}
  178. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(id)
  179. jo = self.fetch(url,headers=self.header).json()
  180. link = jo['hls_url'].strip()
  181. rsp = self.fetch(link,headers=self.header)
  182. content = rsp.text.strip()
  183. arr = content.split('\n')
  184. urlPrefix = self.regStr(link,'(http[s]?://[a-zA-z0-9.]+)/')
  185. subUrl = arr[-1].split('/')
  186. subUrl[3] = '1200'
  187. subUrl[-1] = '1200.m3u8'
  188. hdUrl = urlPrefix + '/'.join(subUrl)
  189. url = urlPrefix + arr[-1]
  190. hdRsp = self.fetch(hdUrl,headers=self.header)
  191. if hdRsp.status_code == 200:
  192. url = hdUrl
  193. result["parse"] = 0
  194. result["playUrl"] = ''
  195. result["url"] = url
  196. result["header"] = ''
  197. return result
  198. config = {
  199. "player": {},
  200. "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"}]}]}
  201. }
  202. header = {
  203. "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",
  204. "Origin": "https://tv.cctv.com",
  205. "Referer": "https://tv.cctv.com/"
  206. }
  207. def localProxy(self,param):
  208. return [200, "video/MP2T", action, ""]