mirror of
https://github.com/develop202/migu_video.git
synced 2025-12-16 23:09:37 +08:00
每2小时更新一次,央视节目单从cntv获取
This commit is contained in:
@@ -8,7 +8,7 @@ triggers:
|
||||
precise:
|
||||
- main
|
||||
schedule:
|
||||
- cron: '* 0 */3 * * ? *'
|
||||
- cron: '* 0 */2 * * ? *'
|
||||
variables:
|
||||
global:
|
||||
- GITHUB_TOKEN
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import { dataList } from "./utils/fetchList.js"
|
||||
import { getAndroidURL720p } from "./utils/androidURL.js"
|
||||
import refreshToken from "./utils/refreshToken.js"
|
||||
import { appendFile, writeFile } from "./utils/fileUtil.js"
|
||||
import { updatePlaybackData } from "./utils/playback.js"
|
||||
|
||||
async function fetchURLByAndroid() {
|
||||
|
||||
const userId = process.env.USERID
|
||||
const token = process.env.MIGU_TOKEN
|
||||
|
||||
const date = new Date()
|
||||
const start = date.getTime()
|
||||
const start = Date.now()
|
||||
|
||||
// 必须绝对路径
|
||||
const path = process.cwd() + '/interface.txt'
|
||||
@@ -26,13 +21,7 @@ async function fetchURLByAndroid() {
|
||||
`<?xml version="1.0" encoding="UTF-8"?>\n` +
|
||||
`<tv generator-info-name="Tak" generator-info-url="https://github.com/develop202/migu_video/">\n`)
|
||||
|
||||
if (!date.getHours()) {
|
||||
// 0点刷新token
|
||||
await refreshToken(userId, token) ? console.log("token刷新成功") : console.log("token刷新失败")
|
||||
}
|
||||
|
||||
// 写入开头
|
||||
// appendFile(aptvPath, `#EXTM3U x-tvg-url="https://gitee.com/dream-deve/migu_video/raw/main/playback.xml" catchup="append" catchup-source="&playbackbegin=\${(b)yyyyMMddHHmmss}&playbackend=\${(e)yyyyMMddHHmmss}"\n`)
|
||||
appendFile(path, `#EXTM3U x-tvg-url="https://develop202.github.io/migu_video/playback.xml,https://raw.githubusercontent.com/develop202/migu_video/refs/heads/main/playback.xml,https://gh-proxy.com/https://raw.githubusercontent.com/develop202/migu_video/refs/heads/main/playback.xml" catchup="append" catchup-source="&playbackbegin=\${(b)yyyyMMddHHmmss}&playbackend=\${(e)yyyyMMddHHmmss}"\n`)
|
||||
|
||||
// 分类列表
|
||||
|
||||
@@ -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