Bedre sync
This commit is contained in:
@@ -158,30 +158,28 @@ def scan_library(library_id: int, library_path: str, db_path: str,
|
||||
# Opret eller opdater fil-post
|
||||
_upsert_file_conn(conn, song_id, path_str, file_format, mtime, extra_tags)
|
||||
|
||||
# Dans-tags fra fil
|
||||
# Dans-tags fra fil — synkroniser altid fra filen
|
||||
file_dances = tags.get("dances", [])
|
||||
if file_dances:
|
||||
existing_count = conn.execute(
|
||||
"SELECT COUNT(*) FROM song_dances WHERE song_id=?", (song_id,)
|
||||
).fetchone()[0]
|
||||
if existing_count == 0:
|
||||
import uuid
|
||||
for order, dance_name in enumerate(file_dances, start=1):
|
||||
dance_row = conn.execute(
|
||||
"SELECT id FROM dances WHERE name=? COLLATE NOCASE LIMIT 1",
|
||||
(dance_name,)
|
||||
).fetchone()
|
||||
if not dance_row:
|
||||
cur = conn.execute(
|
||||
"INSERT INTO dances (name) VALUES (?)", (dance_name,)
|
||||
)
|
||||
dance_id = cur.lastrowid
|
||||
else:
|
||||
dance_id = dance_row["id"]
|
||||
conn.execute(
|
||||
"INSERT OR IGNORE INTO song_dances (id, song_id, dance_id, dance_order) VALUES (?,?,?,?)",
|
||||
(str(uuid.uuid4()), song_id, dance_id, order)
|
||||
import uuid
|
||||
# Slet eksisterende og genindsæt fra filen
|
||||
conn.execute("DELETE FROM song_dances WHERE song_id=?", (song_id,))
|
||||
for order, dance_name in enumerate(file_dances, start=1):
|
||||
dance_row = conn.execute(
|
||||
"SELECT id FROM dances WHERE name=? COLLATE NOCASE LIMIT 1",
|
||||
(dance_name,)
|
||||
).fetchone()
|
||||
if not dance_row:
|
||||
cur = conn.execute(
|
||||
"INSERT INTO dances (name) VALUES (?)", (dance_name,)
|
||||
)
|
||||
dance_id = cur.lastrowid
|
||||
else:
|
||||
dance_id = dance_row["id"]
|
||||
conn.execute(
|
||||
"INSERT OR IGNORE INTO song_dances (id, song_id, dance_id, dance_order) VALUES (?,?,?,?)",
|
||||
(str(uuid.uuid4()), song_id, dance_id, order)
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user