Sync playlister
This commit is contained in:
@@ -266,9 +266,33 @@ def pull(
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Egne playlister
|
||||||
|
my_playlists = []
|
||||||
|
for p in db.query(Project).filter_by(owner_id=me.id).all():
|
||||||
|
songs_out = []
|
||||||
|
for ps in p.project_songs:
|
||||||
|
song = db.query(Song).filter_by(id=ps.song_id).first()
|
||||||
|
if not song:
|
||||||
|
continue
|
||||||
|
songs_out.append({
|
||||||
|
"title": song.title,
|
||||||
|
"artist": song.artist,
|
||||||
|
"position": ps.position,
|
||||||
|
"status": ps.status,
|
||||||
|
"is_workshop": ps.is_workshop,
|
||||||
|
"dance_override": ps.dance_override or "",
|
||||||
|
})
|
||||||
|
my_playlists.append({
|
||||||
|
"server_id": p.id,
|
||||||
|
"name": p.name,
|
||||||
|
"description": p.description or "",
|
||||||
|
"songs": sorted(songs_out, key=lambda x: x["position"]),
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"levels": levels,
|
"levels": levels,
|
||||||
"dances": dances,
|
"dances": dances,
|
||||||
"community": community,
|
"community": community,
|
||||||
"shared": shared,
|
"shared": shared,
|
||||||
|
"my_playlists": my_playlists,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,11 +220,11 @@ class SyncManager:
|
|||||||
# ── Anvend pull ───────────────────────────────────────────────────────────
|
# ── Anvend pull ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
def _apply_pull(self, data: dict):
|
def _apply_pull(self, data: dict):
|
||||||
"""Gem server-data lokalt — opdaterer dans-info og community forslag."""
|
"""Gem server-data lokalt — opdaterer dans-info og importerer playlister."""
|
||||||
conn = sqlite3.connect(self._db_path)
|
conn = sqlite3.connect(self._db_path)
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
|
|
||||||
# Opdater dans-info fra server (koreograf, links, noter)
|
# Opdater dans-info fra server
|
||||||
for d in data.get("dances", []):
|
for d in data.get("dances", []):
|
||||||
if not d.get("name"):
|
if not d.get("name"):
|
||||||
continue
|
continue
|
||||||
@@ -241,5 +241,43 @@ class SyncManager:
|
|||||||
""", (d.get("choreographer",""), d.get("video_url",""),
|
""", (d.get("choreographer",""), d.get("video_url",""),
|
||||||
d.get("stepsheet_url",""), existing["id"]))
|
d.get("stepsheet_url",""), existing["id"]))
|
||||||
|
|
||||||
|
# Importer egne playlister fra server hvis de ikke findes lokalt
|
||||||
|
for pl in data.get("my_playlists", []):
|
||||||
|
server_id = pl.get("server_id")
|
||||||
|
name = pl.get("name", "")
|
||||||
|
if not server_id or not name:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Tjek om listen allerede eksisterer lokalt
|
||||||
|
existing = conn.execute(
|
||||||
|
"SELECT id FROM playlists WHERE api_project_id=?", (server_id,)
|
||||||
|
).fetchone()
|
||||||
|
if existing:
|
||||||
|
continue # Allerede importeret — spring over
|
||||||
|
|
||||||
|
# Opret liste
|
||||||
|
cur = conn.execute(
|
||||||
|
"INSERT INTO playlists (name, description, api_project_id, is_linked, server_permission) "
|
||||||
|
"VALUES (?,?,?,1,'edit')",
|
||||||
|
(name, pl.get("description",""), server_id)
|
||||||
|
)
|
||||||
|
pl_id = cur.lastrowid
|
||||||
|
|
||||||
|
# Indsæt sange med lokal matching
|
||||||
|
for song_data in pl.get("songs", []):
|
||||||
|
local = conn.execute(
|
||||||
|
"SELECT id FROM songs WHERE title=? AND artist=? AND file_missing=0 LIMIT 1",
|
||||||
|
(song_data["title"], song_data["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 ""))
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user