diff --git a/backend/src/song.py b/backend/src/song.py index 51509ce..598975f 100644 --- a/backend/src/song.py +++ b/backend/src/song.py @@ -41,3 +41,18 @@ def get_song_by_mbid(mbid: str) -> Song: 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() + + cursor.execute( + """ + INSERT OR REPLACE INTO songs (mbid, title, artist, tags, lastfm_image_id, youtube_id) + VALUES (?, ?, ?, ?, ?, ?) + """, + (song.mbid, song.title, song.artist, ",".join(song.tags), song.image_id, song.youtube_id), + ) # Updates song info if it already exists + conn.commit() + conn.close()