From 1f41ef2f9b7f26270365d9c4605c2e610726380b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=89=E9=BB=98=E3=81=AE=E9=87=91?= <110812055+chenmozhijin@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:01:09 +0800 Subject: [PATCH] fix #4 --- utils/lyrics.py | 23 +++++++++++++++-------- utils/worker.py | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/utils/lyrics.py b/utils/lyrics.py index d318fd7..4e40134 100644 --- a/utils/lyrics.py +++ b/utils/lyrics.py @@ -108,7 +108,7 @@ def yrc2list(yrc: str) -> list: return lrc_list -def lrc2list(lrc: str) -> tuple[dict, list]: +def lrc2list(lrc: str, source: Source | None = None) -> tuple[dict, list]: """将lrc转换为列表[(行起始时间, 行结束时间, [(字起始时间, 字结束时间, 字内容)])]""" lrc_list: list[tuple[int, int | None, list[tuple[int, int | None, str]]]] = [] tags = {} @@ -146,15 +146,22 @@ def lrc2list(lrc: str) -> tuple[dict, list]: lrc_list[-1][2].append((line_start_time, line_end_time, line_content)) continue - line = [] - for wrods_split_content in wrods_split_contents: - m, s, ms, word_content = wrods_split_content + if source == Source.NE and len([word_content for m, s, ms, word_content in wrods_split_contents if word_content != ""]) == 1 and wrods_split_contents[-1][3] != "": + # 如果转换的是网易云歌词且这一行有开头有几个连在一起的时间戳表示这几个时间戳的行都是这个歌词 + line_content = wrods_split_contents[-1][3] + lrc_list[-1][2].append((line_start_time, line_end_time, line_content)) + for m, s, ms, _line_content in wrods_split_contents: + line_start_time = time2ms(m, s, ms) + lrc_list.append((line_start_time, None, [(line_start_time, None, line_content)])) + continue + + line = lrc_list[-1][2] + for m, s, ms, word_content in wrods_split_contents: word_start_time = time2ms(m, s, ms) if line: - line[-1][1] = word_start_time - lrc_list.append((word_start_time, None, word_content)) + line[-1] = (line[-1][0], word_start_time, line[-1][2]) + line.append((word_start_time, None, word_content)) - lrc_list.append(line) return tags, lrc_list @@ -533,7 +540,7 @@ def download_and_decrypt(self) -> tuple[str | None, LyricsProcessingError | None self[key] = yrc2list(lyrics[value]['lyric']) self.lrc_types[key] = LyricsType.YRC elif lyric_type == LyricsType.LRC: - self[key] = lrc2list(lyrics[value]['lyric'])[1] + self[key] = lrc2list(lyrics[value]['lyric'], source=Source.NE)[1] self.lrc_types[key] = LyricsType.LRC elif lyric_type == LyricsType.PlainText: self[key] = plaintext2list(lyrics[value]['lyric']) diff --git a/utils/worker.py b/utils/worker.py index 81aa887..fb60c27 100644 --- a/utils/worker.py +++ b/utils/worker.py @@ -55,7 +55,7 @@ case _: cache_dir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "cache") cache = Cache(cache_dir) -cache_version = 3 +cache_version = 4 if "version" not in cache or cache["version"] != cache_version: cache.clear() cache["version"] = cache_version