diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 3a56cc738..71969cab3 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -359,14 +359,9 @@ class Genius(Backend): 'User-Agent': USER_AGENT, } - def lyrics_from_song_api_path(self, song_api_path): - song_url = self.base_url + song_api_path - response = requests.get(song_url, headers=self.headers) - json = response.json() - path = json["response"]["song"]["path"] - + def lyrics_from_song_page(self, page_url): # Gotta go regular html scraping... come on Genius. - page_url = "https://genius.com" + path + self._log.debug(u'fetching lyrics from: {0}', page_url) try: page = requests.get(page_url) except requests.RequestException as exc: @@ -404,7 +399,6 @@ class Genius(Backend): self._log.debug(u'Genius API request returned invalid JSON') return None - song_info = None for hit in json["response"]["hits"]: # Genius uses zero-width characters to denote lowercase # artist names. @@ -412,15 +406,9 @@ class Genius(Backend): strip(u'\u200b').lower() if hit_artist == artist.lower(): - song_info = hit - break + return self.lyrics_from_song_page(hit["result"]["url"]) - if song_info: - self._log.debug(u'fetched: {0}', song_info["result"]["url"]) - song_api_path = song_info["result"]["api_path"] - return self.lyrics_from_song_api_path(song_api_path) - else: - self._log.debug(u'genius: no matching artist') + self._log.debug(u'genius: no matching artist') class LyricsWiki(SymbolsReplaced): diff --git a/test/test_lyrics.py b/test/test_lyrics.py index 81d62fea9..d0507c16f 100644 --- a/test/test_lyrics.py +++ b/test/test_lyrics.py @@ -456,7 +456,7 @@ class LyricsGeniusBaseTest(unittest.TestCase): self.skipTest("Python's built-in HTML parser is not good enough") -class LyricsGeniusScrapTest(LyricsGeniusBaseTest): +class LyricsGeniusScrapeTest(LyricsGeniusBaseTest): """Checks that Genius backend works as intended. """ @@ -469,12 +469,12 @@ class LyricsGeniusScrapTest(LyricsGeniusBaseTest): @patch.object(requests, 'get', GeniusMockGet()) def test_no_lyrics_div(self): - """Ensure that `lyrics_from_song_api_path` doesn't crash when the html - for a Genius page contain
+ """Ensure that `lyrics_from_song_page` doesn't crash when the html + for a Genius page doesn't contain
""" # https://github.com/beetbox/beets/issues/3535 # expected return value None - self.assertEqual(genius.lyrics_from_song_api_path('/nolyric'), + self.assertEqual(genius.lyrics_from_song_page('https://genius.com/sample'), None)