From b34442f5d11bb118856e2c6ad9f6ae9b5ee96e36 Mon Sep 17 00:00:00 2001 From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com> Date: Tue, 15 Jun 2021 10:24:03 +0200 Subject: [PATCH] lyrics: always check for fetch_url() returning None --- beetsplug/lyrics.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 9607a5cb7..a6dc0bd6a 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -344,8 +344,10 @@ class Genius(Backend): hit_artist = hit["result"]["primary_artist"]["name"] if slug(hit_artist) == slug(artist): - return self._scrape_lyrics_from_html( - self.fetch_url(hit["result"]["url"])) + html = self.fetch_url(hit["result"]["url"]) + if not html: + return None + return self._scrape_lyrics_from_html(html) self._log.debug(u'Genius failed to find a matching artist for \'{0}\'', artist) @@ -419,12 +421,16 @@ class Tekstowo(Backend): def fetch(self, artist, title): url = self.build_url(title, artist) search_results = self.fetch_url(url) + if not search_results: + return None song_page_url = self.parse_search_results(search_results) if not song_page_url: return None song_page_html = self.fetch_url(song_page_url) + if not song_page_html: + return None return self.extract_lyrics(song_page_html) def parse_search_results(self, html): @@ -512,9 +518,6 @@ def scrape_lyrics_from_html(html): if not HAS_BEAUTIFUL_SOUP: return None - if not html: - return None - def is_text_notcode(text): length = len(text) return (length > 20 and @@ -647,6 +650,8 @@ class Google(Backend): title, artist): continue html = self.fetch_url(url_link) + if not html: + continue lyrics = scrape_lyrics_from_html(html) if not lyrics: continue