diff --git a/backend/src/song.py b/backend/src/song.py index 8570033..51509ce 100644 --- a/backend/src/song.py +++ b/backend/src/song.py @@ -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