From e7e8758716b93b1a95390602c92a80e9b8eac179 Mon Sep 17 00:00:00 2001 From: IndieKKY Date: Fri, 15 Sep 2023 21:59:33 +0800 Subject: [PATCH] optimize --- src/util/biz_util.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/util/biz_util.ts b/src/util/biz_util.ts index fd7e0e1..119c83b 100644 --- a/src/util/biz_util.ts +++ b/src/util/biz_util.ts @@ -203,18 +203,22 @@ export const parseTranscript = (filename: string, text: string | ArrayBuffer): T if (filename.toLowerCase().endsWith('.srt')) { const lines = text.split('\n\n') for (const line of lines) { - const lines = line.split('\n') - if (lines.length >= 3) { - const time = lines[1].split(' --> ') - const from = parseTime(time[0]) - const to = parseTime(time[1]) - const content = lines.slice(2).join('\n') - items.push({ - from, - to, - content, - idx: items.length, - }) + try { + const linesInner = line.trim().split('\n') + if (linesInner.length >= 3) { + const time = linesInner[1].split(' --> ') + const from = parseTime(time[0]) + const to = parseTime(time[1]) + const content = linesInner.slice(2).join('\n') + items.push({ + from, + to, + content, + idx: items.length, + }) + } + } catch (e) { + console.error('parse error', line) } } }