添加是否登录日志

This commit is contained in:
test
2025-12-12 19:46:22 +08:00
parent dcd069b4c4
commit 37dde4820c
6 changed files with 42 additions and 29 deletions

51
app.js
View File

@@ -4,7 +4,7 @@ import { readFileSync } from "./utils/fileUtil.js";
import { host, port, rateType, token, userId } from "./config.js";
import { getDateTimeStr } from "./utils/time.js";
import update from "./updateData.js";
import { printBlue, printGreen, printGrey, printMagenta, printRed, printYellow } from "./utils/colorOut.js";
import { printBlue, printDebug, printGreen, printGrey, printMagenta, printRed, printYellow } from "./utils/colorOut.js";
import { delay } from "./utils/fetchList.js";
// 运行时长
@@ -16,7 +16,6 @@ let loading = false
const server = http.createServer(async (req, res) => {
// console.dir(req, { depth: null })
while (loading) {
await delay(50)
}
@@ -134,16 +133,22 @@ const server = http.createServer(async (req, res) => {
const valTime = urlCache[pid].valTime - Date.now()
// 缓存是否有效
if (valTime >= 0) {
printGreen(`缓存有效,使用缓存数据`)
let playURL = urlCache[pid].url
let msg = "节目调整,暂不提供服务"
if (urlCache[pid].content != null) {
if (urlCache[pid].content.body.auth.logined) {
printGreen("登录认证成功")
if (urlCache[pid].content.body.auth.authResult == "FAIL") {
printRed(`认证失败 视频内容不完整 可能缺少相关VIP: ${urlCache[pid].content.body.auth.resultDesc}`)
}
} else {
printYellow("未登录")
}
msg = urlCache[pid].content.message
}
printGreen(`缓存有效,使用缓存数据`)
// 节目调整
if (playURL == "") {
let msg = "节目调整,暂不提供服务"
if (urlCache[pid].content != null) {
msg = urlCache[pid].content.message
}
printRed(`${pid} ${msg}`)
res.writeHead(200, { "Content-Type": "application/json;charset=UTF-8" })
@@ -187,9 +192,8 @@ const server = http.createServer(async (req, res) => {
loading = false
return
}
printDebug(`添加加密字段后链接 ${resObj.url}`)
// 直接访问g开头的域名链接时概率会302到不能播放的地址,目前不清楚原因,在这重定向正确地址
// printRed(resObj.url)
let changeFailed = false
if (resObj.url != "") {
let z = 1
@@ -204,12 +208,11 @@ const server = http.createServer(async (req, res) => {
const location = obj.headers.get("Location")
if (location == "" || location == undefined || location == null) {
continue
}
if (location.startsWith("http://hlsz") || location.startsWith("http://mgsp") || location.startsWith("http://trial")) {
resObj.url = location
break
if (location != "" && location != undefined && location != null) {
if (location.startsWith("http://hlsz") || location.startsWith("http://mgsp") || location.startsWith("http://trial")) {
resObj.url = location
break
}
}
if (z == 6) {
printYellow(`获取失败,返回原链接`)
@@ -220,7 +223,14 @@ const server = http.createServer(async (req, res) => {
z++
}
}
if (resObj.content.body.auth.logined) {
printGreen("登录认证成功")
if (resObj.content.body.auth.authResult == "FAIL") {
printRed(`认证失败 视频内容不完整 可能缺少相关VIP: ${resObj.content.body.auth.resultDesc}`)
}
} else {
printYellow("未登录")
}
// printRed(resObj.url)
printGreen(`添加节目缓存 ${pid}`)
// 缓存有效时长
@@ -240,7 +250,6 @@ const server = http.createServer(async (req, res) => {
url: resObj.url,
content: resObj.content,
}
// console.log(resObj.url)
if (resObj.url == "") {
let msg = "节目调整,暂不提供服务"
@@ -256,8 +265,6 @@ const server = http.createServer(async (req, res) => {
}
let playURL = resObj.url
// console.dir(playURL, { depth: null })
// 添加回放参数
if (params != "") {
const resultParams = new URLSearchParams(params);
@@ -289,7 +296,6 @@ server.listen(port, async () => {
} catch (error) {
printRed(error)
printRed("更新失败")
console.log(error)
}
printBlue(`当前已运行${hours}小时`)
@@ -301,7 +307,6 @@ server.listen(port, async () => {
} catch (error) {
printRed(error)
printRed("更新失败")
console.log(error)
}
printGreen("每3小时更新一次")

View File

@@ -13,5 +13,6 @@ const host = process.env.mhost || ""
const rateType = process.env.mrateType || 3
// 是否刷新token可能是导致封号的原因
// const refreshToken = process.env.mrefreshToken || true
const debug = process.env.mdebug || false
export { userId, token, port, host, rateType/* , refreshToken */ }
export { userId, token, port, host, rateType, debug/* , refreshToken */ }

View File

@@ -1,6 +1,6 @@
import { getStringMD5 } from "./EncryUtils.js";
import { getddCalcuURL, getddCalcuURL720p } from "./ddCalcuURL.js";
import { printYellow } from "./colorOut.js";
import { printDebug, printYellow } from "./colorOut.js";
/**
* @typedef {object} SaltSign
@@ -80,7 +80,7 @@ async function getAndroidURL(userId, token, pid, rateType) {
}).then(r => r.json())
}
// console.dir(respData, { depth: null })
printDebug(respData)
// console.log(respData)
const url = respData.body.urlInfo?.url
// console.log(rateType)
@@ -98,7 +98,6 @@ async function getAndroidURL(userId, token, pid, rateType) {
rateType = respData.body.urlInfo?.rateType
// console.log("清晰度" + rateType)
return {
url: resURL,
rateType: parseInt(rateType),
@@ -144,6 +143,7 @@ async function getAndroidURL720p(pid) {
headers: headers
}).then(r => r.json())
printDebug(respData)
// console.dir(respData, { depth: null })
const url = respData.body.urlInfo?.url
// console.log(rateType)

View File

@@ -1,3 +1,4 @@
import { debug } from "../config.js"
import { getLogDateTime } from "./time.js"
function basePrint(color, msg) {
@@ -27,7 +28,12 @@ function printMagenta(msg) {
function printGrey(msg) {
basePrint("\x1B[2m", msg)
}
function printDebug(obj) {
if (debug) {
console.dir(obj, { depth: null })
}
}
export {
printGreen, printBlue, printRed, printYellow, printMagenta, printGrey
printGreen, printBlue, printRed, printYellow, printMagenta, printGrey, printDebug
}

View File

@@ -1,5 +1,4 @@
// 睡眠
function delay(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms)

View File

@@ -1,3 +1,4 @@
import { printDebug } from "./colorOut.js";
import { AESencrypt, getStringMD5, RSAencrypt } from "./EncryUtils.js"
/**
@@ -57,6 +58,7 @@ async function refreshToken(userId, token) {
// console.log(respResult)
return true
}
console.dir(respResult, { depth: null })
return false
}