Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SSLError and TypeError when fetching synced lyrics #1981

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions spotdl/providers/lyrics/synced.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from typing import Dict, List, Optional

import requests
import syncedlyrics

from spotdl.providers.lyrics.base import LyricsProvider
Expand Down Expand Up @@ -46,7 +47,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

Expand All @@ -59,6 +60,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
Loading