复活失败,正在重试之域名白名单

This commit is contained in:
develop202
2026-01-15 21:49:04 +08:00
parent 4f64e1a390
commit ff435c2468
9 changed files with 6231 additions and 5072 deletions

View File

@@ -21,4 +21,26 @@ const cntvNames = {
"CCTV4美洲": "cctvamerica",
}
export { cntvNames }
// 域名白名单
const domainWhiteList = [
"tvpull.dxhmt.cn:9081",
"live.dxhmt.cn:9081",
"hlsztemgsplive.miguvideo.com:8080",
"play.kankanlive.com",
"ali-xwl.cztv.com",
"l.cztvcloud.com",
"live.ynurl.com",
"stream.hrbtv.net",
"play-a2.quklive.com",
"gxlive.snrtv.com",
"m3u8.channel.wsrtv.com.cn",
"jwcdnqx.hebyun.com.cn",
"nklive.nbs.cn",
"stream.thmz.com",
"pull-hls-f1.douyincdn.com",
"pull-flv-f1.douyincdn.com",
"pull-hs-f5.flive.douyincdn.com",
]
export { cntvNames, domainWhiteList }

View File

@@ -23,12 +23,12 @@ function getLocalIPv(ver = 4) {
return ips
}
async function fetchUrl(url, opts = {}) {
async function fetchUrl(url, opts = {}, timeout = 6000) {
const controller = new AbortController();
const timeoutId = setTimeout(() => {
controller.abort()
printRed("请求超时")
}, 6000);
}, timeout);
opts["signal"] = controller.signal
const res = await fetch(url, opts)
.then(r => r.json())

View File

@@ -4,16 +4,16 @@ import { cntvNames } from "./datas.js"
import { fetchUrl } from "./net.js"
async function getPlaybackData(programId) {
async function getPlaybackData(programId, timeout = 6000) {
const date = new Date()
const today = getDateString(date)
const resp = await fetchUrl(`https://program-sc.miguvideo.com/live/v2/tv-programs-data/${programId}/${today}`)
const resp = await fetchUrl(`https://program-sc.miguvideo.com/live/v2/tv-programs-data/${programId}/${today}`, {}, timeout)
return resp.body?.program[0]?.content
}
async function updatePlaybackDataByMigu(program, filePath) {
async function updatePlaybackDataByMigu(program, filePath, timeout = 6000) {
// 今日节目数据
const playbackData = await getPlaybackData(program.pID)
const playbackData = await getPlaybackData(program.pID, timeout)
if (!playbackData) {
return false
}
@@ -38,12 +38,12 @@ async function updatePlaybackDataByMigu(program, filePath) {
return true
}
async function updatePlaybackDataByCntv(program, filePath) {
async function updatePlaybackDataByCntv(program, filePath, timeout = 6000) {
// 今日节目数据
const date = new Date()
const today = getDateString(date)
const cntvName = cntvNames[program.name]
const resp = await fetchUrl(`https://api.cntv.cn/epg/epginfo3?serviceId=shiyi&d=${today}&c=${cntvName}`)
const resp = await fetchUrl(`https://api.cntv.cn/epg/epginfo3?serviceId=shiyi&d=${today}&c=${cntvName}`, {}, timeout)
const playbackData = resp[cntvName]?.program
if (!playbackData) {
@@ -70,11 +70,11 @@ async function updatePlaybackDataByCntv(program, filePath) {
return true
}
async function updatePlaybackData(program, filePath) {
async function updatePlaybackData(program, filePath, timeout = 6000) {
if (cntvNames[program.name]) {
return updatePlaybackDataByCntv(program, filePath)
return updatePlaybackDataByCntv(program, filePath, timeout)
}
return updatePlaybackDataByMigu(program, filePath)
return updatePlaybackDataByMigu(program, filePath, timeout)
}
export { updatePlaybackData }

View File

@@ -2,6 +2,8 @@ import { printGreen, printMagenta, printRed } from "./colorOut.js"
import crypto from "node:crypto"
import { writeFileSync } from "node:fs"
import { gunzipSync } from "node:zlib"
import { debug } from "../config.js"
import { domainWhiteList } from "./datas.js"
const KEY_ARRAY = [121, 111, 117, 33, 106, 101, 64, 49, 57, 114, 114, 36, 50, 48, 121, 35]
const IV_ARRAY = [65, 114, 101, 121, 111, 117, 124, 62, 127, 110, 54, 38, 13, 97, 110, 63]
@@ -20,9 +22,24 @@ function AESdecrypt(baseData, keyArray = KEY_ARRAY, ivArray = IV_ARRAY) {
return dest.toString()
}
/**
* @param {Array<String>} whiteList - 域名白名单
* @param {String} item - 域名
* @returns {Boolean} - 是否在白名单
*/
function isInWhiteList(whiteList, item) {
for (const white of whiteList) {
if (item == white) {
return true
}
}
return false
}
async function getAllURL() {
const channelsURLM3U = []
const channelsURLTXT = []
const domains = {}
let sumChannel = 0
const headers = { Referer: "http://pro.fengcaizb.com" }
await fetch("http://pro.fengcaizb.com/channels/pro.gz", {
@@ -68,25 +85,40 @@ async function getAllURL() {
// printYellow(`${i} ${channel?.title} 存在特殊字符, 过滤`)
continue
}
// 超时
const controller = new AbortController();
const timeoutId = setTimeout(() => {
controller.abort()
// console.log("请求超时")
}, 1200);
const test = await fetch(decryptURL, {
signal: controller.signal
})
.catch(_ => {
// console.log(err)
clearTimeout(timeoutId);
const domain = decryptURL.split("/")[2]
// 不在域名白名单
if (!isInWhiteList(domainWhiteList, domain)) {
// 超时
const controller = new AbortController();
const timeoutId = setTimeout(() => {
controller.abort()
// console.log("请求超时")
}, 1200);
const test = await fetch(decryptURL, {
signal: controller.signal
})
clearTimeout(timeoutId);
.catch(_ => {
// console.log(err)
clearTimeout(timeoutId);
})
clearTimeout(timeoutId);
if (!test?.ok) {
// let msg = test == undefined ? "请求超时" : "无法播放"
// printYellow(`${i} ${channel?.title} ${msg}, 过滤`)
continue
if (!test?.ok) {
// let msg = test == undefined ? "请求超时" : "无法播放"
// printYellow(`${i} ${channel?.title} ${msg}, 过滤`)
continue
}
if (debug) {
if (domains[domain]) {
domains[domain].times += 1
} else {
domains[domain] = {
value: domain,
times: 1
}
}
// console.log(domain)
}
}
const channelURLM3U = `#EXTINF:-1 tvg-id="${channel?.title}" tvg-name="${channel?.title}" tvg-logo="" group-title="${channel?.province}",${channel.title}\n${decryptURL}`
const channelURLTXT = `${channel?.title},${decryptURL}`
@@ -100,6 +132,13 @@ async function getAllURL() {
const m3u = channelsURLM3U.join("\n")
const txt = channelsURLTXT.join("\n")
printGreen(`本次共更新${sumChannel}`)
if (debug) {
Object.entries(domains)
.sort((a, b) => b[1].times - a[1].times)
.forEach(([_, item]) => {
console.log(`"${item.value}",次数: ${item.times}`)
})
}
return {
m3u: m3u,
txt: txt