mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-26 00:55:16 -07:00
32 lines
812 B
TypeScript
32 lines
812 B
TypeScript
import type { SubtitleCue } from '../../types';
|
|
|
|
export function selectAutoplayStartupCue(
|
|
cues: SubtitleCue[],
|
|
currentTimeSeconds: number,
|
|
lookaheadSeconds: number,
|
|
): SubtitleCue | null {
|
|
const currentTime = Math.max(0, Number.isFinite(currentTimeSeconds) ? currentTimeSeconds : 0);
|
|
const lookahead = Math.max(0, Number.isFinite(lookaheadSeconds) ? lookaheadSeconds : 0);
|
|
const latestStartTime = currentTime + lookahead;
|
|
|
|
for (const cue of cues) {
|
|
if (!cue.text.trim()) {
|
|
continue;
|
|
}
|
|
if (cue.startTime <= currentTime && cue.endTime > currentTime) {
|
|
return cue;
|
|
}
|
|
}
|
|
|
|
for (const cue of cues) {
|
|
if (!cue.text.trim()) {
|
|
continue;
|
|
}
|
|
if (cue.startTime >= currentTime && cue.startTime <= latestStartTime) {
|
|
return cue;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|