diff --git a/lib/mq/exec/snapshotTick.ts b/lib/mq/exec/snapshotTick.ts index e88f503..8fdd8d6 100644 --- a/lib/mq/exec/snapshotTick.ts +++ b/lib/mq/exec/snapshotTick.ts @@ -106,8 +106,13 @@ export const takeSnapshotForMilestoneVideoWorker = async (job: Job) => { const { aid, currentViews, snapshotedAt } = job.data; const lastSnapshoted = snapshotedAt; const stat = await insertVideoStats(client, aid, "snapshotMilestoneVideo"); - if (stat == null) { - await setSnapshotScheduled(aid, false, 0); + if (typeof stat === "number") { + if (stat === -404 || stat === 62002) { + await setSnapshotScheduled(aid, true, 6 * 60 * 60); + } + else { + await setSnapshotScheduled(aid, false, 0); + } return; } const nextMilestone = currentViews >= 100000 ? 1000000 : 100000; @@ -166,6 +171,15 @@ export const takeSnapshotForVideoWorker = async (job: Job) => { try { const { aid } = job.data; const stat = await insertVideoStats(client, aid, "getVideoInfo"); + if (typeof stat === "number") { + if (stat === -404 || stat === 62002) { + await setSnapshotScheduled(aid, true, 6 * 60 * 60); + } + else { + await setSnapshotScheduled(aid, false, 0); + } + return; + } logger.log(`Taken snapshot for ${aid}`, "mq"); if (stat == null) { setSnapshotScheduled(aid, false, 0); diff --git a/lib/mq/task/getVideoStats.ts b/lib/mq/task/getVideoStats.ts index dd9d1f4..274d1bb 100644 --- a/lib/mq/task/getVideoStats.ts +++ b/lib/mq/task/getVideoStats.ts @@ -4,8 +4,8 @@ import { getVideoInfo } from "lib/net/getVideoInfo.ts"; export async function insertVideoStats(client: Client, aid: number, task: string) { const data = await getVideoInfo(aid, task); const time = new Date().getTime(); - if (data === null) { - return null; + if (typeof data == 'number') { + return data; } const views = data.stat.view; const danmakus = data.stat.danmaku; diff --git a/lib/net/getVideoInfo.ts b/lib/net/getVideoInfo.ts index 5ccb8ec..c35bf56 100644 --- a/lib/net/getVideoInfo.ts +++ b/lib/net/getVideoInfo.ts @@ -2,13 +2,13 @@ import netScheduler from "lib/mq/scheduler.ts"; import { VideoInfoData, VideoInfoResponse } from "lib/net/bilibili.d.ts"; import logger from "lib/log/logger.ts"; -export async function getVideoInfo(aid: number, task: string): Promise { +export async function getVideoInfo(aid: number, task: string): Promise { const url = `https://api.bilibili.com/x/web-interface/view?aid=${aid}`; const data = await netScheduler.request(url, task); const errMessage = `Error fetching metadata for ${aid}:`; if (data.code !== 0) { logger.error(errMessage + data.code + "-" + data.message, "net", "fn:getVideoInfo"); - return null; + return data.code; } return data.data; }