From 252121f537613fbdf2564605dbefc683a632b04b Mon Sep 17 00:00:00 2001 From: Luke Harder Date: Thu, 10 Nov 2022 12:54:45 -0500 Subject: [PATCH 1/5] bug 4406 fix --- beetsplug/lyrics.py | 22 +- docs/changelog.rst | 3 + .../piosenka24kgoldncityofangels1.txt | 910 ++++++++++++++++++ .../piosenkabaileybiggerblackeyedsusan.txt | 888 +++++++++++++++++ ...ovenpianosonata17tempestthe3rdmovement.txt | 751 +++++++++++++++ .../szukajwykonawcaagfdgjatytulagfdgafg.txt | 537 +++++++++++ ...ukajwykonawcajuicewrldtytulluciddreams.txt | 584 +++++++++++ test/rsrc/unicode’d.mp3 | Bin 12820 -> 12820 bytes test/test_lyrics.py | 104 ++ 9 files changed, 3797 insertions(+), 2 deletions(-) mode change 100644 => 100755 docs/changelog.rst create mode 100755 test/rsrc/lyrics/tekstowopl/piosenka24kgoldncityofangels1.txt create mode 100755 test/rsrc/lyrics/tekstowopl/piosenkabaileybiggerblackeyedsusan.txt create mode 100755 test/rsrc/lyrics/tekstowopl/piosenkabeethovenbeethovenpianosonata17tempestthe3rdmovement.txt create mode 100755 test/rsrc/lyrics/tekstowopl/szukajwykonawcaagfdgjatytulagfdgafg.txt create mode 100755 test/rsrc/lyrics/tekstowopl/szukajwykonawcajuicewrldtytulluciddreams.txt diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 800e0302a..62ba7fd78 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -51,6 +51,7 @@ except ImportError: class HTMLParseError(Exception): pass +from beets.autotag.hooks import string_dist from beets import plugins from beets import ui import beets @@ -461,7 +462,7 @@ class Tekstowo(Backend): if not song_page_html: return None - return self.extract_lyrics(song_page_html) + return self.extract_lyrics(song_page_html, artist, title) def parse_search_results(self, html): html = _scrape_strip_cruft(html) @@ -493,7 +494,7 @@ class Tekstowo(Backend): return self.BASE_URL + link.get('href') - def extract_lyrics(self, html): + def extract_lyrics(self, html, artist, title): html = _scrape_strip_cruft(html) html = _scrape_merge_paragraphs(html) @@ -501,6 +502,23 @@ class Tekstowo(Backend): if not soup: return None + info_div = soup.find("div", class_="col-auto") + if not info_div: + return None + + info_elements = info_div.find_all("a") + if not info_elements: + return None + + html_title = info_elements[-1].get_text() + html_artist = info_elements[-2].get_text() + + title_dist = string_dist(html_title, title) + artist_dist = string_dist(html_artist, artist) + + if title_dist > 0.1 or artist_dist > 0.1: + return None + lyrics_div = soup.select("div.song-text > div.inner-text") if not lyrics_div: return None diff --git a/docs/changelog.rst b/docs/changelog.rst old mode 100644 new mode 100755 index 646417f28..33eccac09 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -117,6 +117,9 @@ Bug fixes: * :doc:`/plugins/lastgenre`: Fix a duplicated entry for trip hop in the default genre list. :bug:`4510` +* :doc:`plugins/lyrics`: Fixed issue with Tekstowo backend not actually checking + if the found song actually matches. + :bug:`4406` For packagers: diff --git a/test/rsrc/lyrics/tekstowopl/piosenka24kgoldncityofangels1.txt b/test/rsrc/lyrics/tekstowopl/piosenka24kgoldncityofangels1.txt new file mode 100755 index 000000000..de91cc339 --- /dev/null +++ b/test/rsrc/lyrics/tekstowopl/piosenka24kgoldncityofangels1.txt @@ -0,0 +1,910 @@ + + + + + + + + + 24kGoldn - City Of Angels - tekst i tłumaczenie piosenki na Tekstowo.pl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + + + + + + + +
+ +
+ + +
+
+
+
+ +
+ 2 170 744 tekstów, 20 217 poszukiwanych i 501 oczekujących +
+
+ +
+ +
+ + + + + Zobacz więcej >> + + + Zobacz więcej >> + + + Zobacz więcej >> + + + + + +
+
+ +
+
+ + + +
+
+

24kGoldn - City Of Angels

+
+
+
+
+
Odsłon: 9846
+
+ +
+
+
+ + + + + +
+
+ + + + + + + + +
+ + + + +
+ +
+ +
+
+
+ +
+
+
+
+ +
+
+
+
+ + Tekst dodał(a): asdfghjklmnop + + Edytuj tekst +
+
+ + Tłumaczenie dodał(a): tapcapslock + Edytuj tłumaczenie +
+
+ + Teledysk dodał(a): olcia_197 + Edytuj teledysk +
+
+
+ +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+ Głosuj na ten utwór +
+ + + (0) +
+ +
+
+ + +
+ + +
+
+
+ + +
+
+
+
+
+

Tekst piosenki:

+ +
[Chorus]
+I sold my soul to the devil for designer
+They said, "Go to hell," but I told 'em I don’t wanna
+If you know me well, then you know that I ain't goin'
+’Cause I don't wanna, I don't wanna
+I don't wanna die young
+The city of angels where I have my fun
+Don't wanna die young
+When I'm gone, remember all I've done-one
+
+[Verse]
+We've had our fun-un
+But now I’m done-one
+’Cause you crazy (Yeah), I can't take it (No)
+Just wanted to see you naked
+Heard time like money, can’t waste it
+What's the price of fame? 'Cause I can taste it
+So I'm chasin’ (Yeah), and I'm facin'
+A little Hennessy, it might be good for me
+
+[Chorus]
+I sold my soul to the devil for designer
+They said, "Go to hell," but I told 'em I don't wanna
+If you know me well, then you know that I ain't goin'
+'Cause I don't wanna, I don't wanna
+I don't wanna die young
+The city of angels where I have my fun
+Don't wanna die young
+When I'm gone, remember all I've done-one
+ Dodaj interpretację do tego tekstu » + + + +
+ + + + + + + + + + +
+

 

+ Historia edycji tekstu +
+
+
+ +
+
+

Tłumaczenie:

+ Pokaż tłumaczenie +
+
[Chór]
+Sprzedałem duszę diabłu za projektanta
+Powiedzieli „Idź do piekła”, ale powiedziałem im, że nie chcę
+Jeśli dobrze mnie znasz, to wiesz, że nie idę
+Bo nie chcę, nie chcę
+Nie chcę umrzeć młodo
+Miasto aniołów, w którym dobrze się bawię
+Nie chcę umrzeć młodo
+Kiedy odejdę, pamiętaj wszystko, co zrobiłem
+
+[Werset]
+Mieliśmy naszą zabawę
+Ale teraz skończyłem
+Bo jesteś szalony (Tak), nie mogę tego znieść (Nie)
+Chciałem tylko zobaczyć cię nago
+Słyszałem czas jak pieniądze, nie można go marnować
+Jaka jest cena sławy? Bo mogę to posmakować
+Więc chasin '(Yeah) i patrzę
+Trochę Hennessy, może być dla mnie dobre
+
+[Chór]
+Sprzedałem duszę diabłu za projektanta
+Powiedzieli „Idź do piekła”, ale powiedziałem im, że nie chcę
+Jeśli dobrze mnie znasz, to wiesz, że nie idę
+Bo nie chcę, nie chcę
+Nie chcę umrzeć młodo
+Miasto aniołów, w którym dobrze się bawię
+Nie chcę umrzeć młodo
+Kiedy odejdę, pamiętaj wszystko, co zrobiłem
+ +

 

+ + Historia edycji tłumaczenia + +
+
+ +
+ + + + + + + + +
+ +
+
+ +
+ + +
+
+
+ + + +
Rok wydania:

2019

Edytuj metrykę
Płyty:

Dropped Outta College

+
+
+
+ + + +
+
+ Głosuj na ten utwór +
+ + + (0) +
+ +
+ +
+
+ + +
+

Komentarze (0):

+ +
+ +
+
+ +
+ +
+
+ + + +
+
+ + + + +
+ +
+
+ + +
+
+ +
+ +
+ + +
+
+
+ +
+
+ 2 170 744 tekstów, 20 217 poszukiwanych i 501 oczekujących +
+
+
+

Największy serwis z tekstami piosenek w Polsce. Każdy może znaleźć u nas teksty piosenek, teledyski oraz tłumaczenia swoich ulubionych utworów.
Zachęcamy wszystkich użytkowników do dodawania nowych tekstów, tłumaczeń i teledysków!

+
+ Reklama | + Kontakt | + FAQ + Polityka prywatności +
+
+
+ +
+ + + +
+ +
+
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/rsrc/lyrics/tekstowopl/piosenkabaileybiggerblackeyedsusan.txt b/test/rsrc/lyrics/tekstowopl/piosenkabaileybiggerblackeyedsusan.txt new file mode 100755 index 000000000..9e3117b41 --- /dev/null +++ b/test/rsrc/lyrics/tekstowopl/piosenkabaileybiggerblackeyedsusan.txt @@ -0,0 +1,888 @@ + + + + + + + + + Bailey Bigger - Black Eyed Susan - tekst i tłumaczenie piosenki na Tekstowo.pl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + + + + + + + +
+ +
+ + +
+
+
+
+ +
+ 2 170 745 tekstów, 20 217 poszukiwanych i 502 oczekujących +
+
+ +
+ +
+ + + + + Zobacz więcej >> + + + Zobacz więcej >> + + + Zobacz więcej >> + + + + + +
+
+ +
+
+ + + +
+
+

Bailey Bigger - Black Eyed Susan

+
+
+
+
+
Odsłon: 22
+
+ +
+
+
+ + + + + +
+
+ + + + + + + + +
+ + + + +
+ +
+ +
+
+
+ +
+
+
+
+ +
+
+
+
+ + Tekst dodał(a): Adelle + + Edytuj tekst +
+
+ + Tłumaczenie dodał(a): brak + Dodaj tłumaczenie +
+
+ + Teledysk dodał(a): Adelle + Edytuj teledysk +
+
+
+ +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+ Głosuj na ten utwór +
+ + + (0) +
+ +
+
+ + +
+ + +
+
+
+ + +
+
+
+
+
+

Tekst piosenki:

+ +
Black eyed Susan
+Sun shines in your veins
+If the clouds are moving
+Never hear her complain
+Yeah, black eyed Susan
+Just waiting on a drop of rain
+
+Black eyed Susan
+Stands true and tall
+If the storms are brewing
+She ain't worried at all
+Yeah, black eyed Susan
+Just waiting on a drop to fall
+
+Everyone calls her the sunflower
+And no one knows her name
+She's a little girl on the side of the road
+Waiting on a drop of rain
+Rain
+Rain
+
+Black eyed Susan
+Ain't it just a shame?
+'Cause now you're losing
+All your petals in a vase
+In a vase
+She got picked and I never really knew her name
+Everyone calls her the sunflower
+And no one knows her name
+She's a little girl on the side of the road
+Waiting on a drop of rain
+Rain
+Rain
+Yeah, she got picked and I never really knew her name
+ Dodaj interpretację do tego tekstu » + + + +
+ + + + + + + + + + +
+

 

+ Historia edycji tekstu +
+
+
+ +
+
+

Tłumaczenie:

+

+ Niestety nikt nie dodał jeszcze tłumaczenia tego utworu. +

+

+ Dodaj tłumaczenie lub wyślij prośbę o tłumaczenie +

+ +
+
+ +

 

+
+ +
+ + + + + + + + +
+ +
+
+ +
+ + +
+
+
+ + +
Autor:

(brak)

Edytuj metrykę
+
+
+
+ + + +
+
+ Głosuj na ten utwór +
+ + + (0) +
+ +
+ +
+
+ + +
+

Komentarze (0):

+ +
+ +
+
+ +
+ +
+
+ + + +
+
+ + + + +
+ +
+
+ + +
+
+ +
+ +
+ + +
+
+
+ +
+
+ 2 170 745 tekstów, 20 217 poszukiwanych i 502 oczekujących +
+
+
+

Największy serwis z tekstami piosenek w Polsce. Każdy może znaleźć u nas teksty piosenek, teledyski oraz tłumaczenia swoich ulubionych utworów.
Zachęcamy wszystkich użytkowników do dodawania nowych tekstów, tłumaczeń i teledysków!

+
+ Reklama | + Kontakt | + FAQ + Polityka prywatności +
+
+
+ +
+ + + +
+ +
+
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/rsrc/lyrics/tekstowopl/piosenkabeethovenbeethovenpianosonata17tempestthe3rdmovement.txt b/test/rsrc/lyrics/tekstowopl/piosenkabeethovenbeethovenpianosonata17tempestthe3rdmovement.txt new file mode 100755 index 000000000..bd3feee01 --- /dev/null +++ b/test/rsrc/lyrics/tekstowopl/piosenkabeethovenbeethovenpianosonata17tempestthe3rdmovement.txt @@ -0,0 +1,751 @@ + + + + + + + + + Beethoven - Beethoven Piano Sonata 17 Tempest The 3rd Movement - na Tekstowo.pl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + + + + + + + +
+ +
+ + +
+
+
+
+ +
+ 2 170 744 tekstów, 20 217 poszukiwanych i 502 oczekujących +
+
+ +
+ +
+ + + + + Zobacz więcej >> + + + Zobacz więcej >> + + + Zobacz więcej >> + + + + + +
+
+ +
+
+ + + +
+
+

Beethoven - Beethoven Piano Sonata 17 Tempest The 3rd Movement

+
+
+
+
+
Odsłon: 25
+
+ +
+
+
+ + + + + + + + +
+
+ + + + + + + + +
+ + + + +
+ +
+ +
+
+
+ +
+
+
+
+ +
+
+
+
+ Utwór dodał(a): anmar09 +
+
+ Utwór instrumentalny Ten utwór ma słowa? Dodaj tekst +
+
+ Teledysk dodał(a): anmar09 + Edytuj teledysk +
+
+
+ +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+ Głosuj na ten utwór +
+ + + (0) +
+ +
+
+ +
+ + +
Ścieżka dźwiękowa:

Pokojówka

+
+ +
+
+ + +
+

Komentarze (0):

+ +
+ +
+
+ +
+ +
+
+ + + +
+
+ + + + +
+ +
+
+ + +
+
+ +
+ +
+ + +
+
+
+ +
+
+ 2 170 744 tekstów, 20 217 poszukiwanych i 502 oczekujących +
+
+
+

Największy serwis z tekstami piosenek w Polsce. Każdy może znaleźć u nas teksty piosenek, teledyski oraz tłumaczenia swoich ulubionych utworów.
Zachęcamy wszystkich użytkowników do dodawania nowych tekstów, tłumaczeń i teledysków!

+
+ Reklama | + Kontakt | + FAQ + Polityka prywatności +
+
+
+ +
+ + + +
+ +
+
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/rsrc/lyrics/tekstowopl/szukajwykonawcaagfdgjatytulagfdgafg.txt b/test/rsrc/lyrics/tekstowopl/szukajwykonawcaagfdgjatytulagfdgafg.txt new file mode 100755 index 000000000..a137059de --- /dev/null +++ b/test/rsrc/lyrics/tekstowopl/szukajwykonawcaagfdgjatytulagfdgafg.txt @@ -0,0 +1,537 @@ + + + + + + + + + Wyszukiwarka - teksty piosenek, tłumaczenia piosenek, teledyski na Tekstowo.pl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + + + + + + + +
+ +
+ + +
+
+
+
+ +
+ 2 170 872 tekstów, 20 217 poszukiwanych i 376 oczekujących +
+
+ +
+ + +
+ +
+ +
+ +
+ + + + +
+ +
+
+
+ + +

Znalezione utwory:

+
+
+ brak wyników wyszukiwania +
+
+ + + + + + +
+
+
+ +
+
+ +
+ +
+
+ + +
+
+ +
+ +
+ + +
+
+
+ +
+
+ 2 170 872 tekstów, 20 217 poszukiwanych i 376 oczekujących +
+
+
+

Największy serwis z tekstami piosenek w Polsce. Każdy może znaleźć u nas teksty piosenek, teledyski oraz tłumaczenia swoich ulubionych utworów.
Zachęcamy wszystkich użytkowników do dodawania nowych tekstów, tłumaczeń i teledysków!

+
+ Reklama | + Kontakt | + FAQ + Polityka prywatności +
+
+
+ +
+ + + +
+ +
+
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/rsrc/lyrics/tekstowopl/szukajwykonawcajuicewrldtytulluciddreams.txt b/test/rsrc/lyrics/tekstowopl/szukajwykonawcajuicewrldtytulluciddreams.txt new file mode 100755 index 000000000..40e8fa3cb --- /dev/null +++ b/test/rsrc/lyrics/tekstowopl/szukajwykonawcajuicewrldtytulluciddreams.txt @@ -0,0 +1,584 @@ + + + + + + + + + Wyszukiwarka - teksty piosenek, tłumaczenia piosenek, teledyski na Tekstowo.pl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + + + + + + + +
+ +
+ + +
+
+
+
+ +
+ 2 170 872 tekstów, 20 217 poszukiwanych i 376 oczekujących +
+
+ +
+ + +
+ +
+ +
+ +
+ + + + +
+ + + +
+
+ +
+ +
+
+ + +
+
+ +
+ +
+ + +
+
+
+ +
+
+ 2 170 872 tekstów, 20 217 poszukiwanych i 376 oczekujących +
+
+
+

Największy serwis z tekstami piosenek w Polsce. Każdy może znaleźć u nas teksty piosenek, teledyski oraz tłumaczenia swoich ulubionych utworów.
Zachęcamy wszystkich użytkowników do dodawania nowych tekstów, tłumaczeń i teledysków!

+
+ Reklama | + Kontakt | + FAQ + Polityka prywatności +
+
+
+ +
+ + + +
+ +
+
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/rsrc/unicode’d.mp3 b/test/rsrc/unicode’d.mp3 index ebc75ce31cfdd6bcea3ed250b2af79b3141c09ea..47b4ce7c0f19dc59dd281d1706f53955b205cafa 100644 GIT binary patch delta 555 zcmbP|G9_ih8|M0uh=>RV1{NL$24>&V;>={HqQuO+Dh0=!q|#i4kjjEohG+(LFxFvE zU{C_Gl^8%Q>|#1VafmEP1%w6CgRU1Qrd|(}f+>V)p}Hk_?5KxWis?f9&cfzYOdX)G t!ZaBs29g2$A7mId17ophCd(3V@ME__5}PF;vDnQYnQfUi+i_ge1OW03IjjHx delta 22 ecmbP|G9_ih8|KYSY&J}r1=z%xHrsJr(*yuu&j(@v diff --git a/test/test_lyrics.py b/test/test_lyrics.py index f8dd0b369..ff6794896 100644 --- a/test/test_lyrics.py +++ b/test/test_lyrics.py @@ -34,6 +34,7 @@ log = logging.getLogger('beets.test_lyrics') raw_backend = lyrics.Backend({}, log) google = lyrics.Google(MagicMock(), log) genius = lyrics.Genius(MagicMock(), log) +tekstowo = lyrics.Tekstowo(MagicMock(), log) class LyricsPluginTest(unittest.TestCase): @@ -209,6 +210,7 @@ class LyricsPluginTest(unittest.TestCase): def url_to_filename(url): url = re.sub(r'https?://|www.', '', url) + url = re.sub(r'.html', '', url) fn = "".join(x for x in url if (x.isalnum() or x == '/')) fn = fn.split('/') fn = os.path.join(LYRICS_ROOT_DIR, @@ -522,6 +524,108 @@ class GeniusFetchTest(GeniusBaseTest): # TODO: add integration test hitting real api +# test Tekstowo + +class TekstowoBaseTest(unittest.TestCase): + def setUp(self): + """Set up configuration.""" + try: + __import__('bs4') + except ImportError: + self.skipTest('Beautiful Soup 4 not available') + + +class TekstowoExtractLyricsTest(TekstowoBaseTest): + """tests Tekstowo.extract_lyrics()""" + + def setUp(self): + """Set up configuration""" + TekstowoBaseTest.setUp(self) + self.plugin = lyrics.LyricsPlugin() + + def test_good_lyrics(self): + """Ensure we are able to scrape a page with lyrics""" + url = 'https://www.tekstowo.pl/piosenka,24kgoldn,city_of_angels_1.html' + mock = MockFetchUrl() + self.assertIsNotNone(tekstowo.extract_lyrics(mock(url), + '24kGoldn', 'City of Angels')) + + def test_no_lyrics(self): + """Ensure we don't crash when the scraping the html for a Tekstowo page + doesn't contain lyrics + """ + url = 'https://www.tekstowo.pl/piosenka,beethoven,' \ + 'beethoven_piano_sonata_17_tempest_the_3rd_movement.html' + mock = MockFetchUrl() + self.assertEqual(tekstowo.extract_lyrics(mock(url), 'Beethoven', + 'Beethoven Piano Sonata 17' + 'Tempest The 3rd Movement'), + None) + + def test_song_no_match(self): + """Ensure we return None when a song does not match the search query""" + # https://github.com/beetbox/beets/issues/4406 + # expected return value None + url = 'https://www.tekstowo.pl/piosenka,bailey_bigger' \ + ',black_eyed_susan.html' + mock = MockFetchUrl() + self.assertEqual(tekstowo.extract_lyrics(mock(url), 'Kelly Bailey', + 'Black Mesa Inbound'), None) + + +class TekstowoParseSearchResultsTest(TekstowoBaseTest): + """tests Tekstowo.parse_search_results()""" + + def setUp(self): + """Set up configuration""" + TekstowoBaseTest.setUp(self) + self.plugin = lyrics.LyricsPlugin() + + def test_multiple_results(self): + """Ensure we are able to scrape a page with multiple search results""" + url = 'https://www.tekstowo.pl/szukaj,wykonawca,juice+wrld' \ + ',tytul,lucid+dreams.html' + mock = MockFetchUrl() + self.assertEqual(tekstowo.parse_search_results(mock(url)), + 'http://www.tekstowo.pl/piosenka,juice_wrld,' + 'lucid_dreams__remix__ft__lil_uzi_vert.html') + + def test_no_results(self): + """Ensure we are able to scrape a page with no search results""" + url = 'https://www.tekstowo.pl/szukaj,wykonawca,' \ + 'agfdgja,tytul,agfdgafg.html' + mock = MockFetchUrl() + self.assertEqual(tekstowo.parse_search_results(mock(url)), None) + + +class TekstowoIntegrationTest(GeniusBaseTest, LyricsAssertions): + """Tests Tekstowo lyric source with real requests""" + + def setUp(self): + """Set up configuration""" + TekstowoBaseTest.setUp(self) + self.plugin = lyrics.LyricsPlugin() + + @unittest.skipUnless( + os.environ.get('INTEGRATION_TEST', '0') == '1', + 'integration testing not enabled') + def test_normal(self): + """Ensure we can fetch a song's lyrics in the ordinary case""" + lyrics = tekstowo.fetch('Boy in Space', 'u n eye') + self.assertLyricsContentOk('u n eye', lyrics) + + @unittest.skipUnless( + os.environ.get('INTEGRATION_TEST', '0') == '1', + 'integration testing not enabled') + def test_no_matching_results(self): + """Ensure we fetch nothing if there are search results + returned but no matches""" + # https://github.com/beetbox/beets/issues/4406 + # expected return value None + lyrics = tekstowo.fetch('Kelly Bailey', 'Black Mesa Inbound') + self.assertEqual(lyrics, None) + + # test utilties class SlugTests(unittest.TestCase): From 22a5a7f9f4ac5a5278cf3faec625cb59c9df049d Mon Sep 17 00:00:00 2001 From: Luke Harder Date: Thu, 10 Nov 2022 14:46:36 -0500 Subject: [PATCH 2/5] bug 4406 fix v2 --- docs/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 33eccac09..f4267b858 100755 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -118,7 +118,7 @@ Bug fixes: default genre list. :bug:`4510` * :doc:`plugins/lyrics`: Fixed issue with Tekstowo backend not actually checking - if the found song actually matches. + if the found song matches. :bug:`4406` For packagers: From 43f1a8412ae642cef529c53ae99ad7f3c0a431f9 Mon Sep 17 00:00:00 2001 From: Luke Harder Date: Thu, 10 Nov 2022 14:53:50 -0500 Subject: [PATCH 3/5] bug 4406 fix v3 --- test/test_lyrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_lyrics.py b/test/test_lyrics.py index ff6794896..c74fb49f9 100644 --- a/test/test_lyrics.py +++ b/test/test_lyrics.py @@ -598,7 +598,7 @@ class TekstowoParseSearchResultsTest(TekstowoBaseTest): self.assertEqual(tekstowo.parse_search_results(mock(url)), None) -class TekstowoIntegrationTest(GeniusBaseTest, LyricsAssertions): +class TekstowoIntegrationTest(TekstowoBaseTest, LyricsAssertions): """Tests Tekstowo lyric source with real requests""" def setUp(self): From 4a1f25e1b1162a447b7f180ca31b270c810dce46 Mon Sep 17 00:00:00 2001 From: Luke Harder Date: Tue, 22 Nov 2022 13:25:09 -0500 Subject: [PATCH 4/5] bug 4406 fix v4 (added configurable threshold) --- beetsplug/lyrics.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 62ba7fd78..8f2cd4ff0 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -234,6 +234,7 @@ class Backend: def __init__(self, config, log): self._log = log + self._config = config @staticmethod def _encode(s): @@ -516,7 +517,8 @@ class Tekstowo(Backend): title_dist = string_dist(html_title, title) artist_dist = string_dist(html_artist, artist) - if title_dist > 0.1 or artist_dist > 0.1: + thresh = self._config['dist_thresh'].get(float) + if title_dist > thresh or artist_dist > thresh: return None lyrics_div = soup.select("div.song-text > div.inner-text") @@ -742,6 +744,7 @@ class LyricsPlugin(plugins.BeetsPlugin): 'force': False, 'local': False, 'sources': self.SOURCES, + 'dist_thresh': 0.1, }) self.config['bing_client_secret'].redact = True self.config['google_API_key'].redact = True From f155d3ba752774061cee8d7369fa38f028052fed Mon Sep 17 00:00:00 2001 From: Luke Harder Date: Tue, 22 Nov 2022 20:40:13 -0500 Subject: [PATCH 5/5] bug 4406 fix v5 (tests pass again) --- beetsplug/lyrics.py | 4 ++-- test/rsrc/unicode’d.mp3 | Bin 12820 -> 25287 bytes test/test_lyrics.py | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 8f2cd4ff0..15e02cf4f 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -234,7 +234,7 @@ class Backend: def __init__(self, config, log): self._log = log - self._config = config + self.config = config @staticmethod def _encode(s): @@ -517,7 +517,7 @@ class Tekstowo(Backend): title_dist = string_dist(html_title, title) artist_dist = string_dist(html_artist, artist) - thresh = self._config['dist_thresh'].get(float) + thresh = self.config['dist_thresh'].get(float) if title_dist > thresh or artist_dist > thresh: return None diff --git a/test/rsrc/unicode’d.mp3 b/test/rsrc/unicode’d.mp3 index 47b4ce7c0f19dc59dd281d1706f53955b205cafa..7a145f01e4b3d17c26abd4ad25101d50af8c9229 100644 GIT binary patch delta 887 zcmbP|a{MSGm#2#{3j+`orf=kW!OWDHv-t~i5aZ-J7M{rmSUDyKu<}fv#}a_V76Qw? zW0^L&i)9Z{>fW)aP2RwAWwHWm%4Co}gt;q-(vML845%O3tO%m?4;6Pp{5Fj!Kamp- lknkri%uvmzcbxqK#`Cao=jL}T0nD2P*e)|}w&S>_2>|yEI2!-} delta 54 zcmX?plyOQ5m#2#{3j+`cm~7;F!OX