mirror of
https://github.com/develop202/migu_video.git
synced 2025-12-17 15:25:03 +08:00
每2小时更新一次,央视节目单从cntv获取
This commit is contained in:
@@ -1,3 +1,27 @@
|
||||
// 回放
|
||||
const cntvNames = {
|
||||
"CCTV1综合": "cctv1",
|
||||
"CCTV2财经": "cctv2",
|
||||
"CCTV3综艺": "cctv3",
|
||||
"CCTV4中文国际": "cctv4",
|
||||
"CCTV5体育": "cctv5",
|
||||
"CCTV5+体育赛事": "cctv5plus",
|
||||
"CCTV6电影": "cctv6",
|
||||
"CCTV7国防军事": "cctv7",
|
||||
"CCTV8电视剧": "cctv8",
|
||||
"CCTV9纪录": "cctv9",
|
||||
"CCTV10科教": "cctv10",
|
||||
"CCTV11戏曲": "cctv11",
|
||||
"CCTV12社会与法": "cctv12",
|
||||
"CCTV13新闻": "cctv13",
|
||||
"CCTV14少儿": "cctvchild",
|
||||
"CCTV15音乐": "cctv15",
|
||||
"CCTV17农业农村": "cctv17",
|
||||
"CCTV4欧洲": "cctveurope",
|
||||
"CCTV4美洲": "cctvamerica",
|
||||
}
|
||||
|
||||
|
||||
// 频道信息
|
||||
const channelName = [
|
||||
{
|
||||
@@ -823,4 +847,4 @@ const changedDdCalcu = {
|
||||
},
|
||||
}
|
||||
|
||||
export { changedDdCalcu, channelName }
|
||||
export { changedDdCalcu, channelName, cntvNames }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import axios from "axios"
|
||||
import { getDateString, getDateTimeString } from "./time.js"
|
||||
import { appendFileSync } from "./fileUtil.js"
|
||||
import { cntvNames } from "./datas.js"
|
||||
|
||||
|
||||
async function getPlaybackData(programId) {
|
||||
@@ -10,7 +11,7 @@ async function getPlaybackData(programId) {
|
||||
return resp.body?.program[0]?.content
|
||||
}
|
||||
|
||||
async function updatePlaybackData(program, filePath) {
|
||||
async function updatePlaybackDataByMigu(program, filePath) {
|
||||
// 今日节目数据
|
||||
const playbackData = await getPlaybackData(program.pID)
|
||||
if (!playbackData) {
|
||||
@@ -36,5 +37,45 @@ async function updatePlaybackData(program, filePath) {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async function updatePlaybackDataByCntv(program, filePath) {
|
||||
// 今日节目数据
|
||||
const date = new Date()
|
||||
const today = getDateString(date)
|
||||
const cntvName = cntvNames[program.name]
|
||||
const resp = await axios.get(`https://api.cntv.cn/epg/epginfo3?serviceId=shiyi&d=${today}&c=${cntvName}`).then(r => r.data)
|
||||
|
||||
const playbackData = resp[cntvName]?.program
|
||||
if (!playbackData) {
|
||||
return false
|
||||
}
|
||||
// 写入频道信息
|
||||
appendFileSync(filePath,
|
||||
` <channel id="${program.name}">\n` +
|
||||
` <display-name lang="zh">${program.name}</display-name>\n` +
|
||||
` </channel>\n`
|
||||
)
|
||||
|
||||
// 写入节目信息
|
||||
for (let i = 0; i < playbackData.length; i++) {
|
||||
// 特殊字符转义
|
||||
const contName = playbackData[i].t.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
||||
|
||||
appendFileSync(filePath,
|
||||
` <programme channel="${program.name}" start="${getDateTimeString(new Date(playbackData[i].st * 1000))} +0800" stop="${getDateTimeString(new Date(playbackData[i].et * 1000))} +0800">\n` +
|
||||
` <title lang="zh">${contName}</title>\n` +
|
||||
` </programme>\n`
|
||||
)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async function updatePlaybackData(program, filePath) {
|
||||
if (cntvNames[program.name]) {
|
||||
return updatePlaybackDataByCntv(program, filePath)
|
||||
}
|
||||
return updatePlaybackDataByMigu(program, filePath)
|
||||
|
||||
}
|
||||
export { updatePlaybackData }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user