Skip to content

Commit e914d59

Browse files
committed
Remove empty timestamps from synced lyrics
1 parent dfb8e4d commit e914d59

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

beetsplug/lyrics.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ class LRCLibItem(TypedDict):
294294
class LRCLyrics:
295295
#: Percentage tolerance for max duration difference between lyrics and item.
296296
DURATION_DIFF_TOLERANCE = 0.05
297+
remove_empty_times = partial(
298+
re.compile(r"^\[\d+:\d+.\d+\] *$", re.M).sub, ""
299+
)
297300

298301
target_duration: float
299302
duration: float
@@ -348,7 +351,10 @@ def get_text(self, want_synced: bool) -> str:
348351
if self.instrumental:
349352
return INSTRUMENTAL_LYRICS
350353

351-
return self.synced if want_synced and self.synced else self.plain
354+
if want_synced and self.synced:
355+
return self.remove_empty_times(self.synced).strip()
356+
357+
return self.plain
352358

353359

354360
class LRCLib(Backend):

test/plugins/lyrics_pages.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,20 @@ def backend(self) -> str:
278278
[00:39.18] See how they run
279279
[00:43.33] Lady Madonna, baby at your breast
280280
[00:48.50] Wonders how you manage to feed the rest
281-
[00:52.54]
281+
282282
[01:01.32] Ba-ba, ba-ba, ba-ba, ba-ba-ba
283283
[01:05.03] Ba-ba, ba-ba, ba-ba, ba, ba-ba, ba-ba
284284
[01:09.58] Ba-ba, ba-ba, ba-ba, ba-ba-ba
285285
[01:14.27] See how they run
286286
[01:19.05] Lady Madonna, lying on the bed
287287
[01:22.99] Listen to the music playing in your head
288-
[01:27.92]
288+
289289
[01:36.33] Tuesday afternoon is never ending
290290
[01:40.47] Wednesday morning papers didn't come
291291
[01:44.76] Thursday night your stockings needed mending
292292
[01:49.35] See how they run
293293
[01:53.73] Lady Madonna, children at your feet
294294
[01:58.65] Wonder how you manage to make ends meet
295-
[02:06.04]
296295
""",
297296
),
298297
LyricsPage.make(

test/plugins/test_lyrics.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,23 @@ def fetch_lyrics(self, backend, requests_mock, request_kwargs):
373373

374374
return partial(backend.fetch, "la", "la", "la", self.ITEM_DURATION)
375375

376-
@pytest.mark.parametrize("response_data", [[lyrics_match()]])
376+
@pytest.mark.parametrize(
377+
"response_data",
378+
[
379+
[
380+
lyrics_match(
381+
plainLyrics="plain",
382+
syncedLyrics="[00:00.00] synced\n[00:01.00] ",
383+
)
384+
]
385+
],
386+
)
377387
@pytest.mark.parametrize(
378388
"plugin_config, expected_lyrics",
379-
[({"synced": True}, "synced"), ({"synced": False}, "plain")],
389+
[
390+
({"synced": True}, "[00:00.00] synced"), # empty timestamp is gone
391+
({"synced": False}, "plain"),
392+
],
380393
)
381394
def test_synced_config_option(self, fetch_lyrics, expected_lyrics):
382395
assert fetch_lyrics() == expected_lyrics

0 commit comments

Comments
 (0)