mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-12-29 13:21:22 +00:00
Refactor exceptions
* Suffix names for custom exceptions with "Error" * Introduce exceptions for when the coressponding encoder isn't found
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class LyricsNotFound(Exception):
|
||||
class LyricsNotFoundError(Exception):
|
||||
__module__ = Exception.__module__
|
||||
|
||||
def __init__(self, message=None):
|
||||
super(LyricsNotFound, self).__init__(message)
|
||||
super(LyricsNotFoundError, self).__init__(message)
|
||||
|
||||
@@ -2,7 +2,7 @@ from bs4 import BeautifulSoup
|
||||
import urllib.request
|
||||
|
||||
from spotdl.lyrics.lyric_base import LyricBase
|
||||
from spotdl.lyrics.exceptions import LyricsNotFound
|
||||
from spotdl.lyrics.exceptions import LyricsNotFoundError
|
||||
|
||||
BASE_URL = "https://genius.com"
|
||||
|
||||
@@ -26,7 +26,7 @@ class Genius(LyricBase):
|
||||
try:
|
||||
response = urllib.request.urlopen(request, timeout=timeout)
|
||||
except urllib.request.HTTPError:
|
||||
raise LyricsNotFound(
|
||||
raise LyricsNotFoundError(
|
||||
"Could not find lyrics for {} - {} at URL: {}".format(
|
||||
self.artist, self.song, url
|
||||
)
|
||||
@@ -40,7 +40,7 @@ class Genius(LyricBase):
|
||||
if lyrics_paragraph:
|
||||
return lyrics_paragraph.get_text()
|
||||
else:
|
||||
raise LyricsNotFound("The lyrics for this track are yet to be released.")
|
||||
raise LyricsNotFoundError("The lyrics for this track are yet to be released.")
|
||||
|
||||
def get_lyrics(self, linesep="\n", timeout=None):
|
||||
url = self._guess_lyric_url()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import lyricwikia
|
||||
|
||||
from spotdl.lyrics.lyric_base import LyricBase
|
||||
from spotdl.lyrics.exceptions import LyricsNotFound
|
||||
from spotdl.lyrics.exceptions import LyricsNotFoundError
|
||||
|
||||
|
||||
class LyricWikia(LyricBase):
|
||||
@@ -13,6 +13,6 @@ class LyricWikia(LyricBase):
|
||||
try:
|
||||
lyrics = lyricwikia.get_lyrics(self.artist, self.song, linesep, timeout)
|
||||
except lyricwikia.LyricsNotFound as e:
|
||||
raise LyricsNotFound(e.args[0])
|
||||
raise LyricsNotFoundError(e.args[0])
|
||||
else:
|
||||
return lyrics
|
||||
|
||||
@@ -33,5 +33,5 @@ class TestGenius:
|
||||
raise urllib.request.HTTPError("", "", "", "", "")
|
||||
|
||||
monkeypatch.setattr("urllib.request.urlopen", mocked_urlopen)
|
||||
with pytest.raises(exceptions.LyricsNotFound):
|
||||
with pytest.raises(exceptions.LyricsNotFoundError):
|
||||
track.get_lyrics()
|
||||
|
||||
@@ -25,11 +25,11 @@ class TestLyricWikia:
|
||||
def lyricwikia_lyrics_not_found(msg):
|
||||
raise lyricwikia.LyricsNotFound(msg)
|
||||
|
||||
# Wrap `lyricwikia.LyricsNotFound` with `exceptions.LyricsNotFound` error.
|
||||
# Wrap `lyricwikia.LyricsNotFoundError` with `exceptions.LyricsNotFoundError` error.
|
||||
monkeypatch.setattr(
|
||||
"lyricwikia.get_lyrics",
|
||||
lambda a, b, c, d: lyricwikia_lyrics_not_found("Nope, no lyrics."),
|
||||
)
|
||||
track = LyricWikia("Lyricwikia", "Lyricwikia")
|
||||
with pytest.raises(exceptions.LyricsNotFound):
|
||||
with pytest.raises(exceptions.LyricsNotFoundError):
|
||||
track.get_lyrics()
|
||||
|
||||
Reference in New Issue
Block a user