update: handling for deleted videos
This commit is contained in:
parent
81b95c9569
commit
9a85da0532
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user