-
Notifications
You must be signed in to change notification settings - Fork 703
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
50 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { CommonSubtitleItem } from "~/lib/types"; | ||
|
||
export type YoutubeSubtitleItem = { start: number; lines: string[] }; | ||
|
||
export function reduceSubtitleTimestamp( | ||
subtitles: Array<YoutubeSubtitleItem> | ||
): Array<CommonSubtitleItem> { | ||
// 把字幕数组分成 10 组 | ||
const groupCount = 20; | ||
const eachGroupCount = | ||
subtitles.length > groupCount | ||
? subtitles.length / groupCount | ||
: subtitles.length; | ||
|
||
return subtitles.reduce( | ||
( | ||
accumulator: CommonSubtitleItem[], | ||
current: YoutubeSubtitleItem, | ||
index: number | ||
) => { | ||
// 计算当前元素在哪一组 | ||
const groupIndex: number = Math.floor(index / eachGroupCount); | ||
|
||
// 如果是当前组的第一个元素,初始化这一组的字符串 | ||
if (!accumulator[groupIndex]) { | ||
accumulator[groupIndex] = { | ||
// 5.88 -> 5.9 | ||
// text: current.start.toFixed() + ": ", | ||
text: current.start + ": ", | ||
index: groupIndex, | ||
}; | ||
} | ||
|
||
// 将当前元素添加到当前组的字符串末尾 | ||
accumulator[groupIndex].text = | ||
accumulator[groupIndex].text + current.lines.join(" ") + " "; | ||
|
||
return accumulator; | ||
}, | ||
[] | ||
); | ||
} |
0d674d9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
chat-bilibili-video – ./
chat-bilibili-video-git-main-jimmylv.vercel.app
m.bilibili.jimmylv.cn
b.jimmylv.cn
bilibili.jimmylv.cn
chat-bilibili-video.vercel.app
www.bilibili.jimmylv.cn
www.youtube.jimmylv.cn
m.youtube.jimmylv.cn
chat-bilibili-video-jimmylv.vercel.app