diff --git a/spotdl/download/downloader.py b/spotdl/download/downloader.py index bdc1edb7f..ec7f43648 100644 --- a/spotdl/download/downloader.py +++ b/spotdl/download/downloader.py @@ -171,6 +171,8 @@ def __init__( found_files = gather_known_songs(self.settings["output"], scan_format) + logger.debug("Found %s %s files", len(found_files), scan_format) + for song_url, song_paths in found_files.items(): known_paths = self.known_songs.get(song_url) if known_paths is None: diff --git a/spotdl/providers/audio/bandcamp.py b/spotdl/providers/audio/bandcamp.py index d5abe9477..114ddee8f 100644 --- a/spotdl/providers/audio/bandcamp.py +++ b/spotdl/providers/audio/bandcamp.py @@ -168,7 +168,6 @@ class BandCamp(AudioProvider): SUPPORTS_ISRC = False GET_RESULTS_OPTS: List[Dict[str, Any]] = [{}] - def get_results(self, search_term: str, *_args, **_kwargs) -> List[Result]: """ Get results from slider.kz diff --git a/spotdl/providers/lyrics/azlyrics.py b/spotdl/providers/lyrics/azlyrics.py index 5513d174f..452224655 100644 --- a/spotdl/providers/lyrics/azlyrics.py +++ b/spotdl/providers/lyrics/azlyrics.py @@ -23,16 +23,7 @@ def __init__(self): self.session = requests.Session() self.session.headers.update(self.headers) - self.session.get("https://www.azlyrics.com/") - - resp = self.session.get("https://www.azlyrics.com/geo.js") - - # extract value from js code - js_code = resp.text - start_index = js_code.find('value"') + 9 - end_index = js_code[start_index:].find('");') - - self.x_code = js_code[start_index : start_index + end_index] + self.x_code = self.get_x_code() def get_results(self, name: str, artists: List[str], **_) -> Dict[str, str]: """ @@ -47,6 +38,12 @@ def get_results(self, name: str, artists: List[str], **_) -> Dict[str, str]: - A dictionary with the results. (The key is the title and the value is the url.) """ + if self.x_code is None: + self.x_code = self.get_x_code() + + if self.x_code is None: + return {} + # Join every artist by comma in artists artist_str = ", ".join(artist for artist in artists if artist) @@ -122,3 +119,29 @@ def extract_lyrics(self, url: str, **_) -> Optional[str]: lyrics = lyrics_div.get_text().strip() return lyrics + + def get_x_code(self) -> Optional[str]: + """ + Returns the x_code used by AZLyrics. + + ### Returns + - The x_code used by AZLyrics or None if it couldn't be retrieved. + """ + + x_code = None + + try: + self.session.get("https://www.azlyrics.com/") + + resp = self.session.get("https://www.azlyrics.com/geo.js") + + # extract value from js code + js_code = resp.text + start_index = js_code.find('value"') + 9 + end_index = js_code[start_index:].find('");') + + x_code = js_code[start_index : start_index + end_index] + except requests.ConnectionError: + pass + + return x_code