mod get_song_by_mbid returns None if it finds nothing
This commit is contained in:
parent
fbd9803965
commit
0f06261c96
1 changed files with 2 additions and 2 deletions
|
@ -29,7 +29,7 @@ class Song:
|
||||||
youtube_id: str
|
youtube_id: str
|
||||||
|
|
||||||
|
|
||||||
def get_song_by_mbid(mbid: str) -> Song:
|
def get_song_by_mbid(mbid: str) -> Song | None:
|
||||||
conn = get_connection()
|
conn = get_connection()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("SELECT * FROM songs WHERE mbid = ?", (mbid,))
|
cursor.execute("SELECT * FROM songs WHERE mbid = ?", (mbid,))
|
||||||
|
@ -37,7 +37,7 @@ def get_song_by_mbid(mbid: str) -> Song:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
if row is None:
|
if row is None:
|
||||||
raise ValueError(f"Song with MBID {mbid} not found")
|
return None
|
||||||
|
|
||||||
song = Song(mbid=row["mbid"], title=row["title"], artist=row["artist"], tags=row["tags"].split(","), image_id=row["lastfm_image_id"], youtube_id=row["youtube_id"])
|
song = Song(mbid=row["mbid"], title=row["title"], artist=row["artist"], tags=row["tags"].split(","), image_id=row["lastfm_image_id"], youtube_id=row["youtube_id"])
|
||||||
return song
|
return song
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue