py_cctvxq.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. "角儿来了":"TOPC1508747509633692",
  23. "梨园闯关我挂帅":"TOPC1451558484007800",
  24. "CCTV空中剧院":"TOPC1451558856402351",
  25. "过把瘾":"TOPC1451558291260577",
  26. "名段欣赏":"TOPC1451558515719854",
  27. "名家书场":"TOPC1579401761622774",
  28. "宝贝亮相吧":"TOPC1579401989187953",
  29. "中国京剧音配像精粹":"TOPC1451558769767256",
  30. "九州大戏台":"TOPC1451558399948678",
  31. "青春戏苑":"TOPC1451558552047910",
  32. "戏曲青年说":"TOPC1626161016006801",
  33. "了不起的戏曲":"TOPC1657505173323752",
  34. "梨园周刊":"TOPC1574909786070351",
  35. "中国京剧像音像集萃":"TOPC1626832834318986",
  36. "典藏":"TOPC1597825254395109",
  37. "快乐戏园":"TOPC1451558438767762",
  38. "锦绣梨园":"TOPC1451558328292617",
  39. "影视剧场":"TOPC1451558728003217",
  40. "戏苑百家":"TOPC1451558644535996",
  41. "跟我学":"TOPC1451558178940505",
  42. "戏曲采风":"TOPC1451558610462968"
  43. }
  44. classes = []
  45. for k in cateManual:
  46. classes.append({
  47. 'type_name':k,
  48. 'type_id':cateManual[k]
  49. })
  50. result['class'] = classes
  51. if(filter):
  52. result['filters'] = self.config['filter']
  53. return result
  54. def homeVideoContent(self):
  55. result = {
  56. 'list':[]
  57. }
  58. return result
  59. def categoryContent(self,tid,pg,filter,extend):
  60. result = {}
  61. extend['id'] = tid
  62. extend['p'] = pg
  63. filterParams = ["id", "p", "d"]
  64. params = ["", "", ""]
  65. for idx in range(len(filterParams)):
  66. fp = filterParams[idx]
  67. if fp in extend.keys():
  68. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  69. suffix = '&'.join(params)
  70. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  71. if not tid.startswith('TOPC'):
  72. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  73. rsp = self.fetch(url,headers=self.header)
  74. jo = json.loads(rsp.text)
  75. vodList = jo['data']['list']
  76. videos = []
  77. for vod in vodList:
  78. guid = vod['guid']
  79. title = vod['title']
  80. img = vod['image']
  81. brief = vod['brief']
  82. videos.append({
  83. "vod_id":guid+"###"+img,
  84. "vod_name":title,
  85. "vod_pic":img,
  86. "vod_remarks":''
  87. })
  88. result['list'] = videos
  89. result['page'] = pg
  90. result['pagecount'] = 9999
  91. result['limit'] = 90
  92. result['total'] = 999999
  93. return result
  94. def detailContent(self,array):
  95. aid = array[0].split('###')
  96. tid = aid[0]
  97. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  98. rsp = self.fetch(url,headers=self.header)
  99. jo = json.loads(rsp.text)
  100. title = jo['title'].strip()
  101. link = jo['hls_url'].strip()
  102. vod = {
  103. "vod_id":tid,
  104. "vod_name":title,
  105. "vod_pic":aid[1],
  106. "type_name":'',
  107. "vod_year":"",
  108. "vod_area":"",
  109. "vod_remarks":"",
  110. "vod_actor":"",
  111. "vod_director":"",
  112. "vod_content":""
  113. }
  114. vod['vod_play_from'] = 'CCTV'
  115. vod['vod_play_url'] = title+"$"+link
  116. result = {
  117. 'list':[
  118. vod
  119. ]
  120. }
  121. return result
  122. def searchContent(self,key,quick):
  123. result = {
  124. 'list':[]
  125. }
  126. return result
  127. def playerContent(self,flag,id,vipFlags):
  128. result = {}
  129. rsp = self.fetch(id,headers=self.header)
  130. content = rsp.text.strip()
  131. arr = content.split('\n')
  132. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  133. url = urlPrefix + arr[-1]
  134. result["parse"] = 0
  135. result["playUrl"] = ''
  136. result["url"] = url
  137. result["header"] = ''
  138. return result
  139. config = {
  140. "player": {},
  141. "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"}]}]}
  142. }
  143. header = {
  144. "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"
  145. }
  146. def localProxy(self,param):
  147. return [200, "video/MP2T", action, ""]