py_cctv.py 5.7 KB

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