央视农业.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. "致富经":"TOPC1568949310515140",
  23. "三农群英汇":"TOPC1600745974233265",
  24. "田间示范秀":"TOPC1563178908227191",
  25. "农业气象":"TOPC1568949200635957",
  26. "中国三农报道":"TOPC1600746045741952",
  27. "大地讲堂":"TOPC1568966472372643",
  28. "乡土中国":"TOPC1563178586782832",
  29. "振兴路上":"TOPC1632709936747979",
  30. "谁知盘中餐":"TOPC1568966325430648",
  31. "田野里的歌声":"TOPC1632628323813790",
  32. "乡理乡亲":"TOPC1568966155566515",
  33. "我的美丽乡村":"TOPC1570787364956444",
  34. "攻坚日记":"TOPC1568966013656550",
  35. "地球村日记":"TOPC1568966232265609",
  36. "乡约":"TOPC1568949394517190",
  37. "乡村剧场":"TOPC1563179005948252",
  38. "乡村振兴面对面":"TOPC1568966531726705",
  39. "乡间纪事":"TOPC1563178829094125",
  40. "超级新农人":"TOPC1597627647957699",
  41. "科技链":"TOPC1563178120425659",
  42. "乡村振兴资讯":"TOPC1568965444563295",
  43. "遍地英雄":"TOPC1568966086614400",
  44. "健康之路":"TOPC1451557646802924",
  45. "中华医药":"TOPC1451541666791291"
  46. }
  47. classes = []
  48. for k in cateManual:
  49. classes.append({
  50. 'type_name':k,
  51. 'type_id':cateManual[k]
  52. })
  53. result['class'] = classes
  54. if(filter):
  55. result['filters'] = self.config['filter']
  56. return result
  57. def homeVideoContent(self):
  58. result = {
  59. 'list':[]
  60. }
  61. return result
  62. def categoryContent(self,tid,pg,filter,extend):
  63. result = {}
  64. extend['id'] = tid
  65. extend['p'] = pg
  66. filterParams = ["id", "p", "d"]
  67. params = ["", "", ""]
  68. for idx in range(len(filterParams)):
  69. fp = filterParams[idx]
  70. if fp in extend.keys():
  71. params[idx] = '{0}={1}'.format(filterParams[idx],extend[fp])
  72. suffix = '&'.join(params)
  73. url = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  74. if not tid.startswith('TOPC'):
  75. url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?{0}&n=20&sort=desc&mode=0&serviceId=tvcctv&t=json'.format(suffix)
  76. rsp = self.fetch(url,headers=self.header)
  77. jo = json.loads(rsp.text)
  78. vodList = jo['data']['list']
  79. videos = []
  80. for vod in vodList:
  81. guid = vod['guid']
  82. title = vod['title']
  83. img = vod['image']
  84. brief = vod['brief']
  85. videos.append({
  86. "vod_id":guid+"###"+img,
  87. "vod_name":title,
  88. "vod_pic":img,
  89. "vod_remarks":''
  90. })
  91. result['list'] = videos
  92. result['page'] = pg
  93. result['pagecount'] = 9999
  94. result['limit'] = 90
  95. result['total'] = 999999
  96. return result
  97. def detailContent(self,array):
  98. aid = array[0].split('###')
  99. tid = aid[0]
  100. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(tid)
  101. rsp = self.fetch(url,headers=self.header)
  102. jo = json.loads(rsp.text)
  103. title = jo['title'].strip()
  104. link = jo['hls_url'].strip()
  105. vod = {
  106. "vod_id":tid,
  107. "vod_name":title,
  108. "vod_pic":aid[1],
  109. "type_name":'',
  110. "vod_year":"",
  111. "vod_area":"",
  112. "vod_remarks":"",
  113. "vod_actor":"",
  114. "vod_director":"",
  115. "vod_content":""
  116. }
  117. vod['vod_play_from'] = 'CCTV'
  118. vod['vod_play_url'] = title+"$"+link
  119. result = {
  120. 'list':[
  121. vod
  122. ]
  123. }
  124. return result
  125. def searchContent(self,key,quick):
  126. result = {
  127. 'list':[]
  128. }
  129. return result
  130. def playerContent(self,flag,id,vipFlags):
  131. result = {}
  132. rsp = self.fetch(id,headers=self.header)
  133. content = rsp.text.strip()
  134. arr = content.split('\n')
  135. urlPrefix = self.regStr(id,'(http[s]?://[a-zA-z0-9.]+)/')
  136. url = urlPrefix + arr[-1]
  137. result["parse"] = 0
  138. result["playUrl"] = ''
  139. result["url"] = url
  140. result["header"] = ''
  141. return result
  142. config = {
  143. "player": {},
  144. "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"}]}]}
  145. }
  146. header = {
  147. "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"
  148. }
  149. def localProxy(self,param):
  150. return [200, "video/MP2T", action, ""]