import textwrap from beets.library import Item from beets.util.lyrics import Lyrics class TestLyrics: def test_instrumental_lyrics(self): lyrics = Lyrics( "[Instrumental]", "lrclib", url="https://lrclib.net/api/1" ) assert lyrics.full_text == "" assert lyrics.instrumental assert lyrics.backend == "lrclib" assert lyrics.url == "https://lrclib.net/api/1" assert lyrics.language is None assert lyrics.translation_language is None def test_from_item_without_lyrics(self): item = Item(lyrics=None) lyrics = Lyrics.from_item(item) assert lyrics.text == "" assert not lyrics.synced assert lyrics.full_text == "" assert lyrics.sylt == [] assert lyrics.text_lines == [] def test_from_legacy_text(self, is_importable): text = textwrap.dedent(""" [00:00.00] Some synced lyrics / Quelques paroles synchronisées [00:00.50] [00:01.00] Some more synced lyrics / Quelques paroles plus synchronisées Source: https://lrclib.net/api/1/""") lyrics = Lyrics.from_legacy_text(text) assert lyrics.full_text == textwrap.dedent( """ [00:00.00] Some synced lyrics / Quelques paroles synchronisées [00:00.50] [00:01.00] Some more synced lyrics / Quelques paroles plus synchronisées""" ) assert lyrics.backend == "lrclib" assert lyrics.url == "https://lrclib.net/api/1/" langdetect_available = is_importable("langdetect") assert lyrics.language == ("EN" if langdetect_available else None) assert lyrics.translation_language == ( "FR" if langdetect_available else None ) assert not lyrics.instrumental def test_timestamp_precision_and_sylt(self): text = textwrap.dedent(""" [00:00.05] Centisecond line [00:01.50] Two decimals [00:02.123] Three decimals [01:00.005] Five milliseconds """).strip() lyrics = Lyrics(text) assert lyrics.synced assert lyrics.timestamps == [ "[00:00.05]", "[00:01.50]", "[00:02.123]", "[01:00.005]", ] assert lyrics.text_lines == [ "Centisecond line", "Two decimals", "Three decimals", "Five milliseconds", ] assert lyrics.sylt == [ ("Centisecond line", 50), ("Two decimals", 1500), ("Three decimals", 2123), ("Five milliseconds", 60005), ]