From 2a10a917760b0030c49d4237c5b755f7e1613e54 Mon Sep 17 00:00:00 2001 From: panzerotto Date: Fri, 1 Aug 2025 21:21:28 +0200 Subject: [PATCH] add get_song_by_mbid --- backend/src/song.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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