add get_song_by_mbid

This commit is contained in:
Francesco De Carlo 2025-08-01 21:21:28 +02:00
parent e78ecede2d
commit 2a10a91776

View file

@ -27,3 +27,17 @@ class Song:
tags: list[str]
image_id: str
youtube_id: str
def get_song_by_mbid(mbid: str) -> Song:
conn = get_connection()
cursor = conn.cursor()
cursor.execute("SELECT * FROM songs WHERE mbid = ?", (mbid,))
row = cursor.fetchone()
conn.close()
if row is None:
raise ValueError(f"Song with MBID {mbid} not found")
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