add add_song

This commit is contained in:
Francesco De Carlo 2025-08-01 21:31:53 +02:00
parent 2a10a91776
commit 386dd64a7a

View file

@ -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()