py_cctvkj.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. "天涯共此时":"TOPC1451540858793305",
  23. "国宝档案":"TOPC1451540268188575",
  24. "外国人在中国":"TOPC1451541113743615",
  25. "文明之旅":"TOPC1451541205513705",
  26. "记住乡愁第六季":"TOPC1577672009520911",
  27. "跟着书本去旅行":"TOPC1575253587571324",
  28. "百家讲坛":"TOPC1451557052519584",
  29. "自然传奇":"TOPC1451558150787467",
  30. "探索·发现":"TOPC1451557893544236",
  31. "地理·中国":"TOPC1451557421544786",
  32. "动物世界":"TOPC1451378967257534",
  33. "人与自然":"TOPC1451525103989666",
  34. "中华民族":"TOPC1451525460925648",
  35. "国家记忆":"TOPC1473235107169415",
  36. "国宝·发现":"TOPC1571034869935436",
  37. "记住乡愁第七季":"TOPC1608533695279753",
  38. "时尚科技秀":"TOPC1570874587435537",
  39. "读书":"TOPC1451557523542854",
  40. "创新进行时":"TOPC1570875218228998",
  41. "解码科技史":"TOPC1570876640457386",
  42. "科学动物园":"TOPC1571021385508957",
  43. "考古公开课":"TOPC1571021251454875",
  44. "科幻地带":"TOPC1571021323137369",
  45. "实验现场":"TOPC1571021159595290",
  46. "人物·故事":"TOPC1570780618796536",
  47. "百家说故事":"TOPC1574995326079121",
  48. "透视新科技":"TOPC1576631973420833",
  49. "夕阳红":"TOPC1451543312252987",
  50. "心理访谈":"TOPC1451543382680164",
  51. "夜线":"TOPC1451543426689237",
  52. "我爱发明":"TOPC1569314345479107",
  53. "环球科技视野":"TOPC1451463780801881",
  54. "状元360":"TOPC1451528493821255",
  55. "1起聊聊":"TOPC1451374975347585",
  56. "秘境之眼":"TOPC1554187056533820",
  57. "文化视点":"TOPC1451536118642783",
  58. "文化正午":"TOPC1451538455169283",
  59. "文化大百科":"TOPC1451536035602751",
  60. "动物传奇":"TOPC1451984181884527",
  61. "文化讲坛":"TOPC1451984533334125",
  62. "流行无限":"TOPC1451540644606949",
  63. "天涯共此时":"TOPC1451540858793305",
  64. "国宝档案":"TOPC1451540268188575",
  65. "外国人在中国":"TOPC1451541113743615",
  66. "文明之旅":"TOPC1451541205513705",
  67. "记住乡愁第六季":"TOPC1577672009520911",
  68. "中国影像方志":"TOPC1592552941644815",
  69. "创新无限":"TOPC1451557109280614",
  70. "科技人生":"TOPC1451557739596986",
  71. "绿色空间":"TOPC1451557825546179",
  72. "重访":"TOPC1451558118808439",
  73. "走近科学":"TOPC1451558190239536",
  74. "原来如此":"TOPC1451558088858410",
  75. "科技之光":"TOPC1451557776198149",
  76. "文明密码":"TOPC1451557930785264",
  77. "真相":"TOPC1503545711557359",
  78. "大家":"TOPC1451557371520714",
  79. "讲述":"TOPC1451557691081955",
  80. "人物":"TOPC1451557861628208",
  81. "我爱发明(科普)":"TOPC1451557970755294"
  82. }
  83. classes = []
  84. for k in cateManual:
  85. classes.append({
  86. 'type_name':k,
  87. 'type_id':cateManual[k]
  88. })
  89. result['class'] = classes
  90. if(filter):
  91. result['filters'] = self.config['filter']
  92. return result
  93. def homeVideoContent(self):
  94. result = {
  95. 'list':[]
  96. }
  97. return result
  98. def categoryContent(self,tid,pg,filter,extend):
  99. result = {}
  100. extend['id'] = tid
  101. extend['p'] = pg
  102. filterParams = ["id", "p", "d"]
  103. params = ["", "", ""]
  104. for idx in range(len(filterParams)):
  105. fp = filterParams[idx]
  106. if fp in extend.keys():
  107. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  108. suffix = '&'.join(params)
  109. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  110. if not tid.startswith('TOPC'):
  111. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  112. rsp = self.fetch(url,headers=self.header)
  113. jo = json.loads(rsp.text)
  114. vodList = jo['data']['list']
  115. videos = []
  116. for vod in vodList:
  117. guid = vod['guid']
  118. title = vod['title']
  119. img = vod['image']
  120. brief = vod['brief']
  121. videos.append({
  122. "vod_id":guid+"###"+img,
  123. "vod_name":title,
  124. "vod_pic":img,
  125. "vod_remarks":''
  126. })
  127. result['list'] = videos
  128. result['page'] = pg
  129. result['pagecount'] = 9999
  130. result['limit'] = 90
  131. result['total'] = 999999
  132. return result
  133. def detailContent(self,array):
  134. aid = array[0].split('###')
  135. tid = aid[0]
  136. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  137. rsp = self.fetch(url,headers=self.header)
  138. jo = json.loads(rsp.text)
  139. title = jo['title'].strip()
  140. link = jo['hls_url'].strip()
  141. vod = {
  142. "vod_id":tid,
  143. "vod_name":title,
  144. "vod_pic":aid[1],
  145. "type_name":'',
  146. "vod_year":"",
  147. "vod_area":"",
  148. "vod_remarks":"",
  149. "vod_actor":"",
  150. "vod_director":"",
  151. "vod_content":""
  152. }
  153. vod['vod_play_from'] = 'CCTV'
  154. vod['vod_play_url'] = title+"$"+link
  155. result = {
  156. 'list':[
  157. vod
  158. ]
  159. }
  160. return result
  161. def searchContent(self,key,quick):
  162. result = {
  163. 'list':[]
  164. }
  165. return result
  166. def playerContent(self,flag,id,vipFlags):
  167. result = {}
  168. rsp = self.fetch(id,headers=self.header)
  169. content = rsp.text.strip()
  170. arr = content.split('\n')
  171. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  172. url = urlPrefix + arr[-1]
  173. result["parse"] = 0
  174. result["playUrl"] = ''
  175. result["url"] = url
  176. result["header"] = ''
  177. return result
  178. config = {
  179. "player": {},
  180. "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"}]}]}
  181. }
  182. header = {
  183. "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"
  184. }
  185. def localProxy(self,param):
  186. return [200, "video/MP2T", action, ""]