py_cctvxw.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. "华人世界":"TOPC1451539822927345",
  23. "海峡两岸":"TOPC1451540328102649",
  24. "今日关注":"TOPC1451540389082713",
  25. "中国新闻":"TOPC1451539894330405",
  26. "今日亚洲":"TOPC1451540448405749",
  27. "朝闻天下":"TOPC1451558496100826",
  28. "新闻直播间":"TOPC1451559129520755",
  29. "新闻30分":"TOPC1451559097947700",
  30. "共同关注":"TOPC1451558858788377",
  31. "东方时空":"TOPC1451558532019883",
  32. "新闻1+1":"TOPC1451559066181661",
  33. "今日环球":"TOPC1571034705435323",
  34. "华人故事":"TOPC1571646754621556",
  35. "鲁健访谈":"TOPC1609904361007481",
  36. "深度国际":"TOPC1451540709098112",
  37. "国际时讯":"TOPC1451558887804404",
  38. "环球视线":"TOPC1451558926200436",
  39. "24小时":"TOPC1451558428005729",
  40. "午夜新闻":"TOPC1451558779639282",
  41. "新闻调查":"TOPC1451558819463311",
  42. "新闻周刊":"TOPC1451559180488841",
  43. "世界周刊":"TOPC1451558687534149",
  44. "面对面":"TOPC1451559038345600",
  45. "每周质量报告":"TOPC1451558650605123",
  46. "华人世界":"TOPC1451539822927345"
  47. }
  48. classes = []
  49. for k in cateManual:
  50. classes.append({
  51. 'type_name':k,
  52. 'type_id':cateManual[k]
  53. })
  54. result['class'] = classes
  55. if(filter):
  56. result['filters'] = self.config['filter']
  57. return result
  58. def homeVideoContent(self):
  59. result = {
  60. 'list':[]
  61. }
  62. return result
  63. def categoryContent(self,tid,pg,filter,extend):
  64. result = {}
  65. extend['id'] = tid
  66. extend['p'] = pg
  67. filterParams = ["id", "p", "d"]
  68. params = ["", "", ""]
  69. for idx in range(len(filterParams)):
  70. fp = filterParams[idx]
  71. if fp in extend.keys():
  72. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  73. suffix = '&'.join(params)
  74. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  75. if not tid.startswith('TOPC'):
  76. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  77. rsp = self.fetch(url,headers=self.header)
  78. jo = json.loads(rsp.text)
  79. vodList = jo['data']['list']
  80. videos = []
  81. for vod in vodList:
  82. guid = vod['guid']
  83. title = vod['title']
  84. img = vod['image']
  85. brief = vod['brief']
  86. videos.append({
  87. "vod_id":guid+"###"+img,
  88. "vod_name":title,
  89. "vod_pic":img,
  90. "vod_remarks":''
  91. })
  92. result['list'] = videos
  93. result['page'] = pg
  94. result['pagecount'] = 9999
  95. result['limit'] = 90
  96. result['total'] = 999999
  97. return result
  98. def detailContent(self,array):
  99. aid = array[0].split('###')
  100. tid = aid[0]
  101. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  102. rsp = self.fetch(url,headers=self.header)
  103. jo = json.loads(rsp.text)
  104. title = jo['title'].strip()
  105. link = jo['hls_url'].strip()
  106. vod = {
  107. "vod_id":tid,
  108. "vod_name":title,
  109. "vod_pic":aid[1],
  110. "type_name":'',
  111. "vod_year":"",
  112. "vod_area":"",
  113. "vod_remarks":"",
  114. "vod_actor":"",
  115. "vod_director":"",
  116. "vod_content":""
  117. }
  118. vod['vod_play_from'] = 'CCTV'
  119. vod['vod_play_url'] = title+"$"+link
  120. result = {
  121. 'list':[
  122. vod
  123. ]
  124. }
  125. return result
  126. def searchContent(self,key,quick):
  127. result = {
  128. 'list':[]
  129. }
  130. return result
  131. def playerContent(self,flag,id,vipFlags):
  132. result = {}
  133. rsp = self.fetch(id,headers=self.header)
  134. content = rsp.text.strip()
  135. arr = content.split('\n')
  136. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  137. url = urlPrefix + arr[-1]
  138. result["parse"] = 0
  139. result["playUrl"] = ''
  140. result["url"] = url
  141. result["header"] = ''
  142. return result
  143. config = {
  144. "player": {},
  145. "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"}]}]}
  146. }
  147. header = {
  148. "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"
  149. }
  150. def localProxy(self,param):
  151. return [200, "video/MP2T", action, ""]