From f8c1415b8ec4893dfa1f578aea0d346e30a30f74 Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Thu, 9 Oct 2025 10:44:18 +0800 Subject: [PATCH] fix(route/bilibili): duration for video route --- lib/routes/bilibili/video.ts | 2 ++ lib/utils/helpers.ts | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) 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(':')