cctv_spider.py 44 KB

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