Skip to content

Commit

Permalink
Fix SSLError and TypeError when fetching synced lyrics (#1981)
Browse files Browse the repository at this point in the history
Co-authored-by: kuba <xnetcat.dev@gmail.com>
  • Loading branch information
Mahasvan and xnetcat authored Jan 5, 2024
1 parent 9037a96 commit 18b44f3
Showing 1 changed file with 18 additions and 4 deletions.
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

0 comments on commit 18b44f3

Please sign in to comment.