Quellcode durchsuchen

歌词显示逻辑的优化

onecold vor 1 Jahr
Ursprung
Commit
9005420ae9

+ 7 - 7
entry/src/main/ets/common/util/LyricUtil.ets

@@ -95,9 +95,9 @@ class LyricUtil {
         let firstTimestamp = "";
         let fullText = "";
 
-        // 处理方括号格式:[00:00.000]文[00:01.000]
-        if (this.isSquareBracketWordByWordLyric(line)) {
-          const regex = /\[(\d{2}:\d{2}\.\d{2,3})\]([^\[]*)/g;
+        // 处理尖括号格式:<00:00.000>文<00:01.000>
+         if (this.isWordByWordLyric(line)) {
+          const regex = /<(\d{2}:\d{2}\.\d{2,3})>([^<]*)/g;
           let match: RegExpExecArray | null;
 
           while ((match = regex.exec(line)) !== null) {
@@ -107,10 +107,10 @@ class LyricUtil {
             if (!firstTimestamp) firstTimestamp = timestamp;
             fullText += word;
           }
-        }
-        // 处理尖括号格式:<00:00.000>文<00:01.000>
-        else if (this.isWordByWordLyric(line)) {
-          const regex = /<(\d{2}:\d{2}\.\d{2,3})>([^<]*)/g;
+        }else
+        // 处理方括号格式:[00:00.000]文[00:01.000]
+        if (this.isSquareBracketWordByWordLyric(line)) {
+          const regex = /\[(\d{2}:\d{2}\.\d{2,3})\]([^\[]*)/g;
           let match: RegExpExecArray | null;
 
           while ((match = regex.exec(line)) !== null) {

+ 8 - 8
lib/src/main/ets/parse/LyricParser.ts

@@ -57,19 +57,19 @@ export class LyricParser implements IParser {
                 offset = Number.parseInt(this.parseIdTag(line))
             } else {
 
-                // 新增:逐字歌词[]检测方括号逐字歌词格式 [mm:ss.xxx] 文字
+                // 新增逐字歌词解析逻辑[mm:ss.xx] <mm:ss.xx>
+                if (this.isWordByWordLyric(line)) {
+                    const { timeline, words } = this.parseWordByWordLine(line, offset);
+                    lyricLines.push(new LyricLine('', timeline, -1, words))
+                    continue;
+                }
+
+                    // 新增:逐字歌词[]检测方括号逐字歌词格式 [mm:ss.xxx] 文字
                 if (this.isSquareBracketWordByWordLyric(line))  {
                     const { timeline, words } = this.parseSquareBracketWordLine(line,  offset);
                     if (words.length  > 0) {
                         lyricLines.push(new  LyricLine('', timeline, -1, words))
                     }
-                    continue;
-                }
-
-                // 新增逐字歌词解析逻辑[mm:ss.xx] <mm:ss.xx>
-                if (this.isWordByWordLyric(line)) {
-                    const { timeline, words } = this.parseWordByWordLine(line, offset);
-                    lyricLines.push(new LyricLine('', timeline, -1, words))
                 } else {
                     // 原逻辑处理,但支持逐字歌词
                     // [00:00.10]画心 - 张靓颖