py_cctvdy.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. "中国电影报道":"TOPC1451354597100320",
  23. "星推荐":"TOPC1451469943519994",
  24. "剧说很好看":"TOPC1495184612807684",
  25. "今日影评":"TOPC1470713254980521",
  26. "世界电影之旅":"TOPC1451560112462173",
  27. "影视俱乐部":"TOPC1451469901250966",
  28. "影视同期声":"TOPC1451469804671799",
  29. "影视名堂":"TOPC1451558049329358",
  30. "第10放映室":"TOPC1451557487468814"
  31. }
  32. classes = []
  33. for k in cateManual:
  34. classes.append({
  35. 'type_name':k,
  36. 'type_id':cateManual[k]
  37. })
  38. result['class'] = classes
  39. if(filter):
  40. result['filters'] = self.config['filter']
  41. return result
  42. def homeVideoContent(self):
  43. result = {
  44. 'list':[]
  45. }
  46. return result
  47. def categoryContent(self,tid,pg,filter,extend):
  48. result = {}
  49. extend['id'] = tid
  50. extend['p'] = pg
  51. filterParams = ["id", "p", "d"]
  52. params = ["", "", ""]
  53. for idx in range(len(filterParams)):
  54. fp = filterParams[idx]
  55. if fp in extend.keys():
  56. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  57. suffix = '&'.join(params)
  58. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  59. if not tid.startswith('TOPC'):
  60. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  61. rsp = self.fetch(url,headers=self.header)
  62. jo = json.loads(rsp.text)
  63. vodList = jo['data']['list']
  64. videos = []
  65. for vod in vodList:
  66. guid = vod['guid']
  67. title = vod['title']
  68. img = vod['image']
  69. brief = vod['brief']
  70. videos.append({
  71. "vod_id":guid+"###"+img,
  72. "vod_name":title,
  73. "vod_pic":img,
  74. "vod_remarks":''
  75. })
  76. result['list'] = videos
  77. result['page'] = pg
  78. result['pagecount'] = 9999
  79. result['limit'] = 90
  80. result['total'] = 999999
  81. return result
  82. def detailContent(self,array):
  83. aid = array[0].split('###')
  84. tid = aid[0]
  85. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  86. rsp = self.fetch(url,headers=self.header)
  87. jo = json.loads(rsp.text)
  88. title = jo['title'].strip()
  89. link = jo['hls_url'].strip()
  90. vod = {
  91. "vod_id":tid,
  92. "vod_name":title,
  93. "vod_pic":aid[1],
  94. "type_name":'',
  95. "vod_year":"",
  96. "vod_area":"",
  97. "vod_remarks":"",
  98. "vod_actor":"",
  99. "vod_director":"",
  100. "vod_content":""
  101. }
  102. vod['vod_play_from'] = 'CCTV'
  103. vod['vod_play_url'] = title+"$"+link
  104. result = {
  105. 'list':[
  106. vod
  107. ]
  108. }
  109. return result
  110. def searchContent(self,key,quick):
  111. result = {
  112. 'list':[]
  113. }
  114. return result
  115. def playerContent(self,flag,id,vipFlags):
  116. result = {}
  117. rsp = self.fetch(id,headers=self.header)
  118. content = rsp.text.strip()
  119. arr = content.split('\n')
  120. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  121. url = urlPrefix + arr[-1]
  122. result["parse"] = 0
  123. result["playUrl"] = ''
  124. result["url"] = url
  125. result["header"] = ''
  126. return result
  127. config = {
  128. "player": {},
  129. "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"}]}]}
  130. }
  131. header = {
  132. "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"
  133. }
  134. def localProxy(self,param):
  135. return [200, "video/MP2T", action, ""]