py_cctv.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. "探索发现": "TOPC1451557893544236",
  26. "创新进行时": "TOPC1570875218228998",
  27. "我爱发明2021": "TOPC1451557970755294",
  28. "经典咏流传 第五季":"VIDAIiNbDQzOjE5mLl3T4t2B220403"
  29. }
  30. classes = []
  31. for k in cateManual:
  32. classes.append({
  33. 'type_name':k,
  34. 'type_id':cateManual[k]
  35. })
  36. result['class'] = classes
  37. if(filter):
  38. result['filters'] = self.config['filter']
  39. return result
  40. def homeVideoContent(self):
  41. result = {
  42. 'list':[]
  43. }
  44. return result
  45. def categoryContent(self,tid,pg,filter,extend):
  46. result = {}
  47. extend['id'] = tid
  48. extend['p'] = pg
  49. filterParams = ["id", "p", "d"]
  50. params = ["", "", ""]
  51. for idx in range(len(filterParams)):
  52. fp = filterParams[idx]
  53. if fp in extend.keys():
  54. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  55. suffix = '&'.join(params)
  56. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  57. if not tid.startswith('TOPC'):
  58. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  59. rsp = self.fetch(url,headers=self.header)
  60. jo = json.loads(rsp.text)
  61. vodList = jo['data']['list']
  62. videos = []
  63. for vod in vodList:
  64. guid = vod['guid']
  65. title = vod['title']
  66. img = vod['image']
  67. brief = vod['brief']
  68. videos.append({
  69. "vod_id":guid+"###"+img,
  70. "vod_name":title,
  71. "vod_pic":img,
  72. "vod_remarks":''
  73. })
  74. result['list'] = videos
  75. result['page'] = pg
  76. result['pagecount'] = 9999
  77. result['limit'] = 90
  78. result['total'] = 999999
  79. return result
  80. def detailContent(self,array):
  81. aid = array[0].split('###')
  82. tid = aid[0]
  83. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  84. rsp = self.fetch(url,headers=self.header)
  85. jo = json.loads(rsp.text)
  86. title = jo['title'].strip()
  87. link = jo['hls_url'].strip()
  88. vod = {
  89. "vod_id":tid,
  90. "vod_name":title,
  91. "vod_pic":aid[1],
  92. "type_name":'',
  93. "vod_year":"",
  94. "vod_area":"",
  95. "vod_remarks":"",
  96. "vod_actor":"",
  97. "vod_director":"",
  98. "vod_content":""
  99. }
  100. vod['vod_play_from'] = 'CCTV'
  101. vod['vod_play_url'] = title+"$"+link
  102. result = {
  103. 'list':[
  104. vod
  105. ]
  106. }
  107. return result
  108. def searchContent(self,key,quick):
  109. result = {
  110. 'list':[]
  111. }
  112. return result
  113. def playerContent(self,flag,id,vipFlags):
  114. result = {}
  115. rsp = self.fetch(id,headers=self.header)
  116. content = rsp.text.strip()
  117. arr = content.split('\n')
  118. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  119. url = urlPrefix + arr[-1]
  120. result["parse"] = 0
  121. result["playUrl"] = ''
  122. result["url"] = url
  123. result["header"] = ''
  124. return result
  125. config = {
  126. "player": {},
  127. "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"}]}]}
  128. }
  129. header = {
  130. "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"
  131. }
  132. def localProxy(self,param):
  133. return [200, "video/MP2T", action, ""]