py_cctvyy.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. "乐享汇":"TOPC1528430065133683",
  23. "国际艺苑":"TOPC1451379250581117",
  24. "中国音乐电视":"TOPC1451542397206110",
  25. "精彩音乐汇":"TOPC1451541414450906",
  26. "童声唱":"TOPC1570593464032566",
  27. "民歌·中国":"TOPC1451541994820527",
  28. "CCTV音乐厅":"TOPC1451534421925242",
  29. "影视留声机":"TOPC1451542346007956",
  30. "音乐人生":"TOPC1451542308412911",
  31. "一起音乐吧":"TOPC1451542132455743",
  32. "音乐公开课":"TOPC1462849800640766",
  33. "乐游天下":"TOPC1451541538046196",
  34. "中国节拍":"TOPC1570025984977611",
  35. "聆听时刻":"TOPC1570026397101703",
  36. "音乐周刊":"TOPC1570593186033488",
  37. "合唱先锋":"TOPC1570026172793162",
  38. "巅峰音乐汇":"TOPC1451984095463376",
  39. "曲苑杂坛":"TOPC1451984417763860",
  40. "星光舞台":"TOPC1451542099519708",
  41. "百年歌声":"TOPC1451534465694290",
  42. "音乐传奇":"TOPC1451542222069826",
  43. "音乐告诉你":"TOPC1451542273313866",
  44. "广场舞金曲":"TOPC1528685010104859",
  45. "快乐琴童":"TOPC1451541450128978",
  46. "歌声与微笑":"TOPC1451541189657627",
  47. "今乐坛":"TOPC1451541229451689",
  48. "乡村大舞台":"TOPC1563179546003162",
  49. "印象·乡村":"TOPC1563178734372977"
  50. }
  51. classes = []
  52. for k in cateManual:
  53. classes.append({
  54. 'type_name':k,
  55. 'type_id':cateManual[k]
  56. })
  57. result['class'] = classes
  58. if(filter):
  59. result['filters'] = self.config['filter']
  60. return result
  61. def homeVideoContent(self):
  62. result = {
  63. 'list':[]
  64. }
  65. return result
  66. def categoryContent(self,tid,pg,filter,extend):
  67. result = {}
  68. extend['id'] = tid
  69. extend['p'] = pg
  70. filterParams = ["id", "p", "d"]
  71. params = ["", "", ""]
  72. for idx in range(len(filterParams)):
  73. fp = filterParams[idx]
  74. if fp in extend.keys():
  75. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  76. suffix = '&'.join(params)
  77. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  78. if not tid.startswith('TOPC'):
  79. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  80. rsp = self.fetch(url,headers=self.header)
  81. jo = json.loads(rsp.text)
  82. vodList = jo['data']['list']
  83. videos = []
  84. for vod in vodList:
  85. guid = vod['guid']
  86. title = vod['title']
  87. img = vod['image']
  88. brief = vod['brief']
  89. videos.append({
  90. "vod_id":guid+"###"+img,
  91. "vod_name":title,
  92. "vod_pic":img,
  93. "vod_remarks":''
  94. })
  95. result['list'] = videos
  96. result['page'] = pg
  97. result['pagecount'] = 9999
  98. result['limit'] = 90
  99. result['total'] = 999999
  100. return result
  101. def detailContent(self,array):
  102. aid = array[0].split('###')
  103. tid = aid[0]
  104. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  105. rsp = self.fetch(url,headers=self.header)
  106. jo = json.loads(rsp.text)
  107. title = jo['title'].strip()
  108. link = jo['hls_url'].strip()
  109. vod = {
  110. "vod_id":tid,
  111. "vod_name":title,
  112. "vod_pic":aid[1],
  113. "type_name":'',
  114. "vod_year":"",
  115. "vod_area":"",
  116. "vod_remarks":"",
  117. "vod_actor":"",
  118. "vod_director":"",
  119. "vod_content":""
  120. }
  121. vod['vod_play_from'] = 'CCTV'
  122. vod['vod_play_url'] = title+"$"+link
  123. result = {
  124. 'list':[
  125. vod
  126. ]
  127. }
  128. return result
  129. def searchContent(self,key,quick):
  130. result = {
  131. 'list':[]
  132. }
  133. return result
  134. def playerContent(self,flag,id,vipFlags):
  135. result = {}
  136. rsp = self.fetch(id,headers=self.header)
  137. content = rsp.text.strip()
  138. arr = content.split('\n')
  139. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  140. url = urlPrefix + arr[-1]
  141. result["parse"] = 0
  142. result["playUrl"] = ''
  143. result["url"] = url
  144. result["header"] = ''
  145. return result
  146. config = {
  147. "player": {},
  148. "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"}]}]}
  149. }
  150. header = {
  151. "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"
  152. }
  153. def localProxy(self,param):
  154. return [200, "video/MP2T", action, ""]