py_cctv1.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. "健康之路": "TOPC1451557646802924",
  23. "远方的家": "TOPC1451541349400938",
  24. "探索发现": "TOPC1451557893544236",
  25. "地理中国": "TOPC1451557421544786",
  26. "人与自然": "TOPC1451525103989666",
  27. "人文地理": "TOPC1451469288523874",
  28. "全景自然": "TOPC1451469617360656",
  29. "魅力纪录": "TOPC1451465982926341",
  30. "秘境之眼": "TOPC1554187056533820",
  31. "自然": "TOPC1451469660736687",
  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. "家庭幽默大赛": "TOPC1451375222891702",
  62. "综艺盛典": "TOPC1451985071887935",
  63. "环球综艺": "TOPC1571300682556971",
  64. "中国好歌曲": "TOPC1451984949453678",
  65. "外国人在中国": "TOPC1451541113743615",
  66. "华人世界": "TOPC1451539822927345",
  67. "动物传奇": "TOPC1451984181884527",
  68. "美食中国": "TOPC1571034804976375",
  69. "动物世界": "TOPC1451378967257534",
  70. "经典咏流传 第五季":"VIDAIiNbDQzOjE5mLl3T4t2B220403"
  71. }
  72. classes = []
  73. for k in cateManual:
  74. classes.append({
  75. 'type_name':k,
  76. 'type_id':cateManual[k]
  77. })
  78. result['class'] = classes
  79. if(filter):
  80. result['filters'] = self.config['filter']
  81. return result
  82. def homeVideoContent(self):
  83. result = {
  84. 'list':[]
  85. }
  86. return result
  87. def categoryContent(self,tid,pg,filter,extend):
  88. result = {}
  89. extend['id'] = tid
  90. extend['p'] = pg
  91. filterParams = ["id", "p", "d"]
  92. params = ["", "", ""]
  93. for idx in range(len(filterParams)):
  94. fp = filterParams[idx]
  95. if fp in extend.keys():
  96. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  97. suffix = '&'.join(params)
  98. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  99. if not tid.startswith('TOPC'):
  100. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  101. rsp = self.fetch(url,headers=self.header)
  102. jo = json.loads(rsp.text)
  103. vodList = jo['data']['list']
  104. videos = []
  105. for vod in vodList:
  106. guid = vod['guid']
  107. title = vod['title']
  108. img = vod['image']
  109. brief = vod['brief']
  110. videos.append({
  111. "vod_id":guid+"###"+img,
  112. "vod_name":title,
  113. "vod_pic":img,
  114. "vod_remarks":''
  115. })
  116. result['list'] = videos
  117. result['page'] = pg
  118. result['pagecount'] = 9999
  119. result['limit'] = 90
  120. result['total'] = 999999
  121. return result
  122. def detailContent(self,array):
  123. aid = array[0].split('###')
  124. tid = aid[0]
  125. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  126. rsp = self.fetch(url,headers=self.header)
  127. jo = json.loads(rsp.text)
  128. title = jo['title'].strip()
  129. link = jo['hls_url'].strip()
  130. vod = {
  131. "vod_id":tid,
  132. "vod_name":title,
  133. "vod_pic":aid[1],
  134. "type_name":'',
  135. "vod_year":"",
  136. "vod_area":"",
  137. "vod_remarks":"",
  138. "vod_actor":"",
  139. "vod_director":"",
  140. "vod_content":""
  141. }
  142. vod['vod_play_from'] = 'CCTV'
  143. vod['vod_play_url'] = title+"$"+link
  144. result = {
  145. 'list':[
  146. vod
  147. ]
  148. }
  149. return result
  150. def searchContent(self,key,quick):
  151. result = {
  152. 'list':[]
  153. }
  154. return result
  155. def playerContent(self,flag,id,vipFlags):
  156. result = {}
  157. rsp = self.fetch(id,headers=self.header)
  158. content = rsp.text.strip()
  159. arr = content.split('\n')
  160. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  161. url = urlPrefix + arr[-1]
  162. result["parse"] = 0
  163. result["playUrl"] = ''
  164. result["url"] = url
  165. result["header"] = ''
  166. return result
  167. config = {
  168. "player": {},
  169. "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"}]}]}
  170. }
  171. header = {
  172. "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"
  173. }
  174. def localProxy(self,param):
  175. return [200, "video/MP2T", action, ""]