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):

+ +
+ +
+
+ +
+ +
+
+ + + +
+
+ + + + +
+ +
+
+ + +
+
+ +
+
+
+
+ tekstowo.pl
+
+ +
+
+ + +
+
+
+ +
+
+ 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):

+ +
+ +
+
+ +
+ +
+
+ + + +
+
+ + + + +
+ +
+
+ + +
+
+ +
+
+
+
+ tekstowo.pl
+
+ +
+
+ + +
+
+
+ +
+
+ 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):

+ +
+ +
+
+ +
+ +
+
+ + + +
+
+ + + + +
+ +
+
+ + +
+
+ +
+
+
+
+ tekstowo.pl
+
+ +
+
+ + +
+
+
+ +
+
+ 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 +
+
+ + + + + + +
+
+
+ +
+
+ +
+ +
+
+ + +
+
+ +
+
+
+
+ tekstowo.pl
+
+ +
+
+ + +
+
+
+ +
+
+ 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 +
+
+ +
+ + +
+ +
+ +
+ +
+ + + + +
+ + + +
+
+ +
+ +
+
+ + +
+
+ +
+
+
+
+ tekstowo.pl
+
+ +
+
+ + +
+
+
+ +
+
+ 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 ebc75ce31..47b4ce7c0 100644 Binary files a/test/rsrc/unicode’d.mp3 and b/test/rsrc/unicode’d.mp3 differ 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):