import logger from "@core/log"; import type { MediaListInfoData, MediaListInfoResponse } from "@core/net/bilibili.d"; import networkDelegate, { type RequestTasks } from "@core/net/delegate"; /* * Bulk fetch video metadata from bilibili API * @param {number[]} aids - The aid list to fetch * @returns {Promise} MediaListInfoData or the error code returned by bilibili API * @throws {NetSchedulerError} - The error will be thrown in following cases: * - No proxy is available currently: with error code `NO_PROXY_AVAILABLE` * - The native `fetch` function threw an error: with error code `FETCH_ERROR` * - The alicloud-fc threw an error: with error code `ALICLOUD_FC_ERROR` */ export async function bulkGetVideoStats( aids: number[], task?: RequestTasks ): Promise< | { data: MediaListInfoData; time: number; } | number > { // TODO: https://api.bilibili.com/x/v3/fav/resource/infos?resources=20:2 let url = `https://api.bilibili.com/medialist/gateway/base/resource/infos?resources=`; for (const aid of aids) { url += `${aid}:2,`; } const { data, time } = await networkDelegate.request( url, task ?? "bulkSnapshot" ); const errMessage = `Error fetching metadata for aid list: ${aids.join(",")}:`; if (data.code !== 0) { logger.error(`${errMessage + data.code}-${data.message}`, "net", "fn:getVideoInfo"); return data.code; } return { data: data.data, time: time, }; }