diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 3a99cea9e4..945061b8fb 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -294,6 +294,9 @@ class LRCLibItem(TypedDict): class LRCLyrics: #: Percentage tolerance for max duration difference between lyrics and item. DURATION_DIFF_TOLERANCE = 0.05 + remove_empty_times = partial( + re.compile(r"^\[\d+:\d+.\d+\] *$", re.M).sub, "" + ) target_duration: float duration: float @@ -348,7 +351,10 @@ def get_text(self, want_synced: bool) -> str: if self.instrumental: return INSTRUMENTAL_LYRICS - return self.synced if want_synced and self.synced else self.plain + if want_synced and self.synced: + return self.remove_empty_times(self.synced).strip() + + return self.plain class LRCLib(Backend): diff --git a/test/plugins/lyrics_pages.py b/test/plugins/lyrics_pages.py index 84c2457ba4..9a5f85f6db 100644 --- a/test/plugins/lyrics_pages.py +++ b/test/plugins/lyrics_pages.py @@ -278,21 +278,20 @@ def backend(self) -> str: [00:39.18] See how they run [00:43.33] Lady Madonna, baby at your breast [00:48.50] Wonders how you manage to feed the rest - [00:52.54] + [01:01.32] Ba-ba, ba-ba, ba-ba, ba-ba-ba [01:05.03] Ba-ba, ba-ba, ba-ba, ba, ba-ba, ba-ba [01:09.58] Ba-ba, ba-ba, ba-ba, ba-ba-ba [01:14.27] See how they run [01:19.05] Lady Madonna, lying on the bed [01:22.99] Listen to the music playing in your head - [01:27.92] + [01:36.33] Tuesday afternoon is never ending [01:40.47] Wednesday morning papers didn't come [01:44.76] Thursday night your stockings needed mending [01:49.35] See how they run [01:53.73] Lady Madonna, children at your feet [01:58.65] Wonder how you manage to make ends meet - [02:06.04] """, ), LyricsPage.make( diff --git a/test/plugins/test_lyrics.py b/test/plugins/test_lyrics.py index fe5909e327..8f5c839931 100644 --- a/test/plugins/test_lyrics.py +++ b/test/plugins/test_lyrics.py @@ -377,10 +377,23 @@ def fetch_lyrics(self, backend, requests_mock, request_kwargs): return partial(backend.fetch, "la", "la", "la", self.ITEM_DURATION) - @pytest.mark.parametrize("response_data", [[lyrics_match()]]) + @pytest.mark.parametrize( + "response_data", + [ + [ + lyrics_match( + plainLyrics="plain", + syncedLyrics="[00:00.00] synced\n[00:01.00] ", + ) + ] + ], + ) @pytest.mark.parametrize( "plugin_config, expected_lyrics", - [({"synced": True}, "synced"), ({"synced": False}, "plain")], + [ + ({"synced": True}, "[00:00.00] synced"), # empty timestamp is gone + ({"synced": False}, "plain"), + ], ) def test_synced_config_option(self, fetch_lyrics, expected_lyrics): assert fetch_lyrics() == expected_lyrics