From 7ca436572fa74e85f75530130610308f138439b6 Mon Sep 17 00:00:00 2001 From: JimenezLi <75196426+JimenezLi@users.noreply.github.com> Date: Sun, 24 Sep 2023 01:17:39 +0800 Subject: [PATCH] feat(route): danmaku add video time (#13379) --- lib/v2/bilibili/danmaku.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/v2/bilibili/danmaku.js b/lib/v2/bilibili/danmaku.js index 1f316d1506..c548e29c5b 100644 --- a/lib/v2/bilibili/danmaku.js +++ b/lib/v2/bilibili/danmaku.js @@ -3,6 +3,14 @@ const cache = require('./cache'); const got = require('@/utils/got'); const zlib = require('zlib'); +const processFloatTime = (time) => { + const totalSeconds = parseInt(time); + const seconds = totalSeconds % 60; + const minutes = ((totalSeconds - seconds) / 60) % 60; + const hours = (totalSeconds - seconds - 60 * minutes) / 3600; + return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`; +}; + module.exports = async (ctx) => { let bvid = ctx.params.bvid; let aid; @@ -46,8 +54,7 @@ module.exports = async (ctx) => { link, description: `${videoName} 的 弹幕动态`, item: danmakuList.map((item) => ({ - title: item.text, - description: item.text, + title: `[${processFloatTime(item.p.split(',')[0])}] ${item.text}`, pubDate: new Date(item.p.split(',')[4] * 1000).toUTCString(), guid: `${cid}-${item.p.split(',')[4]}-${item.p.split(',')[7]}`, link,