py_cctv.py 6.1 KB

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