央视军事.py 4.5 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. "国防军事早报":"TOPC1564109128610932",
  23. "正午国防军事":"TOPC1564109254301161",
  24. "军事报道":"TOPC1451527941788652",
  25. "防务新观察":"TOPC1451526164984187",
  26. "军迷行天下":"TOPC1564131644145429",
  27. "老兵你好":"TOPC1564109722559395",
  28. "军武零距离":"TOPC1564109434999268",
  29. "军事制高点":"TOPC1564109356650207",
  30. "军事科技":"TOPC1451528087494889",
  31. "军事纪实":"TOPC1451527993718730",
  32. "谁是终极英雄":"TOPC1451530272783201",
  33. "军营的味道":"TOPC1564110136027687",
  34. "砺剑":"TOPC1649983616689859",
  35. "军事纪录":"TOPC1575602995944674",
  36. "国防故事":"TOPC1578551434601482",
  37. "兵器面面观":"TOPC1564110696628209",
  38. "第二战场":"TOPC1564110615253124",
  39. "世界战史":"TOPC1564110396694880",
  40. "五星剧场":"TOPC1564110834985329",
  41. "国防微视频-军歌嘹亮":"TOPC1564110222559767",
  42. "军情时间到":"TOPC1462504102545692",
  43. "国防科工":"TOPC1564109813378483"
  44. }
  45. classes = []
  46. for k in cateManual:
  47. classes.append({
  48. 'type_name':k,
  49. 'type_id':cateManual[k]
  50. })
  51. result['class'] = classes
  52. if(filter):
  53. result['filters'] = self.config['filter']
  54. return result
  55. def homeVideoContent(self):
  56. result = {
  57. 'list':[]
  58. }
  59. return result
  60. def categoryContent(self,tid,pg,filter,extend):
  61. result = {}
  62. extend['id'] = tid
  63. extend['p'] = pg
  64. filterParams = ["id", "p", "d"]
  65. params = ["", "", ""]
  66. for idx in range(len(filterParams)):
  67. fp = filterParams[idx]
  68. if fp in extend.keys():
  69. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  70. suffix = '&'.join(params)
  71. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  72. if not tid.startswith('TOPC'):
  73. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  74. rsp = self.fetch(url,headers=self.header)
  75. jo = json.loads(rsp.text)
  76. vodList = jo['data']['list']
  77. videos = []
  78. for vod in vodList:
  79. guid = vod['guid']
  80. title = vod['title']
  81. img = vod['image']
  82. brief = vod['brief']
  83. videos.append({
  84. "vod_id":guid+"###"+img,
  85. "vod_name":title,
  86. "vod_pic":img,
  87. "vod_remarks":''
  88. })
  89. result['list'] = videos
  90. result['page'] = pg
  91. result['pagecount'] = 9999
  92. result['limit'] = 90
  93. result['total'] = 999999
  94. return result
  95. def detailContent(self,array):
  96. aid = array[0].split('###')
  97. tid = aid[0]
  98. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  99. rsp = self.fetch(url,headers=self.header)
  100. jo = json.loads(rsp.text)
  101. title = jo['title'].strip()
  102. link = jo['hls_url'].strip()
  103. vod = {
  104. "vod_id":tid,
  105. "vod_name":title,
  106. "vod_pic":aid[1],
  107. "type_name":'',
  108. "vod_year":"",
  109. "vod_area":"",
  110. "vod_remarks":"",
  111. "vod_actor":"",
  112. "vod_director":"",
  113. "vod_content":""
  114. }
  115. vod['vod_play_from'] = 'CCTV'
  116. vod['vod_play_url'] = title+"$"+link
  117. result = {
  118. 'list':[
  119. vod
  120. ]
  121. }
  122. return result
  123. def searchContent(self,key,quick):
  124. result = {
  125. 'list':[]
  126. }
  127. return result
  128. def playerContent(self,flag,id,vipFlags):
  129. result = {}
  130. rsp = self.fetch(id,headers=self.header)
  131. content = rsp.text.strip()
  132. arr = content.split('\n')
  133. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  134. url = urlPrefix + arr[-1]
  135. result["parse"] = 0
  136. result["playUrl"] = ''
  137. result["url"] = url
  138. result["header"] = ''
  139. return result
  140. config = {
  141. "player": {},
  142. "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"}]}]}
  143. }
  144. header = {
  145. "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"
  146. }
  147. def localProxy(self,param):
  148. return [200, "video/MP2T", action, ""]