cctv_spider_0710.py 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. # coding=utf-8
  2. # !/usr/bin/python
  3. import os.path
  4. import random
  5. import sys
  6. sys.path.append('..')
  7. try:
  8. from base.spider import Spider as BaseSpider
  9. except ImportError:
  10. from t4.base.spider import BaseSpider
  11. import json
  12. import time
  13. import base64
  14. import re
  15. from urllib import request, parse
  16. from pathlib import Path
  17. import urllib
  18. import urllib.request
  19. import time
  20. """
  21. 配置示例:
  22. t4的配置里ext节点会自动变成api对应query参数extend,但t4的ext字符串不支持路径格式,比如./开头或者.json结尾
  23. api里会自动含有ext参数是base64编码后的选中的筛选条件
  24. 错误示例,ext含有json:
  25. {
  26. "key":"hipy_cctv",
  27. "name":"hipy_cctv",
  28. "type":4,
  29. "api":"http://192.168.31.49:5707/api/v1/vod/cctv_spider?api_ext={{host}}/txt/hipy/cctv_spider.json",
  30. "searchable":1,
  31. "quickSearch":1,
  32. "filterable":1,
  33. "ext":"cctv_spider.json"
  34. }
  35. 正确示例。同时存在ext和api_ext会优先取ext作为extend加载init
  36. {
  37. "key":"hipy_cctv",
  38. "name":"hipy_cctv",
  39. "type":4,
  40. "api":"http://192.168.31.49:5707/api/v1/vod/cctv_spider?api_ext={{host}}/txt/hipy/cctv_spider.json",
  41. "searchable":1,
  42. "quickSearch":1,
  43. "filterable":1,
  44. "ext":"cctv_spider"
  45. }
  46. {
  47. "key": "t3_hipy_cctv",
  48. "name": "t3_hipy_cctv",
  49. "type": 3,
  50. "api": "{{host}}/txt/hipy/cctv_spider.py",
  51. "searchable": 1,
  52. "quickSearch": 1,
  53. "filterable": 1,
  54. "ext": "{{host}}/txt/hipy/cctv_spider.json"
  55. }
  56. """
  57. class Spider(BaseSpider): # 元类 默认的元类 type
  58. def getName(self):
  59. return "中央电视台" # 可搜索
  60. def init_api_ext_file(self):
  61. ext_file = __file__.replace('.py', '.json')
  62. print(f'ext_file:{ext_file}')
  63. # 特别节目网页: https://tv.cctv.com/yxg/index.shtml?spm=C28340.PlFTqGe6Zk8M.E2PQtIunpEaz.65
  64. # 特别节目分类筛选获取页面: https://tv.cctv.com/yxg/tbjm/index.shtml
  65. # 纪录片网页: https://tv.cctv.com/yxg/index.shtml?spm=C28340.PlFTqGe6Zk8M.E2PQtIunpEaz.65
  66. # 纪录片分类筛选获取页面:https://tv.cctv.com/yxg/jlp/index.shtml
  67. # ==================== 获取特别节目的筛选条件 ======================
  68. r = self.fetch('https://tv.cctv.com/yxg/tbjm/index.shtml')
  69. html = r.text
  70. # html = self.webReadFile(urlStr='https://tv.cctv.com/yxg/tbjm/index.shtml', header=self.header)
  71. # print(html)
  72. html = self.html(html)
  73. filter_tbjm = []
  74. lis = html.xpath('//*[@id="pindao"]/li')
  75. li_value = []
  76. for li in lis:
  77. li_value.append({
  78. 'n': ''.join(li.xpath('./span//text()')),
  79. 'v': ''.join(li.xpath('@datacd')),
  80. })
  81. # print(li_value)
  82. filter_tbjm.append({
  83. "key": "datapd-channel",
  84. "name": "频道",
  85. "value": li_value
  86. })
  87. lis = html.xpath('//*[@id="fenlei"]/li')
  88. li_value = []
  89. for li in lis:
  90. li_value.append({
  91. 'n': ''.join(li.xpath('./span//text()')),
  92. 'v': ''.join(li.xpath('@datalx')),
  93. })
  94. # print(li_value)
  95. filter_tbjm.append({
  96. "key": "datafl-sc",
  97. "name": "类型",
  98. "value": li_value
  99. })
  100. lis = html.xpath('//*[@id="zimu"]/li')
  101. li_value = []
  102. for li in lis:
  103. li_value.append({
  104. 'n': ''.join(li.xpath('./span//text()')),
  105. 'v': ''.join(li.xpath('@datazm')),
  106. })
  107. # print(li_value)
  108. filter_tbjm.append({
  109. "key": "dataszm-letter",
  110. "name": "首字母",
  111. "value": li_value
  112. })
  113. print(filter_tbjm)
  114. # ==================== 纪录片筛选获取 ======================
  115. r = self.fetch('https://tv.cctv.com/yxg/jlp/index.shtml')
  116. html = r.text
  117. html = self.html(html)
  118. filter_jlp = []
  119. lis = html.xpath('//*[@id="pindao"]/li')
  120. li_value = []
  121. for li in lis:
  122. li_value.append({
  123. 'n': ''.join(li.xpath('./span//text()')),
  124. 'v': ''.join(li.xpath('@datacd')),
  125. })
  126. # print(li_value)
  127. filter_jlp.append({
  128. "key": "datapd-channel",
  129. "name": "频道",
  130. "value": li_value
  131. })
  132. lis = html.xpath('//*[@id="fenlei"]/li')
  133. li_value = []
  134. for li in lis:
  135. li_value.append({
  136. 'n': ''.join(li.xpath('./span//text()')),
  137. 'v': ''.join(li.xpath('@datalx')),
  138. })
  139. # print(li_value)
  140. filter_jlp.append({
  141. "key": "datafl-sc",
  142. "name": "类型",
  143. "value": li_value
  144. })
  145. lis = html.xpath('//*[@id="nianfen"]/li')
  146. li_value = []
  147. for li in lis:
  148. li_value.append({
  149. 'n': ''.join(li.xpath('./span//text()')),
  150. 'v': ''.join(li.xpath('@datanf')),
  151. })
  152. # print(li_value)
  153. filter_jlp.append({
  154. "key": "datanf-year",
  155. "name": "年份",
  156. "value": li_value
  157. })
  158. lis = html.xpath('//*[@id="zimu"]/li')
  159. li_value = []
  160. for li in lis:
  161. li_value.append({
  162. 'n': ''.join(li.xpath('./span//text()')),
  163. 'v': ''.join(li.xpath('@datazm')),
  164. })
  165. # print(li_value)
  166. filter_jlp.append({
  167. "key": "dataszm-letter",
  168. "name": "首字母",
  169. "value": li_value
  170. })
  171. print(filter_jlp)
  172. ext_file_dict = {
  173. "特别节目": filter_tbjm,
  174. "纪录片": filter_jlp,
  175. }
  176. # print(json.dumps(ext_file_dict,ensure_ascii=False,indent=4))
  177. with open(ext_file, mode='w+', encoding='utf-8') as f:
  178. # f.write(json.dumps(ext_file_dict,ensure_ascii=False,indent=4))
  179. f.write(json.dumps(ext_file_dict, ensure_ascii=False))
  180. def init(self, extend=""):
  181. def init_file(ext_file):
  182. ext_file = Path(ext_file).as_posix()
  183. # print(f'ext_file:{ext_file}')
  184. if os.path.exists(ext_file):
  185. # print('存在扩展文件')
  186. with open(ext_file, mode='r', encoding='utf-8') as f:
  187. try:
  188. ext_dict = json.loads(f.read())
  189. # print(ext_dict)
  190. self.config['filter'].update(ext_dict)
  191. except Exception as e:
  192. print(f'更新扩展筛选条件发生错误:{e}')
  193. print("============{0}============".format(extend))
  194. if extend.startswith('./'):
  195. ext_file = os.path.join(os.path.dirname(__file__), extend)
  196. init_file(ext_file)
  197. elif extend.startswith('http'):
  198. try:
  199. r = self.fetch(extend)
  200. self.config['filter'].update(r.json())
  201. except Exception as e:
  202. print(f'更新扩展筛选条件发生错误:{e}')
  203. elif extend and not extend.startswith('./') and not extend.startswith('http'):
  204. ext_file = os.path.join(os.path.dirname(__file__), './' + extend + '.json')
  205. init_file(ext_file)
  206. def isVideoFormat(self, url):
  207. pass
  208. def manualVideoCheck(self):
  209. pass
  210. def homeContent(self, filter):
  211. result = {}
  212. cateManual = {
  213. "栏目大全": "栏目大全",
  214. "特别节目": "特别节目",
  215. "纪录片": "纪录片",
  216. "电视剧": "电视剧",
  217. "动画片": "动画片"
  218. }
  219. classes = []
  220. for k in cateManual:
  221. classes.append({
  222. 'type_name': k,
  223. 'type_id': cateManual[k]
  224. })
  225. result['class'] = classes
  226. if (filter):
  227. result['filters'] = self.config['filter']
  228. return result
  229. def homeVideoContent(self):
  230. result = {
  231. 'list': []
  232. }
  233. return result
  234. def categoryContent(self, tid, pg, filter, extend):
  235. result = {}
  236. month = "" # 月
  237. year = "" # 年
  238. area = '' # 地区
  239. channel = '' # 频道
  240. datafl = '' # 类型
  241. letter = '' # 字母
  242. pagecount = 24
  243. if tid == '动画片':
  244. id = urllib.parse.quote(tid)
  245. if 'datadq-area' in extend.keys():
  246. area = urllib.parse.quote(extend['datadq-area'])
  247. if 'dataszm-letter' in extend.keys():
  248. letter = extend['dataszm-letter']
  249. if 'datafl-sc' in extend.keys():
  250. datafl = urllib.parse.quote(extend['datafl-sc'])
  251. url = 'https://api.cntv.cn/list/getVideoAlbumList?channelid=CHAL1460955899450127&area={0}&sc={4}&fc={1}&letter={2}&p={3}&n=24&serviceId=tvcctv&topv=1&t=json'.format(
  252. area, id, letter, pg, datafl)
  253. elif tid == '纪录片':
  254. id = urllib.parse.quote(tid)
  255. if 'datapd-channel' in extend.keys():
  256. channel = urllib.parse.quote(extend['datapd-channel'])
  257. if 'datafl-sc' in extend.keys():
  258. datafl = urllib.parse.quote(extend['datafl-sc'])
  259. if 'datanf-year' in extend.keys():
  260. year = extend['datanf-year']
  261. if 'dataszm-letter' in extend.keys():
  262. letter = extend['dataszm-letter']
  263. url = 'https://api.cntv.cn/list/getVideoAlbumList?channelid=CHAL1460955924871139&fc={0}&channel={1}&sc={2}&year={3}&letter={4}&p={5}&n=24&serviceId=tvcctv&topv=1&t=json'.format(
  264. id, channel, datafl, year, letter, pg)
  265. elif tid == '电视剧':
  266. id = urllib.parse.quote(tid)
  267. if 'datafl-sc' in extend.keys():
  268. datafl = urllib.parse.quote(extend['datafl-sc'])
  269. if 'datanf-year' in extend.keys():
  270. year = extend['datanf-year']
  271. if 'dataszm-letter' in extend.keys():
  272. letter = extend['dataszm-letter']
  273. url = 'https://api.cntv.cn/list/getVideoAlbumList?channelid=CHAL1460955853485115&area={0}&sc={1}&fc={2}&year={3}&letter={4}&p={5}&n=24&serviceId=tvcctv&topv=1&t=json'.format(
  274. area, datafl, id, year, letter, pg)
  275. elif tid == '特别节目':
  276. id = urllib.parse.quote(tid)
  277. if 'datapd-channel' in extend.keys():
  278. channel = urllib.parse.quote(extend['datapd-channel'])
  279. if 'datafl-sc' in extend.keys():
  280. datafl = urllib.parse.quote(extend['datafl-sc'])
  281. if 'dataszm-letter' in extend.keys():
  282. letter = extend['dataszm-letter']
  283. url = 'https://api.cntv.cn/list/getVideoAlbumList?channelid=CHAL1460955953877151&channel={0}&sc={1}&fc={2}&bigday=&letter={3}&p={4}&n=24&serviceId=tvcctv&topv=1&t=json'.format(
  284. channel, datafl, id, letter, pg)
  285. elif tid == '栏目大全':
  286. cid = '' # 频道
  287. if 'cid' in extend.keys():
  288. cid = extend['cid']
  289. fc = '' # 分类
  290. if 'fc' in extend.keys():
  291. fc = extend['fc']
  292. fl = '' # 字母
  293. if 'fl' in extend.keys():
  294. fl = extend['fl']
  295. url = 'https://api.cntv.cn/lanmu/columnSearch?&fl={0}&fc={1}&cid={2}&p={3}&n=20&serviceId=tvcctv&t=json&cb=ko'.format(
  296. fl, fc, cid, pg)
  297. pagecount = 20
  298. else:
  299. url = 'https://tv.cctv.com/epg/index.shtml'
  300. videos = []
  301. htmlText = self.webReadFile(urlStr=url, header=self.header)
  302. if tid == '栏目大全':
  303. index = htmlText.rfind(');')
  304. if index > -1:
  305. htmlText = htmlText[3:index]
  306. videos = self.get_list1(html=htmlText, tid=tid)
  307. else:
  308. videos = self.get_list(html=htmlText, tid=tid)
  309. # print(videos)
  310. result['list'] = videos
  311. result['page'] = pg
  312. result['pagecount'] = 9999 if len(videos) >= pagecount else pg
  313. result['limit'] = 90
  314. result['total'] = 999999
  315. return result
  316. def detailContent(self, array):
  317. result = {}
  318. aid = array[0].split('||')
  319. tid = aid[0]
  320. logo = aid[3]
  321. lastVideo = aid[2]
  322. title = aid[1]
  323. id = aid[4]
  324. vod_year = aid[5]
  325. actors = aid[6] if len(aid) > 6 else ''
  326. brief = aid[7] if len(aid) > 7 else '' # get请求最长255,这个描述会有可能直接被干没了。
  327. fromId = 'CCTV'
  328. if tid == "栏目大全":
  329. lastUrl = 'https://api.cntv.cn/video/videoinfoByGuid?guid={0}&serviceId=tvcctv'.format(id)
  330. htmlTxt = self.webReadFile(urlStr=lastUrl, header=self.header)
  331. topicId = json.loads(htmlTxt)['ctid']
  332. Url = "https://api.cntv.cn/NewVideo/getVideoListByColumn?id={0}&d=&p=1&n=100&sort=desc&mode=0&serviceId=tvcctv&t=json".format(
  333. topicId)
  334. htmlTxt = self.webReadFile(urlStr=Url, header=self.header)
  335. else:
  336. Url = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?id={0}&serviceId=tvcctv&p=1&n=100&mode=0&pub=1'.format(
  337. id)
  338. jRoot = ''
  339. videoList = []
  340. try:
  341. if tid == "搜索":
  342. fromId = '中央台'
  343. videoList = [title + "$" + lastVideo]
  344. else:
  345. htmlTxt = self.webReadFile(urlStr=Url, header=self.header)
  346. jRoot = json.loads(htmlTxt)
  347. data = jRoot['data']
  348. jsonList = data['list']
  349. videoList = self.get_EpisodesList(jsonList=jsonList)
  350. if len(videoList) < 1:
  351. htmlTxt = self.webReadFile(urlStr=lastVideo, header=self.header)
  352. if tid == "电视剧" or tid == "纪录片":
  353. patternTxt = r"'title':\s*'(?P<title>.+?)',\n{0,1}\s*'brief':\s*'(.+?)',\n{0,1}\s*'img':\s*'(.+?)',\n{0,1}\s*'url':\s*'(?P<url>.+?)'"
  354. elif tid == "特别节目":
  355. patternTxt = r'class="tp1"><a\s*href="(?P<url>https://.+?)"\s*target="_blank"\s*title="(?P<title>.+?)"></a></div>'
  356. elif tid == "动画片":
  357. patternTxt = r"'title':\s*'(?P<title>.+?)',\n{0,1}\s*'img':\s*'(.+?)',\n{0,1}\s*'brief':\s*'(.+?)',\n{0,1}\s*'url':\s*'(?P<url>.+?)'"
  358. elif tid == "栏目大全":
  359. patternTxt = r'href="(?P<url>.+?)" target="_blank" alt="(?P<title>.+?)" title=".+?">'
  360. videoList = self.get_EpisodesList_re(htmlTxt=htmlTxt, patternTxt=patternTxt)
  361. fromId = '央视'
  362. except:
  363. pass
  364. if len(videoList) == 0:
  365. return {}
  366. vod = {
  367. "vod_id": array[0],
  368. "vod_name": title,
  369. "vod_pic": logo,
  370. "type_name": tid,
  371. "vod_year": vod_year,
  372. "vod_area": "",
  373. "vod_remarks": '',
  374. "vod_actor": actors,
  375. "vod_director": '',
  376. "vod_content": brief
  377. }
  378. vod['vod_play_from'] = fromId
  379. vod['vod_play_url'] = "#".join(videoList)
  380. result = {
  381. 'list': [
  382. vod
  383. ]
  384. }
  385. return result
  386. def get_lineList(self, Txt, mark, after):
  387. circuit = []
  388. origin = Txt.find(mark)
  389. while origin > 8:
  390. end = Txt.find(after, origin)
  391. circuit.append(Txt[origin:end])
  392. origin = Txt.find(mark, end)
  393. return circuit
  394. def get_RegexGetTextLine(self, Text, RegexText, Index):
  395. returnTxt = []
  396. pattern = re.compile(RegexText, re.M | re.S)
  397. ListRe = pattern.findall(Text)
  398. if len(ListRe) < 1:
  399. return returnTxt
  400. for value in ListRe:
  401. returnTxt.append(value)
  402. return returnTxt
  403. def searchContent(self, key, quick):
  404. key = urllib.parse.quote(key)
  405. Url = 'https://search.cctv.com/ifsearch.php?page=1&qtext={0}&sort=relevance&pageSize=20&type=video&vtime=-1&datepid=1&channel=&pageflag=0&qtext_str={0}'.format(
  406. key)
  407. htmlTxt = self.webReadFile(urlStr=Url, header=self.header)
  408. videos = self.get_list_search(html=htmlTxt, tid='搜索')
  409. result = {
  410. 'list': videos
  411. }
  412. return result
  413. def playerContent(self, flag, id, vipFlags):
  414. result = {}
  415. url = ''
  416. parse = 0
  417. headers = {
  418. 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'
  419. }
  420. if flag == 'CCTV':
  421. url = self.get_m3u8(urlTxt=id)
  422. elif flag == '道长在线直播':
  423. # _url = id
  424. title = id.split('||')[0] # 获取标题
  425. _url = f'https://vdn.live.cntv.cn/api2/liveHtml5.do?channel=pc://cctv_p2p_hd{title}&channel_id={title}'
  426. htmlTxt = self.webReadFile(urlStr=_url, header=self.header)
  427. #htmlTxt = self.fetch(_url).text
  428. # print(htmlTxt)
  429. vdata = self.regStr(htmlTxt, "var .*?=.*?'(.*?)';")
  430. vdata = self.str2json(vdata)
  431. print(vdata)
  432. url = vdata['hls_url']['hls1']
  433. print(url)
  434. url = self.fixm3u8_url(url)
  435. else:
  436. try:
  437. html = self.webReadFile(urlStr=id, header=self.header)
  438. #htmlTxt = self.fetch(id).text
  439. guid = self.get_RegexGetText(Text=html, RegexText=r'var\sguid\s*=\s*"(.+?)";', Index=1)
  440. url = self.get_m3u8(urlTxt=guid)
  441. except:
  442. url = id
  443. parse = 1
  444. if url.find('https:') < 0:
  445. url = id
  446. parse = 1
  447. result["parse"] = parse # 1=嗅探,0=播放
  448. result["playUrl"] = ''
  449. result["url"] = url
  450. result["header"] = headers
  451. return result
  452. # 分类抓取地址:
  453. # 栏目大全:https://tv.cctv.com/lm/index.shtml?spm=C28340.Pu9TN9YUsfNZ.E2PQtIunpEaz.24
  454. # 电视剧:https://tv.cctv.com/yxg/index.shtml?spm=C28340.PlFTqGe6Zk8M.E2PQtIunpEaz.65#datacid=dsj&datafl=&datadq=&fc=%E7%94%B5%E8%A7%86%E5%89%A7&datanf=&dataszm=
  455. # 动画片:https://tv.cctv.com/yxg/index.shtml?spm=C28340.PlFTqGe6Zk8M.E2PQtIunpEaz.65#datacid=dhp&datafl=&datadq=&fc=%E5%8A%A8%E7%94%BB%E7%89%87&dataszm=
  456. # 记录片:https://tv.cctv.com/yxg/index.shtml?spm=C28340.PlFTqGe6Zk8M.E2PQtIunpEaz.65#datacid=jlp&datapd=&datafl=&fc=%E7%BA%AA%E5%BD%95%E7%89%87&datanf=&dataszm=
  457. # 特别节目:https://tv.cctv.com/yxg/index.shtml?spm=C28340.PlFTqGe6Zk8M.E2PQtIunpEaz.65#datacid=tbjm&datapd=&datafl=&fc=%E7%89%B9%E5%88%AB%E8%8A%82%E7%9B%AE&datajr=&dataszm=
  458. config = {
  459. "player": {},
  460. "filter": {
  461. "电视剧": [
  462. {"key": "datafl-sc", "name": "类型",
  463. "value": [{"n": "全部", "v": ""}, {"n": "谍战", "v": "谍战"}, {"n": "悬疑", "v": "悬疑"},
  464. {"n": "刑侦", "v": "刑侦"}, {"n": "历史", "v": "历史"}, {"n": "古装", "v": "古装"},
  465. {"n": "武侠", "v": "武侠"}, {"n": "军旅", "v": "军旅"}, {"n": "战争", "v": "战争"},
  466. {"n": "喜剧", "v": "喜剧"}, {"n": "青春", "v": "青春"}, {"n": "言情", "v": "言情"},
  467. {"n": "偶像", "v": "偶像"}, {"n": "家庭", "v": "家庭"}, {"n": "年代", "v": "年代"},
  468. {"n": "革命", "v": "革命"}, {"n": "农村", "v": "农村"}, {"n": "都市", "v": "都市"},
  469. {"n": "其他", "v": "其他"}]},
  470. {"key": "datadq-area", "name": "地区",
  471. "value": [{"n": "全部", "v": ""}, {"n": "中国大陆", "v": "中国大陆"}, {"n": "中国香港", "v": "香港"},
  472. {"n": "美国", "v": "美国"}, {"n": "欧洲", "v": "欧洲"}, {"n": "泰国", "v": "泰国"}]},
  473. {"key": "datanf-year", "name": "年份",
  474. "value": [{"n": "全部", "v": ""}, {"n": "2023", "v": "2023"}, {"n": "2022", "v": "2022"},
  475. {"n": "2021", "v": "2021"}, {"n": "2020", "v": "2020"}, {"n": "2019", "v": "2019"},
  476. {"n": "2018", "v": "2018"}, {"n": "2017", "v": "2017"}, {"n": "2016", "v": "2016"},
  477. {"n": "2015", "v": "2015"}, {"n": "2014", "v": "2014"}, {"n": "2013", "v": "2013"},
  478. {"n": "2012", "v": "2012"}, {"n": "2011", "v": "2011"}, {"n": "2010", "v": "2010"},
  479. {"n": "2009", "v": "2009"}, {"n": "2008", "v": "2008"}, {"n": "2007", "v": "2007"},
  480. {"n": "2006", "v": "2006"}, {"n": "2005", "v": "2005"}, {"n": "2004", "v": "2004"},
  481. {"n": "2003", "v": "2003"}, {"n": "2002", "v": "2002"}, {"n": "2001", "v": "2001"},
  482. {"n": "2000", "v": "2000"}, {"n": "1999", "v": "1999"}, {"n": "1998", "v": "1998"},
  483. {"n": "1997", "v": "1997"}]},
  484. {"key": "dataszm-letter", "name": "字母",
  485. "value": [{"n": "全部", "v": ""}, {"n": "A", "v": "A"}, {"n": "C", "v": "C"}, {"n": "E", "v": "E"},
  486. {"n": "F", "v": "F"}, {"n": "G", "v": "G"}, {"n": "H", "v": "H"}, {"n": "I", "v": "I"},
  487. {"n": "J", "v": "J"}, {"n": "K", "v": "K"}, {"n": "L", "v": "L"}, {"n": "M", "v": "M"},
  488. {"n": "N", "v": "N"}, {"n": "O", "v": "O"}, {"n": "P", "v": "P"}, {"n": "Q", "v": "Q"},
  489. {"n": "R", "v": "R"}, {"n": "S", "v": "S"}, {"n": "T", "v": "T"}, {"n": "U", "v": "U"},
  490. {"n": "V", "v": "V"}, {"n": "W", "v": "W"}, {"n": "X", "v": "X"}, {"n": "Y", "v": "Y"},
  491. {"n": "Z", "v": "Z"}, {"n": "0-9", "v": "0-9"}]}
  492. ],
  493. "动画片": [
  494. {"key": "datafl-sc", "name": "类型",
  495. "value": [{"n": "全部", "v": ""}, {"n": "亲子", "v": "亲子"}, {"n": "搞笑", "v": "搞笑"},
  496. {"n": "冒险", "v": "冒险"}, {"n": "动作", "v": "动作"}, {"n": "宠物", "v": "宠物"},
  497. {"n": "体育", "v": "体育"}, {"n": "益智", "v": "益智"}, {"n": "历史", "v": "历史"},
  498. {"n": "教育", "v": "教育"}, {"n": "校园", "v": "校园"}, {"n": "言情", "v": "言情"},
  499. {"n": "武侠", "v": "武侠"}, {"n": "经典", "v": "经典"}, {"n": "未来", "v": "未来"},
  500. {"n": "古代", "v": "古代"}, {"n": "神话", "v": "神话"}, {"n": "真人", "v": "真人"},
  501. {"n": "励志", "v": "励志"}, {"n": "热血", "v": "热血"}, {"n": "奇幻", "v": "奇幻"},
  502. {"n": "童话", "v": "童话"}, {"n": "剧情", "v": "剧情"}, {"n": "夺宝", "v": "夺宝"},
  503. {"n": "其他", "v": "其他"}]},
  504. {"key": "datadq-area", "name": "地区",
  505. "value": [{"n": "全部", "v": ""}, {"n": "中国大陆", "v": "中国大陆"}, {"n": "美国", "v": "美国"},
  506. {"n": "欧洲", "v": "欧洲"}]},
  507. {"key": "dataszm-letter", "name": "字母",
  508. "value": [{"n": "全部", "v": ""}, {"n": "A", "v": "A"}, {"n": "C", "v": "C"}, {"n": "E", "v": "E"},
  509. {"n": "F", "v": "F"}, {"n": "G", "v": "G"}, {"n": "H", "v": "H"}, {"n": "I", "v": "I"},
  510. {"n": "J", "v": "J"}, {"n": "K", "v": "K"}, {"n": "L", "v": "L"}, {"n": "M", "v": "M"},
  511. {"n": "N", "v": "N"}, {"n": "O", "v": "O"}, {"n": "P", "v": "P"}, {"n": "Q", "v": "Q"},
  512. {"n": "R", "v": "R"}, {"n": "S", "v": "S"}, {"n": "T", "v": "T"}, {"n": "U", "v": "U"},
  513. {"n": "V", "v": "V"}, {"n": "W", "v": "W"}, {"n": "X", "v": "X"}, {"n": "Y", "v": "Y"},
  514. {"n": "Z", "v": "Z"}, {"n": "0-9", "v": "0-9"}]}
  515. ],
  516. "纪录片": [
  517. {"key": "datapd-channel", "name": "频道",
  518. "value": [{"n": "全部", "v": ""}, {"n": "CCTV{1 综合", "v": "CCTV{1 综合"},
  519. {"n": "CCTV{2 财经", "v": "CCTV{2 财经"}, {"n": "CCTV{3 综艺", "v": "CCTV{3 综艺"},
  520. {"n": "CCTV{4 中文国际", "v": "CCTV{4 中文国际"}, {"n": "CCTV{5 体育", "v": "CCTV{5 体育"},
  521. {"n": "CCTV{6 电影", "v": "CCTV{6 电影"}, {"n": "CCTV{7 国防军事", "v": "CCTV{7 国防军事"},
  522. {"n": "CCTV{8 电视剧", "v": "CCTV{8 电视剧"}, {"n": "CCTV{9 纪录", "v": "CCTV{9 纪录"},
  523. {"n": "CCTV{10 科教", "v": "CCTV{10 科教"}, {"n": "CCTV{11 戏曲", "v": "CCTV{11 戏曲"},
  524. {"n": "CCTV{12 社会与法", "v": "CCTV{12 社会与法"},
  525. {"n": "CCTV{13 新闻", "v": "CCTV{13 新闻"}, {"n": "CCTV{14 少儿", "v": "CCTV{14 少儿"},
  526. {"n": "CCTV{15 音乐", "v": "CCTV{15 音乐"},
  527. {"n": "CCTV{17 农业农村", "v": "CCTV{17 农业农村"}]},
  528. {"key": "datafl-sc", "name": "类型",
  529. "value": [{"n": "全部", "v": ""}, {"n": "人文历史", "v": "人文历史"}, {"n": "人物", "v": "人物"},
  530. {"n": "军事", "v": "军事"}, {"n": "探索", "v": "探索"}, {"n": "社会", "v": "社会"},
  531. {"n": "时政", "v": "时政"}, {"n": "经济", "v": "经济"}, {"n": "科技", "v": "科技"}]},
  532. {"key": "datanf-year", "name": "年份",
  533. "value": [{"n": "全部", "v": ""}, {"n": "2023", "v": "2023"}, {"n": "2022", "v": "2022"},
  534. {"n": "2021", "v": "2021"}, {"n": "2020", "v": "2020"}, {"n": "2019", "v": "2019"},
  535. {"n": "2018", "v": "2018"}, {"n": "2017", "v": "2017"}, {"n": "2016", "v": "2016"},
  536. {"n": "2015", "v": "2015"}, {"n": "2014", "v": "2014"}, {"n": "2013", "v": "2013"},
  537. {"n": "2012", "v": "2012"}, {"n": "2011", "v": "2011"}, {"n": "2010", "v": "2010"},
  538. {"n": "2009", "v": "2009"}, {"n": "2008", "v": "2008"}]},
  539. {"key": "dataszm-letter", "name": "字母",
  540. "value": [{"n": "全部", "v": ""}, {"n": "A", "v": "A"}, {"n": "C", "v": "C"}, {"n": "E", "v": "E"},
  541. {"n": "F", "v": "F"}, {"n": "G", "v": "G"}, {"n": "H", "v": "H"}, {"n": "I", "v": "I"},
  542. {"n": "J", "v": "J"}, {"n": "K", "v": "K"}, {"n": "L", "v": "L"}, {"n": "M", "v": "M"},
  543. {"n": "N", "v": "N"}, {"n": "O", "v": "O"}, {"n": "P", "v": "P"}, {"n": "Q", "v": "Q"},
  544. {"n": "R", "v": "R"}, {"n": "S", "v": "S"}, {"n": "T", "v": "T"}, {"n": "U", "v": "U"},
  545. {"n": "V", "v": "V"}, {"n": "W", "v": "W"}, {"n": "X", "v": "X"}, {"n": "Y", "v": "Y"},
  546. {"n": "Z", "v": "Z"}, {"n": "0-9", "v": "0-9"}]}
  547. ],
  548. "特别节目": [
  549. {"key": "datapd-channel", "name": "频道",
  550. "value": [{"n": "全部", "v": ""}, {"n": "CCTV{1 综合", "v": "CCTV{1 综合"},
  551. {"n": "CCTV{2 财经", "v": "CCTV{2 财经"}, {"n": "CCTV{3 综艺", "v": "CCTV{3 综艺"},
  552. {"n": "CCTV{4 中文国际", "v": "CCTV{4 中文国际"}, {"n": "CCTV{5 体育", "v": "CCTV{5 体育"},
  553. {"n": "CCTV{6 电影", "v": "CCTV{6 电影"}, {"n": "CCTV{7 国防军事", "v": "CCTV{7 国防军事"},
  554. {"n": "CCTV{8 电视剧", "v": "CCTV{8 电视剧"}, {"n": "CCTV{9 纪录", "v": "CCTV{9 纪录"},
  555. {"n": "CCTV{10 科教", "v": "CCTV{10 科教"}, {"n": "CCTV{11 戏曲", "v": "CCTV{11 戏曲"},
  556. {"n": "CCTV{12 社会与法", "v": "CCTV{12 社会与法"},
  557. {"n": "CCTV{13 新闻", "v": "CCTV{13 新闻"}, {"n": "CCTV{14 少儿", "v": "CCTV{14 少儿"},
  558. {"n": "CCTV{15 音乐", "v": "CCTV{15 音乐"},
  559. {"n": "CCTV{17 农业农村", "v": "CCTV{17 农业农村"}]},
  560. {"key": "datafl-sc", "name": "类型",
  561. "value": [{"n": "全部", "v": ""}, {"n": "全部", "v": "全部"}, {"n": "新闻", "v": "新闻"},
  562. {"n": "经济", "v": "经济"}, {"n": "综艺", "v": "综艺"}, {"n": "体育", "v": "体育"},
  563. {"n": "军事", "v": "军事"}, {"n": "影视", "v": "影视"}, {"n": "科教", "v": "科教"},
  564. {"n": "戏曲", "v": "戏曲"}, {"n": "青少", "v": "青少"}, {"n": "音乐", "v": "音乐"},
  565. {"n": "社会", "v": "社会"}, {"n": "公益", "v": "公益"}, {"n": "其他", "v": "其他"}]},
  566. {"key": "dataszm-letter", "name": "字母",
  567. "value": [{"n": "全部", "v": ""}, {"n": "A", "v": "A"}, {"n": "C", "v": "C"}, {"n": "E", "v": "E"},
  568. {"n": "F", "v": "F"}, {"n": "G", "v": "G"}, {"n": "H", "v": "H"}, {"n": "I", "v": "I"},
  569. {"n": "J", "v": "J"}, {"n": "K", "v": "K"}, {"n": "L", "v": "L"}, {"n": "M", "v": "M"},
  570. {"n": "N", "v": "N"}, {"n": "O", "v": "O"}, {"n": "P", "v": "P"}, {"n": "Q", "v": "Q"},
  571. {"n": "R", "v": "R"}, {"n": "S", "v": "S"}, {"n": "T", "v": "T"}, {"n": "U", "v": "U"},
  572. {"n": "V", "v": "V"}, {"n": "W", "v": "W"}, {"n": "X", "v": "X"}, {"n": "Y", "v": "Y"},
  573. {"n": "Z", "v": "Z"}, {"n": "0-9", "v": "0-9"}]}
  574. ],
  575. "栏目大全": [{"key": "cid", "name": "频道",
  576. "value": [{"n": "全部", "v": ""}, {"n": "CCTV-1综合", "v": "EPGC1386744804340101"},
  577. {"n": "CCTV-2财经", "v": "EPGC1386744804340102"},
  578. {"n": "CCTV-3综艺", "v": "EPGC1386744804340103"},
  579. {"n": "CCTV-4中文国际", "v": "EPGC1386744804340104"},
  580. {"n": "CCTV-5体育", "v": "EPGC1386744804340107"},
  581. {"n": "CCTV-6电影", "v": "EPGC1386744804340108"},
  582. {"n": "CCTV-7国防军事", "v": "EPGC1386744804340109"},
  583. {"n": "CCTV-8电视剧", "v": "EPGC1386744804340110"},
  584. {"n": "CCTV-9纪录", "v": "EPGC1386744804340112"},
  585. {"n": "CCTV-10科教", "v": "EPGC1386744804340113"},
  586. {"n": "CCTV-11戏曲", "v": "EPGC1386744804340114"},
  587. {"n": "CCTV-12社会与法", "v": "EPGC1386744804340115"},
  588. {"n": "CCTV-13新闻", "v": "EPGC1386744804340116"},
  589. {"n": "CCTV-14少儿", "v": "EPGC1386744804340117"},
  590. {"n": "CCTV-15音乐", "v": "EPGC1386744804340118"},
  591. {"n": "CCTV-16奥林匹克", "v": "EPGC1634630207058998"},
  592. {"n": "CCTV-17农业农村", "v": "EPGC1563932742616872"},
  593. {"n": "CCTV-5+体育赛事", "v": "EPGC1468294755566101"}]},
  594. {"key": "fc", "name": "分类",
  595. "value": [{"n": "全部", "v": ""}, {"n": "新闻", "v": "新闻"}, {"n": "体育", "v": "体育"},
  596. {"n": "综艺", "v": "综艺"}, {"n": "健康", "v": "健康"}, {"n": "生活", "v": "生活"},
  597. {"n": "科教", "v": "科教"}, {"n": "经济", "v": "经济"}, {"n": "农业", "v": "农业"},
  598. {"n": "法治", "v": "法治"}, {"n": "军事", "v": "军事"}, {"n": "少儿", "v": "少儿"},
  599. {"n": "动画", "v": "动画"}, {"n": "纪实", "v": "纪实"}, {"n": "戏曲", "v": "戏曲"},
  600. {"n": "音乐", "v": "音乐"}, {"n": "影视", "v": "影视"}]},
  601. {"key": "fl", "name": "字母",
  602. "value": [{"n": "全部", "v": ""}, {"n": "A", "v": "A"}, {"n": "B", "v": "B"},
  603. {"n": "C", "v": "C"}, {"n": "D", "v": "D"}, {"n": "E", "v": "E"},
  604. {"n": "F", "v": "F"}, {"n": "G", "v": "G"}, {"n": "H", "v": "H"},
  605. {"n": "I", "v": "I"}, {"n": "J", "v": "J"}, {"n": "K", "v": "K"},
  606. {"n": "L", "v": "L"}, {"n": "M", "v": "M"}, {"n": "N", "v": "N"},
  607. {"n": "O", "v": "O"}, {"n": "P", "v": "P"}, {"n": "Q", "v": "Q"},
  608. {"n": "R", "v": "R"}, {"n": "S", "v": "S"}, {"n": "T", "v": "T"},
  609. {"n": "U", "v": "U"}, {"n": "V", "v": "V"}, {"n": "W", "v": "W"},
  610. {"n": "X", "v": "X"}, {"n": "Y", "v": "Y"}, {"n": "Z", "v": "Z"}]},
  611. {"key": "year", "name": "年份",
  612. "value": [{"n": "全部", "v": ""}, {"n": "2022", "v": "2022"}, {"n": "2021", "v": "2021"},
  613. {"n": "2020", "v": "2020"}, {"n": "2019", "v": "2019"}, {"n": "2018", "v": "2018"},
  614. {"n": "2017", "v": "2017"}, {"n": "2016", "v": "2016"}, {"n": "2015", "v": "2015"},
  615. {"n": "2014", "v": "2014"}, {"n": "2013", "v": "2013"}, {"n": "2012", "v": "2012"},
  616. {"n": "2011", "v": "2011"}, {"n": "2010", "v": "2010"}, {"n": "2009", "v": "2009"},
  617. {"n": "2008", "v": "2008"}, {"n": "2007", "v": "2007"}, {"n": "2006", "v": "2006"},
  618. {"n": "2005", "v": "2005"}, {"n": "2004", "v": "2004"}, {"n": "2003", "v": "2003"},
  619. {"n": "2002", "v": "2002"}, {"n": "2001", "v": "2001"},
  620. {"n": "2000", "v": "2000"}]}, {"key": "month", "name": "月份",
  621. "value": [{"n": "全部", "v": ""},
  622. {"n": "12", "v": "12"},
  623. {"n": "11", "v": "11"},
  624. {"n": "10", "v": "10"},
  625. {"n": "09", "v": "09"},
  626. {"n": "08", "v": "08"},
  627. {"n": "07", "v": "07"},
  628. {"n": "06", "v": "06"},
  629. {"n": "05", "v": "05"},
  630. {"n": "04", "v": "04"},
  631. {"n": "03", "v": "03"},
  632. {"n": "02", "v": "02"},
  633. {"n": "01", "v": "01"}]}]
  634. }
  635. }
  636. header = {
  637. "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",
  638. "Host": "tv.cctv.com",
  639. "Referer": "https://tv.cctv.com/"
  640. }
  641. def localProxy(self, param):
  642. return [200, "video/MP2T", action, ""]
  643. # -----------------------------------------------自定义函数-----------------------------------------------
  644. # 访问网页
  645. def webReadFile(self, urlStr, header):
  646. html = ''
  647. req = urllib.request.Request(url=urlStr) # ,headers=header
  648. with urllib.request.urlopen(req) as response:
  649. html = response.read().decode('utf-8')
  650. return html
  651. # 判断网络地址是否存在
  652. def TestWebPage(self, urlStr, header):
  653. html = ''
  654. req = urllib.request.Request(url=urlStr, method='HEAD') # ,headers=header
  655. with urllib.request.urlopen(req) as response:
  656. html = response.getcode()
  657. return html
  658. # 正则取文本
  659. def get_RegexGetText(self, Text, RegexText, Index):
  660. returnTxt = ""
  661. Regex = re.search(RegexText, Text, re.M | re.S)
  662. if Regex is None:
  663. returnTxt = ""
  664. else:
  665. returnTxt = Regex.group(Index)
  666. return returnTxt
  667. # 取集数
  668. def get_EpisodesList(self, jsonList):
  669. videos = []
  670. for vod in jsonList:
  671. url = vod['guid']
  672. title = vod['title']
  673. if len(url) == 0:
  674. continue
  675. videos.append(title + "$" + url)
  676. return videos
  677. # 取集数
  678. def get_EpisodesList_re(self, htmlTxt, patternTxt):
  679. ListRe = re.finditer(patternTxt, htmlTxt, re.M | re.S)
  680. videos = []
  681. for vod in ListRe:
  682. url = vod.group('url')
  683. title = vod.group('title')
  684. if len(url) == 0:
  685. continue
  686. videos.append(title + "$" + url)
  687. return videos
  688. # 取剧集区
  689. def get_lineList(self, Txt, mark, after):
  690. circuit = []
  691. origin = Txt.find(mark)
  692. while origin > 8:
  693. end = Txt.find(after, origin)
  694. circuit.append(Txt[origin:end])
  695. origin = Txt.find(mark, end)
  696. return circuit
  697. # 正则取文本,返回数组
  698. def get_RegexGetTextLine(self, Text, RegexText, Index):
  699. returnTxt = []
  700. pattern = re.compile(RegexText, re.M | re.S)
  701. ListRe = pattern.findall(Text)
  702. if len(ListRe) < 1:
  703. return returnTxt
  704. for value in ListRe:
  705. returnTxt.append(value)
  706. return returnTxt
  707. # 删除html标签
  708. def removeHtml(self, txt):
  709. soup = re.compile(r'<[^>]+>', re.S)
  710. txt = soup.sub('', txt)
  711. return txt.replace("&nbsp;", " ")
  712. def hookM3u8(self, url):
  713. """
  714. https://www.52pojie.cn/thread-1932358-1-1.html
  715. JavaScript:$.ajaxSettings.async = false; var s = ""; let a = $.get(vodh5player.playerList[0].ads.contentSrc); for (var m = 0; m < a.responseText.match(/asp.*?m3u8/g).length; m++) { s = s + "https://hls.cntv.myalicdn.com//asp" + a.responseText.match(/asp.*?m3u8/g)[m].slice(7) + "\n\n" }; var blob = new Blob([s], { type: "text/plain" }); var url = URL.createObjectURL(blob); window.open(url);
  716. @param url:
  717. @return:
  718. """
  719. url = url or ''
  720. hook1 = lambda x: x.replace('asp/', 'asp//', 1)
  721. hook2 = lambda x: x.replace('hls/', 'hls//', 1)
  722. hook3 = lambda x: x.replace('https://newcntv.qcloudcdn.com', 'https://hls.cntv.myalicdn.com/', 1)
  723. hooks = [hook1, hook2, hook3]
  724. hook = random.choice(hooks)
  725. return hook(url)
  726. # 取m3u8
  727. def get_m3u8(self, urlTxt):
  728. """
  729. https://blog.csdn.net/panwang666/article/details/135347859
  730. JavaScript:jQuery.getJSON("https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid="+guid,function(result){document.writeln(result.hls_url.link(result.hls_url));});
  731. https://newcntv.qcloudcdn.com/asp/hls/main/0303000a/3/default/3628bb15af644f588dc91ec68425b9ac/main.m3u8?maxbr=2048
  732. @param urlTxt:
  733. @return:
  734. """
  735. url = "https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={0}".format(urlTxt)
  736. # htmlTxt = self.webReadFile(urlStr=url, header=self.header)
  737. htmlTxt = self.fetch(url).text
  738. jo = json.loads(htmlTxt)
  739. link = jo['hls_url'].strip()
  740. # print('hls_url:',link)
  741. # 获取域名前缀
  742. urlPrefix = self.get_RegexGetText(Text=link, RegexText='(http[s]?://[a-zA-z0-9.]+)/', Index=1)
  743. # 域名前缀指定替换,然后可以获取到更高质量的视频列表
  744. # /asp/h5e/hls/2000/0303000a/3/default/3628bb15af644f588dc91ec68425b9ac/2000.m3u8
  745. new_link = link.replace(f'{urlPrefix}/asp/hls/', 'https://dh5.cntv.qcloudcdn.com/asp/h5e/hls/').split('?')[0]
  746. # print('new_link:',new_link)
  747. html = self.webReadFile(urlStr=new_link, header=self.header)
  748. content = html.strip()
  749. arr = content.split('\n')
  750. subUrl = arr[-1].split('/')
  751. # hdUrl = urlPrefix + arr[-1]
  752. # subUrl[3] = '2000'
  753. # subUrl[-1] = '2000.m3u8'
  754. # hdUrl = urlPrefix + '/'.join(subUrl)
  755. maxVideo = subUrl[-1].replace('.m3u8', '')
  756. hdUrl = link.replace('main', maxVideo)
  757. hdUrl = hdUrl.replace(urlPrefix, 'https://newcntv.qcloudcdn.com')
  758. hdRsp = self.TestWebPage(urlStr=hdUrl, header=self.header)
  759. if hdRsp == 200:
  760. url = hdUrl.split('?')[0]
  761. url = self.hookM3u8(url)
  762. self.log(f'视频链接: {url}')
  763. else:
  764. url = ''
  765. return url
  766. def fixm3u8_url(self, url):
  767. # 获取域名前缀
  768. urlPrefix = self.get_RegexGetText(Text=url, RegexText='(http[s]?://[a-zA-z0-9.]+)/', Index=1)
  769. # 域名前缀指定替换,然后可以获取到更高质量的视频列表
  770. new_link = url.split('?')[0]
  771. # print(new_link)
  772. html = self.webReadFile(urlStr=new_link, header=self.header)
  773. content = html.strip()
  774. # print(content)
  775. arr = content.split('\n')
  776. subUrl = arr[3] if 'EXT-X-VERSION' in content else arr[2]
  777. hdUrl = self.urljoin(new_link, subUrl).split('?')[0]
  778. # hdUrl = hdUrl.replace(urlPrefix, 'https://newcntv.qcloudcdn.com')
  779. hdRsp = self.TestWebPage(urlStr=hdUrl, header=self.header)
  780. if hdRsp == 200:
  781. url = hdUrl
  782. self.log(f'视频链接: {url}')
  783. else:
  784. url = ''
  785. return url
  786. # 搜索
  787. def get_list_search(self, html, tid):
  788. jRoot = json.loads(html)
  789. jsonList = jRoot['list']
  790. videos = []
  791. for vod in jsonList:
  792. url = vod['urllink']
  793. title = self.removeHtml(txt=vod['title'])
  794. img = vod['imglink']
  795. id = vod['id']
  796. brief = vod['channel']
  797. year = vod['uploadtime']
  798. if len(url) == 0:
  799. continue
  800. guids = [tid, title, url, img, id, year, '', brief]
  801. guid = "||".join(guids)
  802. videos.append({
  803. "vod_id": guid,
  804. "vod_name": title,
  805. "vod_pic": img,
  806. "vod_remarks": year
  807. })
  808. return videos
  809. def get_list1(self, html, tid):
  810. jRoot = json.loads(html)
  811. videos = []
  812. data = jRoot['response']
  813. if data is None:
  814. return []
  815. jsonList = data['docs']
  816. for vod in jsonList:
  817. id = vod['lastVIDE']['videoSharedCode']
  818. desc = vod['lastVIDE']['videoTitle']
  819. title = vod['column_name']
  820. url = vod['column_website']
  821. img = vod['column_logo']
  822. year = vod['column_playdate']
  823. brief = vod['column_brief']
  824. actors = ''
  825. if len(url) == 0:
  826. continue
  827. guids = [tid, title, url, img, id, year, actors, brief]
  828. guid = "||".join(guids)
  829. # print(vod_id)
  830. videos.append({
  831. "vod_id": guid,
  832. "vod_name": title,
  833. "vod_pic": img,
  834. "vod_remarks": desc.split('》')[1].strip() if '》' in desc else desc.strip()
  835. })
  836. # print(videos)
  837. return videos
  838. # 分类取结果
  839. def get_list(self, html, tid):
  840. jRoot = json.loads(html)
  841. videos = []
  842. data = jRoot['data']
  843. if data is None:
  844. return []
  845. jsonList = data['list']
  846. for vod in jsonList:
  847. url = vod['url']
  848. title = vod['title']
  849. img = vod['image']
  850. id = vod['id']
  851. try:
  852. brief = vod['brief']
  853. except:
  854. brief = ''
  855. try:
  856. year = vod['year']
  857. except:
  858. year = ''
  859. try:
  860. actors = vod['actors']
  861. except:
  862. actors = ''
  863. if len(url) == 0:
  864. continue
  865. guids = [tid, title, url, img, id, year, actors, brief]
  866. guid = "||".join(guids)
  867. # print(vod_id)
  868. videos.append({
  869. "vod_id": guid,
  870. "vod_name": title,
  871. "vod_pic": img,
  872. "vod_remarks": ''
  873. })
  874. return videos
  875. if __name__ == '__main__':
  876. spider = Spider()
  877. spider.init()
  878. spider.init_api_ext_file()
  879. # home_content = spider.homeContent(None)
  880. # print(home_content)
  881. # cate_content = spider.categoryContent('栏目大全', 1, {'cid': 'n'}, {})
  882. # print(cate_content)
  883. # vid = cate_content['list'][0]['vod_id']
  884. # print(vid)
  885. # detail_content = spider.detailContent([vid])
  886. # print(detail_content)
  887. #
  888. # vod_play_from = detail_content['list'][0]['vod_play_from']
  889. # vod_play_url = detail_content['list'][0]['vod_play_url']
  890. # print(vod_play_from, vod_play_url)
  891. # _url = vod_play_url.split('#')[0].split('$')[1]
  892. # print(_url)
  893. # play = spider.playerContent(vod_play_from, _url, None)
  894. # print(play)