This commit is contained in:
2026-04-13 16:16:20 +02:00
parent d056f02f78
commit b805bd77e7
3 changed files with 62 additions and 62 deletions

View File

@@ -79,51 +79,6 @@ class SyncManager:
)
except Exception:
pass
# Importer brugerens egne dans-tags
for tag in data.get("song_tags", []):
title = tag.get("song_title", "")
artist = tag.get("song_artist", "")
dance_name = tag.get("dance_name", "")
level_name = tag.get("level_name", "")
if not title or not dance_name:
continue
song = conn.execute(
"SELECT id FROM songs WHERE title=? AND artist=? LIMIT 1",
(title, artist)
).fetchone()
if not song:
continue
level_row = conn.execute(
"SELECT id FROM dance_levels WHERE name=? COLLATE NOCASE LIMIT 1",
(level_name,)
).fetchone() if level_name else None
level_id = level_row["id"] if level_row else None
dance_row = conn.execute(
"SELECT id FROM dances WHERE name=? AND level_id IS ? LIMIT 1",
(dance_name, level_id)
).fetchone()
if not dance_row:
cur = conn.execute(
"INSERT OR IGNORE INTO dances (name, level_id) VALUES (?,?)",
(dance_name, level_id)
)
dance_id = cur.lastrowid
else:
dance_id = dance_row["id"]
existing = conn.execute(
"SELECT id FROM song_dances WHERE song_id=? AND dance_id=?",
(song["id"], dance_id)
).fetchone()
if not existing:
max_order = conn.execute(
"SELECT COALESCE(MAX(dance_order),0) FROM song_dances WHERE song_id=?",
(song["id"],)
).fetchone()[0]
conn.execute(
"INSERT INTO song_dances (song_id, dance_id, dance_order) VALUES (?,?,?)",
(song["id"], dance_id, max_order + 1)
)
conn.commit()
conn.close()
@@ -323,21 +278,39 @@ class SyncManager:
)
pl_id = cur.lastrowid
# Indsæt sange med lokal matching
# Indsæt sange — opret dem lokalt hvis de ikke findes endnu
position = 1
for song_data in pl.get("songs", []):
title = song_data.get("title", "")
artist = song_data.get("artist", "")
if not title:
continue
# Find sangen lokalt
local = conn.execute(
"SELECT id FROM songs WHERE title=? AND artist=? AND file_missing=0 LIMIT 1",
(song_data["title"], song_data["artist"])
"SELECT id FROM songs WHERE title=? AND artist=? LIMIT 1",
(title, artist)
).fetchone()
if local:
conn.execute("""
INSERT INTO playlist_songs
(playlist_id, song_id, position, status, is_workshop, dance_override)
VALUES (?,?,?,?,?,?)
""", (pl_id, local["id"], song_data["position"],
song_data.get("status","pending"),
1 if song_data.get("is_workshop") else 0,
song_data.get("dance_override","") or ""))
if not local:
# Opret som file_missing=1 — kobles til rigtig fil ved næste scan
import uuid
new_id = str(uuid.uuid4())
conn.execute(
"INSERT OR IGNORE INTO songs (id, title, artist, file_missing) VALUES (?,?,?,1)",
(new_id, title, artist)
)
local_id = new_id
else:
local_id = local["id"]
conn.execute("""
INSERT OR IGNORE INTO playlist_songs
(playlist_id, song_id, position, status, is_workshop, dance_override)
VALUES (?,?,?,?,?,?)
""", (pl_id, local_id, position,
song_data.get("status","pending"),
1 if song_data.get("is_workshop") else 0,
song_data.get("dance_override","") or ""))
position += 1
conn.commit()
conn.close()