mod mbid with uuid

This commit is contained in:
Francesco De Carlo 2025-08-01 23:24:54 +02:00
parent 9ba0e04501
commit b7fed3c719

View file

@ -8,7 +8,7 @@ def init_db():
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS songs (
mbid TEXT PRIMARY KEY,
uuid TEXT PRIMARY KEY,
title TEXT NOT NULL,
artist TEXT NOT NULL,
tags TEXT NOT NULL,
@ -22,7 +22,7 @@ def init_db():
@dataclass(frozen=True)
class Song:
mbid: str
uuid: str
title: str
artist: str
tags: list[str]
@ -30,17 +30,17 @@ class Song:
youtube_id: str
def get_song_by_mbid(mbid: str) -> Song | None:
def get_song_by_uuid(uuid: str) -> Song | None:
conn = get_connection()
cursor = conn.cursor()
cursor.execute("SELECT * FROM songs WHERE mbid = ?", (mbid,))
cursor.execute("SELECT * FROM songs WHERE uuid = ?", (uuid,))
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"])
song = Song(uuid=row["uuid"], title=row["title"], artist=row["artist"], tags=row["tags"].split(","), image_id=row["lastfm_image_id"], youtube_id=row["youtube_id"])
return song
@ -54,7 +54,7 @@ def get_song_by_title_artist(title: str, artist: str) -> Song | None:
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"])
song = Song(uuid=row["uuid"], title=row["title"], artist=row["artist"], tags=row["tags"].split(","), image_id=row["lastfm_image_id"], youtube_id=row["youtube_id"])
return song
@ -64,10 +64,10 @@ def add_song(song: Song):
cursor.execute(
"""
INSERT OR REPLACE INTO songs (mbid, title, artist, tags, lastfm_image_id, youtube_id)
INSERT OR REPLACE INTO songs (uuid, title, artist, tags, lastfm_image_id, youtube_id)
VALUES (?, ?, ?, ?, ?, ?)
""",
(song.mbid, song.title, song.artist, ",".join(song.tags), song.image_id, song.youtube_id),
(song.uuid, song.title, song.artist, ",".join(song.tags), song.image_id, song.youtube_id),
) # Updates song info if it already exists
conn.commit()
conn.close()