Merge remote-tracking branch 'refs/remotes/origin/main'

This commit is contained in:
Leonardo Segala 2025-08-01 23:29:44 +02:00
commit 66188ba181

View file

@ -8,7 +8,7 @@ from .connect import get_connection
def init_db(db: Cursor): def init_db(db: Cursor):
db.execute(""" db.execute("""
CREATE TABLE IF NOT EXISTS songs ( CREATE TABLE IF NOT EXISTS songs (
mbid TEXT PRIMARY KEY, uuid TEXT PRIMARY KEY,
title TEXT NOT NULL, title TEXT NOT NULL,
artist TEXT NOT NULL, artist TEXT NOT NULL,
tags TEXT NOT NULL, tags TEXT NOT NULL,
@ -20,7 +20,7 @@ def init_db(db: Cursor):
@dataclass(frozen=True) @dataclass(frozen=True)
class Song: class Song:
mbid: str uuid: str
title: str title: str
artist: str artist: str
tags: list[str] tags: list[str]
@ -28,17 +28,17 @@ class Song:
youtube_id: str youtube_id: str
def get_song_by_mbid(mbid: str) -> Song | None: def get_song_by_uuid(uuid: str) -> Song | None:
conn = get_connection() conn = get_connection()
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute("SELECT * FROM songs WHERE mbid = ?", (mbid,)) cursor.execute("SELECT * FROM songs WHERE uuid = ?", (uuid,))
row = cursor.fetchone() row = cursor.fetchone()
conn.close() conn.close()
if row is None: if row is None:
return 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 return song
@ -52,7 +52,7 @@ def get_song_by_title_artist(title: str, artist: str) -> Song | None:
if row is None: if row is None:
return 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 return song
@ -62,7 +62,7 @@ def add_song_in_db(title: str, artist: str, tags: list[str], image_id: str, yt_i
cursor.execute( 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 (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?)
""", """,
(str(uuid.uuid4()), title, artist, ",".join(tags), image_id, yt_id), (str(uuid.uuid4()), title, artist, ",".join(tags), image_id, yt_id),