Skip to content

Commit

Permalink
更新央视筛选
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdhnx committed Jan 14, 2024
1 parent 5b4fb26 commit 58f0066
Showing 1 changed file with 68 additions and 5 deletions.
73 changes: 68 additions & 5 deletions txt/hipy/cntv央视.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ def homeContent(self, filter):
"特别节目": "特别节目",
"纪录片": "纪录片",
"电视剧": "电视剧",
"动画片": "动画片"
"动画片": "动画片",
"频道直播": "频道直播",

}
classes = []
for k in cateManual:
Expand Down Expand Up @@ -364,6 +366,8 @@ def categoryContent(self, tid, pg, filter, extend):
url = 'https://api.cntv.cn/NewVideo/getLastVideoList4K?serviceId=cctv4k&cid={0}&p={1}&n={2}&t=json&cb=ko'.format(
cid, pg, pagecount
)
elif tid == '频道直播':
url = 'https://tv.cctv.com/epg/index.shtml'
else:
url = 'https://tv.cctv.com/epg/index.shtml'

Expand All @@ -379,6 +383,19 @@ def categoryContent(self, tid, pg, filter, extend):
if index > -1:
htmlText = htmlText[3:index]
videos = self.get_list_4k(html=htmlText, tid=tid)
elif tid == '频道直播':
html = self.html(htmlText)
lis = html.xpath('//*[@id="jiemudan01"]//div[contains(@class,"channel_con")]//ul/li')
for li in lis:
vid = ''.join(li.xpath('./img/@title'))
pic = ''.join(li.xpath('./img/@src'))
pic = self.urljoin('https://tv.cctv.com/epg/index.shtml', pic)
videos.append({
'vod_id': '||'.join([tid, vid, f'https://tv.cctv.com/live/{vid}/', pic]),
'vod_name': vid,
'vod_pic': pic,
'vod_mark': '',
})

else:
videos = self.get_list(html=htmlText, tid=tid)
Expand All @@ -400,9 +417,21 @@ def detailContent(self, array):
did = did.split('$$$')[1]
aid = did.split('||')
tid = aid[0]
logo = aid[3]
lastVideo = aid[2]
title = aid[1]
lastVideo = aid[2]
logo = aid[3]
if tid == '频道直播':
vod = {
"vod_id": did,
"vod_name": title.replace(' ', ''),
"vod_pic": logo,
"vod_content": f'频道{title}正在直播中',
"vod_play_from": '道长在线直播',
"vod_play_url": f'在线观看${title}||{lastVideo}',
}
result = {'list': [vod]}
return result

id = aid[4]

vod_year = aid[5]
Expand Down Expand Up @@ -469,7 +498,7 @@ def detailContent(self, array):
if len(videoList) == 0:
return {}
vod = {
"vod_id": array[0],
"vod_id": did,
"vod_name": title.replace(' ', ''),
"vod_pic": logo,
"type_name": tid,
Expand Down Expand Up @@ -529,6 +558,18 @@ def playerContent(self, flag, id, vipFlags):
}
if flag == 'CCTV':
url = self.get_m3u8(urlTxt=id)
elif flag == '道长在线直播':
# _url = id
title = id.split('||')[0] # 获取标题
_url = f'https://vdn.live.cntv.cn/api2/liveHtml5.do?channel=pc:https://cctv_p2p_hd{title}&channel_id={title}'
htmlTxt = self.fetch(_url).text
# print(htmlTxt)
vdata = self.regStr(htmlTxt, "var .*?=.*?'(.*?)';")
vdata = self.str2json(vdata)
print(vdata)
url = vdata['hls_url']['hls1']
print(url)
url = self.fixm3u8_url(url)
else:
try:
# htmlTxt = self.webReadFile(urlStr=id, header=self.header)
Expand Down Expand Up @@ -806,6 +847,27 @@ def get_m3u8(self, urlTxt):
url = ''
return url

def fixm3u8_url(self, url):
# 获取域名前缀
urlPrefix = self.get_RegexGetText(Text=url, RegexText='(http[s]?:https://[a-zA-z0-9.]+)/', Index=1)
# 域名前缀指定替换,然后可以获取到更高质量的视频列表
new_link = url.split('?')[0]
# print(new_link)
html = self.webReadFile(urlStr=new_link, header=self.header)
content = html.strip()
# print(content)
arr = content.split('\n')
subUrl = arr[3] if 'EXT-X-VERSION' in content else arr[2]
hdUrl = self.urljoin(new_link, subUrl).split('?')[0]
# hdUrl = hdUrl.replace(urlPrefix, 'https://newcntv.qcloudcdn.com')
hdRsp = self.TestWebPage(urlStr=hdUrl, header=self.header)
if hdRsp == 200:
url = hdUrl
self.log(f'视频链接: {url}')
else:
url = ''
return url

# 搜索
def get_list_search(self, html, tid):
jRoot = json.loads(html)
Expand Down Expand Up @@ -945,7 +1007,8 @@ def get_list_4k(self, html, tid):
# home_content = spider.homeContent(None)
# print(home_content)
# cate_content = spider.categoryContent('栏目大全', 1, {'cid': 'n'}, {})
# print(cate_content)
cate_content = spider.categoryContent('频道直播', 1, None, None)
print(cate_content)
# vid = cate_content['list'][0]['vod_id']
# print(vid)
# detail_content = spider.detailContent([vid])
Expand Down

0 comments on commit 58f0066

Please sign in to comment.