This commit is contained in:
IndieKKY
2023-09-15 21:59:33 +08:00
parent 49e311a9ed
commit e7e8758716

View File

@@ -203,12 +203,13 @@ export const parseTranscript = (filename: string, text: string | ArrayBuffer): T
if (filename.toLowerCase().endsWith('.srt')) { if (filename.toLowerCase().endsWith('.srt')) {
const lines = text.split('\n\n') const lines = text.split('\n\n')
for (const line of lines) { for (const line of lines) {
const lines = line.split('\n') try {
if (lines.length >= 3) { const linesInner = line.trim().split('\n')
const time = lines[1].split(' --> ') if (linesInner.length >= 3) {
const time = linesInner[1].split(' --> ')
const from = parseTime(time[0]) const from = parseTime(time[0])
const to = parseTime(time[1]) const to = parseTime(time[1])
const content = lines.slice(2).join('\n') const content = linesInner.slice(2).join('\n')
items.push({ items.push({
from, from,
to, to,
@@ -216,6 +217,9 @@ export const parseTranscript = (filename: string, text: string | ArrayBuffer): T
idx: items.length, idx: items.length,
}) })
} }
} catch (e) {
console.error('parse error', line)
}
} }
} }
// .vtt: // .vtt: