mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-24 23:42:40 +08:00
fix(route/bilibili): duration for video route
This commit is contained in:
@@ -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,
|
||||
]
|
||||
|
||||
@@ -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(':')
|
||||
|
||||
Reference in New Issue
Block a user