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,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