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 { aid, currentViews, snapshotedAt } = job.data;
|
||||||
const lastSnapshoted = snapshotedAt;
|
const lastSnapshoted = snapshotedAt;
|
||||||
const stat = await insertVideoStats(client, aid, "snapshotMilestoneVideo");
|
const stat = await insertVideoStats(client, aid, "snapshotMilestoneVideo");
|
||||||
if (stat == null) {
|
if (typeof stat === "number") {
|
||||||
await setSnapshotScheduled(aid, false, 0);
|
if (stat === -404 || stat === 62002) {
|
||||||
|
await setSnapshotScheduled(aid, true, 6 * 60 * 60);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await setSnapshotScheduled(aid, false, 0);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const nextMilestone = currentViews >= 100000 ? 1000000 : 100000;
|
const nextMilestone = currentViews >= 100000 ? 1000000 : 100000;
|
||||||
@ -166,6 +171,15 @@ export const takeSnapshotForVideoWorker = async (job: Job) => {
|
|||||||
try {
|
try {
|
||||||
const { aid } = job.data;
|
const { aid } = job.data;
|
||||||
const stat = await insertVideoStats(client, aid, "getVideoInfo");
|
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");
|
logger.log(`Taken snapshot for ${aid}`, "mq");
|
||||||
if (stat == null) {
|
if (stat == null) {
|
||||||
setSnapshotScheduled(aid, false, 0);
|
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) {
|
export async function insertVideoStats(client: Client, aid: number, task: string) {
|
||||||
const data = await getVideoInfo(aid, task);
|
const data = await getVideoInfo(aid, task);
|
||||||
const time = new Date().getTime();
|
const time = new Date().getTime();
|
||||||
if (data === null) {
|
if (typeof data == 'number') {
|
||||||
return null;
|
return data;
|
||||||
}
|
}
|
||||||
const views = data.stat.view;
|
const views = data.stat.view;
|
||||||
const danmakus = data.stat.danmaku;
|
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 { VideoInfoData, VideoInfoResponse } from "lib/net/bilibili.d.ts";
|
||||||
import logger from "lib/log/logger.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 url = `https://api.bilibili.com/x/web-interface/view?aid=${aid}`;
|
||||||
const data = await netScheduler.request<VideoInfoResponse>(url, task);
|
const data = await netScheduler.request<VideoInfoResponse>(url, task);
|
||||||
const errMessage = `Error fetching metadata for ${aid}:`;
|
const errMessage = `Error fetching metadata for ${aid}:`;
|
||||||
if (data.code !== 0) {
|
if (data.code !== 0) {
|
||||||
logger.error(errMessage + data.code + "-" + data.message, "net", "fn:getVideoInfo");
|
logger.error(errMessage + data.code + "-" + data.message, "net", "fn:getVideoInfo");
|
||||||
return null;
|
return data.code;
|
||||||
}
|
}
|
||||||
return data.data;
|
return data.data;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user