cctv.py 6.1 KB

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