diff --git a/lib/routes/bilibili/video.ts b/lib/routes/bilibili/video.ts index 959e919d2b..f149cb7cc9 100644 --- a/lib/routes/bilibili/video.ts +++ b/lib/routes/bilibili/video.ts @@ -1,5 +1,6 @@ import { Route, ViewType } from '@/types'; import got from '@/utils/got'; +import { parseDuration } from '@/utils/helpers'; import logger from '@/utils/logger'; import type { Context } from 'hono'; import cache from './cache'; @@ -86,6 +87,7 @@ async function handler(ctx: Context) { { url: getVideoUrl(item.bvid), mime_type: 'text/html', + duration_in_seconds: parseDuration(item.length), }, ...subtitles, ] diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index 3e4e820ea2..63c8ca3a09 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -46,7 +46,10 @@ export function getSearchParamsString(searchParams: any) { * @param {string} timeStr - duration string like "01:01:01" / "01:01" / "59" * @returns {number} - total seconds */ -export function parseDuration(timeStr: string) { +export function parseDuration(timeStr: string | undefined | null): number | undefined { + if (!timeStr) { + return; + } const clean = timeStr.trim().replaceAll(/[^\d:]/g, ''); return clean .split(':')