py_cctv.json 7.1 KB

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