diff --git a/backend/src/song.py b/backend/src/song.py index 9b95add..76ab0c8 100644 --- a/backend/src/song.py +++ b/backend/src/song.py @@ -43,6 +43,20 @@ def get_song_by_mbid(mbid: str) -> Song | None: return song +def get_song_by_title_artist(title: str, artist: str) -> Song | None: + conn = get_connection() + cursor = conn.cursor() + cursor.execute("SELECT * FROM songs WHERE title = ? AND artist = ?", (title, artist)) + row = cursor.fetchone() + conn.close() + + if row is None: + 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"]) + return song + + def add_song(song: Song): conn = get_connection() cursor = conn.cursor()