py_cctvfz.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. "方圆剧阵":"TOPC1571217727564820",
  23. "天网":"TOPC1451543228296920",
  24. "生命线":"TOPC1571040589483598",
  25. "道德观察":"TOPC1451542784285432",
  26. "一线":"TOPC1451543462858283",
  27. "法治在线":"TOPC1451558590627940",
  28. "热线12":"TOPC1451543168050863",
  29. "从心开始":"TOPC1571217374070848",
  30. "现场":"TOPC1571301089686775",
  31. "小区大事":"TOPC1451543346581129",
  32. "法治深壹度":"TOPC1571535828826169",
  33. "忏悔录":"TOPC1451542672944335"
  34. }
  35. classes = []
  36. for k in cateManual:
  37. classes.append({
  38. 'type_name':k,
  39. 'type_id':cateManual[k]
  40. })
  41. result['class'] = classes
  42. if(filter):
  43. result['filters'] = self.config['filter']
  44. return result
  45. def homeVideoContent(self):
  46. result = {
  47. 'list':[]
  48. }
  49. return result
  50. def categoryContent(self,tid,pg,filter,extend):
  51. result = {}
  52. extend['id'] = tid
  53. extend['p'] = pg
  54. filterParams = ["id", "p", "d"]
  55. params = ["", "", ""]
  56. for idx in range(len(filterParams)):
  57. fp = filterParams[idx]
  58. if fp in extend.keys():
  59. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  60. suffix = '&'.join(params)
  61. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  62. if not tid.startswith('TOPC'):
  63. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  64. rsp = self.fetch(url,headers=self.header)
  65. jo = json.loads(rsp.text)
  66. vodList = jo['data']['list']
  67. videos = []
  68. for vod in vodList:
  69. guid = vod['guid']
  70. title = vod['title']
  71. img = vod['image']
  72. brief = vod['brief']
  73. videos.append({
  74. "vod_id":guid+"###"+img,
  75. "vod_name":title,
  76. "vod_pic":img,
  77. "vod_remarks":''
  78. })
  79. result['list'] = videos
  80. result['page'] = pg
  81. result['pagecount'] = 9999
  82. result['limit'] = 90
  83. result['total'] = 999999
  84. return result
  85. def detailContent(self,array):
  86. aid = array[0].split('###')
  87. tid = aid[0]
  88. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  89. rsp = self.fetch(url,headers=self.header)
  90. jo = json.loads(rsp.text)
  91. title = jo['title'].strip()
  92. link = jo['hls_url'].strip()
  93. vod = {
  94. "vod_id":tid,
  95. "vod_name":title,
  96. "vod_pic":aid[1],
  97. "type_name":'',
  98. "vod_year":"",
  99. "vod_area":"",
  100. "vod_remarks":"",
  101. "vod_actor":"",
  102. "vod_director":"",
  103. "vod_content":""
  104. }
  105. vod['vod_play_from'] = 'CCTV'
  106. vod['vod_play_url'] = title+"$"+link
  107. result = {
  108. 'list':[
  109. vod
  110. ]
  111. }
  112. return result
  113. def searchContent(self,key,quick):
  114. result = {
  115. 'list':[]
  116. }
  117. return result
  118. def playerContent(self,flag,id,vipFlags):
  119. result = {}
  120. rsp = self.fetch(id,headers=self.header)
  121. content = rsp.text.strip()
  122. arr = content.split('\n')
  123. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  124. url = urlPrefix + arr[-1]
  125. result["parse"] = 0
  126. result["playUrl"] = ''
  127. result["url"] = url
  128. result["header"] = ''
  129. return result
  130. config = {
  131. "player": {},
  132. "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"}]}]}
  133. }
  134. header = {
  135. "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"
  136. }
  137. def localProxy(self,param):
  138. return [200, "video/MP2T", action, ""]