update: handling for deleted videos

This commit is contained in:
alikia2x (寒寒) 2025-03-09 22:57:26 +08:00
parent 81b95c9569
commit 9a85da0532
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
3 changed files with 20 additions and 6 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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<VideoInfoData | null> {
export async function getVideoInfo(aid: number, task: string): Promise<VideoInfoData | number> {
const url = `https://api.bilibili.com/x/web-interface/view?aid=${aid}`;
const data = await netScheduler.request<VideoInfoResponse>(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;
}