From c04c9c486191b542de6c492a07fba76ddc4db48f Mon Sep 17 00:00:00 2001 From: Mahas1 Date: Tue, 12 Dec 2023 22:10:13 +0530 Subject: [PATCH 1/5] Fix SSLError and TypeError when fetching synced lyrics --- spotdl/providers/lyrics/synced.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/spotdl/providers/lyrics/synced.py b/spotdl/providers/lyrics/synced.py index 200fd6a4e..b76cffa15 100644 --- a/spotdl/providers/lyrics/synced.py +++ b/spotdl/providers/lyrics/synced.py @@ -2,9 +2,8 @@ Synced lyrics provider using the syncedlyrics library """ -from typing import Dict, List, Optional - import syncedlyrics +from typing import Dict, List, Optional from spotdl.providers.lyrics.base import LyricsProvider @@ -46,7 +45,7 @@ def extract_lyrics(self, url: str, **kwargs) -> Optional[str]: raise NotImplementedError - def get_lyrics(self, name: str, artists: List[str], **_) -> Optional[str]: + def get_lyrics(self, name: str, artists: List[str], **kwargs) -> Optional[str]: """ Try to get lyrics using syncedlyrics @@ -59,6 +58,19 @@ def get_lyrics(self, name: str, artists: List[str], **_) -> Optional[str]: - The lyrics of the song or None if no lyrics were found. """ - lyrics = syncedlyrics.search(f"{name} - {artists[0]}", allow_plain_format=True) - - return lyrics + try: + lyrics = syncedlyrics.search(f"{name} - {artists[0]}", + allow_plain_format=kwargs.get("allow_plain_format", True)) + return lyrics + except requests.exceptions.SSLError: + # Max retries reached + return None + except TypeError: + # Error at syncedlyrics.providers.musixmatch L89 - Because `body` is occasionally an empty list + # instead of a dictionary. + # We get this error when allow_plain_format is set to True, and there are no synced lyrics present + # Because its empty, we know there are no lyrics + return None + except: + # Potential unhandled exceptions caused by syncedlyrics + return None From 67334d5c6b67b9b90d222a55cac59f86116f5d59 Mon Sep 17 00:00:00 2001 From: Mahas1 Date: Tue, 12 Dec 2023 22:20:55 +0530 Subject: [PATCH 2/5] Fix errors --- spotdl/providers/lyrics/synced.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spotdl/providers/lyrics/synced.py b/spotdl/providers/lyrics/synced.py index b76cffa15..1917bc176 100644 --- a/spotdl/providers/lyrics/synced.py +++ b/spotdl/providers/lyrics/synced.py @@ -2,9 +2,11 @@ Synced lyrics provider using the syncedlyrics library """ -import syncedlyrics from typing import Dict, List, Optional +import requests +import syncedlyrics + from spotdl.providers.lyrics.base import LyricsProvider __all__ = ["Synced"] From 9c97a2f70392c7a97811136a8fb372997cd73bb5 Mon Sep 17 00:00:00 2001 From: Mahas1 Date: Tue, 12 Dec 2023 22:24:01 +0530 Subject: [PATCH 3/5] Clean up code to pass tests --- spotdl/providers/lyrics/synced.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spotdl/providers/lyrics/synced.py b/spotdl/providers/lyrics/synced.py index 1917bc176..15158e310 100644 --- a/spotdl/providers/lyrics/synced.py +++ b/spotdl/providers/lyrics/synced.py @@ -68,11 +68,11 @@ def get_lyrics(self, name: str, artists: List[str], **kwargs) -> Optional[str]: # Max retries reached return None except TypeError: - # Error at syncedlyrics.providers.musixmatch L89 - Because `body` is occasionally an empty list - # instead of a dictionary. - # We get this error when allow_plain_format is set to True, and there are no synced lyrics present + # Error at syncedlyrics.providers.musixmatch L89 - + # Because `body` is occasionally an empty list instead of a dictionary. + # We get this error when allow_plain_format is set to True, + # and there are no synced lyrics present # Because its empty, we know there are no lyrics return None - except: - # Potential unhandled exceptions caused by syncedlyrics + finally: return None From 5e69e408760e151fbd3cb3f007d7dde2f972e44f Mon Sep 17 00:00:00 2001 From: Mahas1 Date: Tue, 12 Dec 2023 22:27:01 +0530 Subject: [PATCH 4/5] remove `finally` clause --- spotdl/providers/lyrics/synced.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/spotdl/providers/lyrics/synced.py b/spotdl/providers/lyrics/synced.py index 15158e310..5980f3018 100644 --- a/spotdl/providers/lyrics/synced.py +++ b/spotdl/providers/lyrics/synced.py @@ -74,5 +74,3 @@ def get_lyrics(self, name: str, artists: List[str], **kwargs) -> Optional[str]: # and there are no synced lyrics present # Because its empty, we know there are no lyrics return None - finally: - return None From 41ab7402d52a2ea813c8172944f8461c5104b8ea Mon Sep 17 00:00:00 2001 From: Mahas1 Date: Thu, 14 Dec 2023 10:38:01 +0530 Subject: [PATCH 5/5] Black formatting --- spotdl/providers/lyrics/synced.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spotdl/providers/lyrics/synced.py b/spotdl/providers/lyrics/synced.py index 5980f3018..d6cc6626e 100644 --- a/spotdl/providers/lyrics/synced.py +++ b/spotdl/providers/lyrics/synced.py @@ -61,8 +61,10 @@ def get_lyrics(self, name: str, artists: List[str], **kwargs) -> Optional[str]: """ try: - lyrics = syncedlyrics.search(f"{name} - {artists[0]}", - allow_plain_format=kwargs.get("allow_plain_format", True)) + lyrics = syncedlyrics.search( + f"{name} - {artists[0]}", + allow_plain_format=kwargs.get("allow_plain_format", True), + ) return lyrics except requests.exceptions.SSLError: # Max retries reached