py_cctvse.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. "新闻袋袋裤":"TOPC1451559603261584",
  23. "英雄出少年":"TOPC1451559695702690",
  24. "七巧板":"TOPC1451559569040502",
  25. "快乐体验":"TOPC1451559479171411",
  26. "智力快车":"TOPC1451559756374759",
  27. "动感特区":"TOPC1451559378830189",
  28. "音乐快递":"TOPC1451559666055645",
  29. "SK极智少年强":"TOPC1476950587121943",
  30. "加油!少年派":"TOPC1451464548229761",
  31. "风车剧场":"TOPC1573528152700717",
  32. "希望-英语杂志":"TOPC1451558013229330",
  33. "成长在线":"TOPC1451559901017891",
  34. "童心回放":"TOPC1451559966897957",
  35. "文学宝库":"TOPC1451560002205989",
  36. "大仓库":"TOPC1451559344361150",
  37. "宝贝一家亲":"TOPC1451559867985861",
  38. "绿野寻踪":"TOPC1451559534065469",
  39. "芝麻开门":"TOPC1451559725520729",
  40. "异想天开":"TOPC1451559633994614"
  41. }
  42. classes = []
  43. for k in cateManual:
  44. classes.append({
  45. 'type_name':k,
  46. 'type_id':cateManual[k]
  47. })
  48. result['class'] = classes
  49. if(filter):
  50. result['filters'] = self.config['filter']
  51. return result
  52. def homeVideoContent(self):
  53. result = {
  54. 'list':[]
  55. }
  56. return result
  57. def categoryContent(self,tid,pg,filter,extend):
  58. result = {}
  59. extend['id'] = tid
  60. extend['p'] = pg
  61. filterParams = ["id", "p", "d"]
  62. params = ["", "", ""]
  63. for idx in range(len(filterParams)):
  64. fp = filterParams[idx]
  65. if fp in extend.keys():
  66. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  67. suffix = '&'.join(params)
  68. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  69. if not tid.startswith('TOPC'):
  70. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  71. rsp = self.fetch(url,headers=self.header)
  72. jo = json.loads(rsp.text)
  73. vodList = jo['data']['list']
  74. videos = []
  75. for vod in vodList:
  76. guid = vod['guid']
  77. title = vod['title']
  78. img = vod['image']
  79. brief = vod['brief']
  80. videos.append({
  81. "vod_id":guid+"###"+img,
  82. "vod_name":title,
  83. "vod_pic":img,
  84. "vod_remarks":''
  85. })
  86. result['list'] = videos
  87. result['page'] = pg
  88. result['pagecount'] = 9999
  89. result['limit'] = 90
  90. result['total'] = 999999
  91. return result
  92. def detailContent(self,array):
  93. aid = array[0].split('###')
  94. tid = aid[0]
  95. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  96. rsp = self.fetch(url,headers=self.header)
  97. jo = json.loads(rsp.text)
  98. title = jo['title'].strip()
  99. link = jo['hls_url'].strip()
  100. vod = {
  101. "vod_id":tid,
  102. "vod_name":title,
  103. "vod_pic":aid[1],
  104. "type_name":'',
  105. "vod_year":"",
  106. "vod_area":"",
  107. "vod_remarks":"",
  108. "vod_actor":"",
  109. "vod_director":"",
  110. "vod_content":""
  111. }
  112. vod['vod_play_from'] = 'CCTV'
  113. vod['vod_play_url'] = title+"$"+link
  114. result = {
  115. 'list':[
  116. vod
  117. ]
  118. }
  119. return result
  120. def searchContent(self,key,quick):
  121. result = {
  122. 'list':[]
  123. }
  124. return result
  125. def playerContent(self,flag,id,vipFlags):
  126. result = {}
  127. rsp = self.fetch(id,headers=self.header)
  128. content = rsp.text.strip()
  129. arr = content.split('\n')
  130. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  131. url = urlPrefix + arr[-1]
  132. result["parse"] = 0
  133. result["playUrl"] = ''
  134. result["url"] = url
  135. result["header"] = ''
  136. return result
  137. config = {
  138. "player": {},
  139. "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"}]}]}
  140. }
  141. header = {
  142. "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"
  143. }
  144. def localProxy(self,param):
  145. return [200, "video/MP2T", action, ""]