Playliste - online
This commit is contained in:
@@ -18,9 +18,9 @@ from pathlib import Path
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# AcoustID API nøgle — gratis til open-source apps
|
||||
# https://acoustid.org/api-key
|
||||
ACOUSTID_API_KEY = "9JYq1saI1H"
|
||||
# AcoustID API nøgle — kan overskrives i Indstillinger → Afspilning
|
||||
# Registrér din egen på https://acoustid.org/new-application
|
||||
ACOUSTID_API_KEY = "71W9SJdajAI"
|
||||
ACOUSTID_API_URL = "https://api.acoustid.org/v2/lookup"
|
||||
|
||||
# Pause mellem API-kald — rolig baggrundskørsel
|
||||
|
||||
@@ -1241,11 +1241,12 @@ class MainWindow(QMainWindow):
|
||||
self._song_ended = False
|
||||
|
||||
def _sync_event_status_to_playlist(self):
|
||||
"""Gem event-fremgang (afspillet/sprunget over) til den navngivne liste."""
|
||||
"""Gem event-fremgang lokalt og mini-sync til server."""
|
||||
try:
|
||||
pl_id = self._playlist_panel.get_named_playlist_id()
|
||||
if not pl_id:
|
||||
return
|
||||
songs = self._playlist_panel.get_songs()
|
||||
statuses = self._playlist_panel.get_statuses()
|
||||
from local.local_db import get_db
|
||||
with get_db() as conn:
|
||||
@@ -1255,9 +1256,54 @@ class MainWindow(QMainWindow):
|
||||
"WHERE playlist_id=? AND position=?",
|
||||
(status, pl_id, position)
|
||||
)
|
||||
except Exception as e:
|
||||
# Hent server_id for denne playliste
|
||||
row = conn.execute(
|
||||
"SELECT api_project_id FROM playlists WHERE id=?", (pl_id,)
|
||||
).fetchone()
|
||||
server_id = row["api_project_id"] if row else None
|
||||
|
||||
# Mini-sync til server hvis online
|
||||
if server_id and self._api_token:
|
||||
self._mini_sync_to_server(server_id, songs, statuses)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _mini_sync_to_server(self, server_id: str, songs: list, statuses: list):
|
||||
"""Send kun playliste-status til server — kører i baggrundstråd."""
|
||||
import threading, urllib.request, json
|
||||
url = f"{self._api_url}/live/{server_id}/status"
|
||||
token = self._api_token
|
||||
|
||||
payload = json.dumps({
|
||||
"songs": [
|
||||
{
|
||||
"title": s.get("title", ""),
|
||||
"artist": s.get("artist", ""),
|
||||
"status": statuses[i] if i < len(statuses) else "pending",
|
||||
"position": i + 1,
|
||||
"dance": s.get("active_dance", "") or
|
||||
(s.get("dances", [""])[0] if s.get("dances") else ""),
|
||||
"duration": s.get("duration_sec", 0),
|
||||
}
|
||||
for i, s in enumerate(songs)
|
||||
]
|
||||
}).encode()
|
||||
|
||||
def _push():
|
||||
try:
|
||||
req = urllib.request.Request(
|
||||
url, data=payload, method="POST",
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {token}",
|
||||
}
|
||||
)
|
||||
urllib.request.urlopen(req, timeout=4)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
threading.Thread(target=_push, daemon=True).start()
|
||||
|
||||
def _on_state_changed(self, state: str):
|
||||
if state == "playing":
|
||||
self._btn_play.setText("⏸")
|
||||
|
||||
Reference in New Issue
Block a user