cctv.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. "等着我": "TOPC1451378757637200",
  23. "我爱发明": "TOPC1569314345479107",
  24. "动物世界": "TOPC1451378967257534",
  25. "我爱发明2021": "TOPC1451557970755294",
  26. "自然传奇": "TOPC1451558150787467",
  27. "探索发现": "TOPC1451557893544236",
  28. "地理中国": "TOPC1451557421544786",
  29. "人与自然": "TOPC1451525103989666",
  30. "远方的家": "TOPC1451541349400938",
  31. "动画大放映": "TOPC1451559025546574",
  32. "新闻联播": "TOPC1451528971114112",
  33. "焦点访谈": "TOPC1451558976694518",
  34. "海峡两岸": "TOPC1451540328102649",
  35. "今日关注": "TOPC1451540389082713",
  36. "今日亚洲": "TOPC1451540448405749",
  37. "防务新观察": "TOPC1451526164984187",
  38. "共同关注": "TOPC1451558858788377",
  39. "深度国际": "TOPC1451540709098112",
  40. "环宇视野": "TOPC1451469241240836",
  41. "环球视线": "TOPC1451558926200436",
  42. "世界周刊": "TOPC1451558687534149",
  43. "东方时空": "TOPC1451558532019883",
  44. "新闻调查": "TOPC1451558819463311",
  45. "环球科技视野": "TOPC1451463780801881",
  46. "讲武堂": "TOPC1451526241359341",
  47. "国宝发现": "TOPC1571034869935436",
  48. "国宝档案": "TOPC1451540268188575",
  49. "天下财经": "TOPC1451531385787654",
  50. "走进科学": "TOPC1451558190239536",
  51. "解码科技史": "TOPC1570876640457386",
  52. "法律讲堂": "TOPC1451542824484472",
  53. "百家讲坛": "TOPC1451557052519584",
  54. "名家书场": "TOPC1579401761622774",
  55. "星光大道": "TOPC1451467630488780",
  56. "非常6+1": "TOPC1451467940101208",
  57. "中国节拍": "TOPC1570025984977611",
  58. "一鸣惊人": "TOPC1451558692971175",
  59. "金牌喜剧班": "TOPC1611826337610628",
  60. "九州大戏台": "TOPC1451558399948678",
  61. "乡村大舞台": "TOPC1563179546003162",
  62. "家庭幽默大赛": "TOPC1451375222891702",
  63. "综艺盛典": "TOPC1451985071887935",
  64. "环球综艺": "TOPC1571300682556971",
  65. "中国好歌曲": "TOPC1451984949453678",
  66. "广场舞金曲": "TOPC1528685010104859",
  67. "曲苑杂谈": "TOPC1451984417763860",
  68. "锦绣梨园": "TOPC1451558363250650",
  69. "梨园周刊": "TOPC1574909786070351",
  70. "外国人在中国": "TOPC1451541113743615",
  71. "华人世界": "TOPC1451539822927345",
  72. "武林大会": "TOPC1451551891055866",
  73. "棋牌乐": "TOPC1451550531682936",
  74. "动物传奇": "TOPC1451984181884527",
  75. "美食中国": "TOPC1571034804976375",
  76. "田间示范秀": "TOPC1563178908227191",
  77. "三农群英会": "TOPC1600745974233265",
  78. "乡村振兴面对面": "TOPC1568966531726705",
  79. "超级新农人": "TOPC1597627647957699",
  80. "印象乡村": "TOPC1563178734372977" }
  81. classes = []
  82. for k in cateManual:
  83. classes.append({
  84. 'type_name':k,
  85. 'type_id':cateManual[k]
  86. })
  87. result['class'] = classes
  88. if(filter):
  89. result['filters'] = self.config['filter']
  90. return result
  91. def homeVideoContent(self):
  92. result = {
  93. 'list':[]
  94. }
  95. return result
  96. def categoryContent(self,tid,pg,filter,extend):
  97. result = {}
  98. extend['id'] = tid
  99. extend['p'] = pg
  100. filterParams = ["id", "p", "d"]
  101. params = ["", "", ""]
  102. for idx in range(len(filterParams)):
  103. fp = filterParams[idx]
  104. if fp in extend.keys():
  105. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  106. suffix = '&'.join(params)
  107. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  108. if not tid.startswith('TOPC'):
  109. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  110. rsp = self.fetch(url,headers=self.header)
  111. jo = json.loads(rsp.text)
  112. vodList = jo['data']['list']
  113. videos = []
  114. for vod in vodList:
  115. guid = vod['guid']
  116. title = vod['title']
  117. img = vod['image']
  118. brief = vod['brief']
  119. videos.append({
  120. "vod_id":guid+"###"+img,
  121. "vod_name":title,
  122. "vod_pic":img,
  123. "vod_remarks":''
  124. })
  125. result['list'] = videos
  126. result['page'] = pg
  127. result['pagecount'] = 9999
  128. result['limit'] = 90
  129. result['total'] = 999999
  130. return result
  131. def detailContent(self,array):
  132. aid = array[0].split('###')
  133. tid = aid[0]
  134. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  135. rsp = self.fetch(url,headers=self.header)
  136. jo = json.loads(rsp.text)
  137. title = jo['title'].strip()
  138. link = jo['hls_url'].strip()
  139. vod = {
  140. "vod_id":tid,
  141. "vod_name":title,
  142. "vod_pic":aid[1],
  143. "type_name":'',
  144. "vod_year":"",
  145. "vod_area":"",
  146. "vod_remarks":"",
  147. "vod_actor":"",
  148. "vod_director":"",
  149. "vod_content":""
  150. }
  151. vod['vod_play_from'] = 'CCTV'
  152. vod['vod_play_url'] = title+"$"+link
  153. result = {
  154. 'list':[
  155. vod
  156. ]
  157. }
  158. return result
  159. def searchContent(self,key,quick):
  160. result = {
  161. 'list':[]
  162. }
  163. return result
  164. def playerContent(self,flag,id,vipFlags):
  165. result = {}
  166. rsp = self.fetch(id,headers=self.header)
  167. content = rsp.text.strip()
  168. arr = content.split('\n')
  169. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  170. url = urlPrefix + arr[-1]
  171. result["parse"] = 0
  172. result["playUrl"] = ''
  173. result["url"] = url
  174. result["header"] = ''
  175. return result
  176. config = {
  177. "player": {},
  178. "filter": {"TOPC1451557970755294": [{"key": "d", "name": "年份", "value": [{"n": "全部", "v": ""}, {"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"}]}]}
  179. }
  180. header = {
  181. "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"
  182. }
  183. def localProxy(self,param):
  184. return [200, "video/MP2T", action, ""]