Playliste - online
This commit is contained in:
@@ -8,7 +8,7 @@ from app.models import (
|
|||||||
PlaylistShare, CommunityDance, CommunityDanceAlt, DanceAltRating,
|
PlaylistShare, CommunityDance, CommunityDanceAlt, DanceAltRating,
|
||||||
SongDance, SongAltDance,
|
SongDance, SongAltDance,
|
||||||
)
|
)
|
||||||
from app.routers import auth, projects, songs, alternatives, dances, sync, sharing
|
from app.routers import auth, projects, songs, alternatives, dances, sync, sharing, live
|
||||||
from app.websocket.manager import router as ws_router
|
from app.websocket.manager import router as ws_router
|
||||||
|
|
||||||
# Opret tabeller hvis de ikke findes
|
# Opret tabeller hvis de ikke findes
|
||||||
@@ -35,6 +35,7 @@ app.include_router(alternatives.router)
|
|||||||
app.include_router(dances.router)
|
app.include_router(dances.router)
|
||||||
app.include_router(sync.router)
|
app.include_router(sync.router)
|
||||||
app.include_router(sharing.router)
|
app.include_router(sharing.router)
|
||||||
|
app.include_router(live.router)
|
||||||
|
|
||||||
|
|
||||||
@app.on_event("startup")
|
@app.on_event("startup")
|
||||||
|
|||||||
108
linedance-api/app/routers/live.py
Normal file
108
linedance-api/app/routers/live.py
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
"""
|
||||||
|
live.py — Live playliste-status til storskærm/mobil.
|
||||||
|
Appen pusher status hertil, storskærmen poller hvert 5 sek.
|
||||||
|
"""
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import Optional
|
||||||
|
import json
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
from app.core.database import get_db
|
||||||
|
from app.core.security import get_current_user
|
||||||
|
from app.models import User, Project
|
||||||
|
|
||||||
|
router = APIRouter(prefix="/live", tags=["live"])
|
||||||
|
|
||||||
|
# In-memory cache: server_id → {songs, updated_at}
|
||||||
|
_live_cache: dict = {}
|
||||||
|
|
||||||
|
|
||||||
|
class SongStatus(BaseModel):
|
||||||
|
title: str
|
||||||
|
artist: str = ""
|
||||||
|
status: str = "pending"
|
||||||
|
position: int
|
||||||
|
dance: str = ""
|
||||||
|
duration: int = 0
|
||||||
|
|
||||||
|
|
||||||
|
class LiveStatus(BaseModel):
|
||||||
|
songs: list[SongStatus]
|
||||||
|
|
||||||
|
|
||||||
|
# ── Push fra app ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
@router.post("/{project_id}/status")
|
||||||
|
def push_status(
|
||||||
|
project_id: str,
|
||||||
|
data: LiveStatus,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
me: User = Depends(get_current_user),
|
||||||
|
):
|
||||||
|
"""App pusher aktuel playliste-status."""
|
||||||
|
p = db.query(Project).filter_by(id=project_id, owner_id=me.id).first()
|
||||||
|
if not p:
|
||||||
|
raise HTTPException(404, "Playliste ikke fundet")
|
||||||
|
|
||||||
|
_live_cache[project_id] = {
|
||||||
|
"name": p.name,
|
||||||
|
"songs": [s.model_dump() for s in data.songs],
|
||||||
|
"updated_at": datetime.now(timezone.utc).isoformat(),
|
||||||
|
}
|
||||||
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
|
# ── Pull til storskærm ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
@router.get("/{project_id}")
|
||||||
|
def get_live_status(project_id: str, db: Session = Depends(get_db)):
|
||||||
|
"""Storskærm poller dette endpoint — ingen login krævet."""
|
||||||
|
# Tjek at playlisten eksisterer og er tilgængelig
|
||||||
|
p = db.query(Project).filter_by(id=project_id).first()
|
||||||
|
if not p:
|
||||||
|
raise HTTPException(404, "Playliste ikke fundet")
|
||||||
|
|
||||||
|
cached = _live_cache.get(project_id)
|
||||||
|
if cached:
|
||||||
|
return cached
|
||||||
|
|
||||||
|
# Ingen live data endnu — returner statisk data fra DB
|
||||||
|
from app.models import ProjectSong, Song
|
||||||
|
songs = []
|
||||||
|
for ps in sorted(p.project_songs, key=lambda x: x.position):
|
||||||
|
song = db.query(Song).filter_by(id=ps.song_id).first()
|
||||||
|
if not song:
|
||||||
|
continue
|
||||||
|
songs.append({
|
||||||
|
"title": song.title,
|
||||||
|
"artist": song.artist,
|
||||||
|
"status": ps.status or "pending",
|
||||||
|
"position": ps.position,
|
||||||
|
"dance": ps.dance_override or "",
|
||||||
|
"duration": song.duration_sec or 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
"name": p.name,
|
||||||
|
"songs": songs,
|
||||||
|
"updated_at": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# ── Liste over aktive live-playlister ─────────────────────────────────────────
|
||||||
|
|
||||||
|
@router.get("/")
|
||||||
|
def list_live(db: Session = Depends(get_db)):
|
||||||
|
"""Hvilke playlister har aktiv live-data?"""
|
||||||
|
result = []
|
||||||
|
for pid, data in _live_cache.items():
|
||||||
|
playing = next((s for s in data["songs"] if s["status"] == "playing"), None)
|
||||||
|
result.append({
|
||||||
|
"id": pid,
|
||||||
|
"name": data["name"],
|
||||||
|
"updated_at": data["updated_at"],
|
||||||
|
"now_playing": playing["title"] if playing else None,
|
||||||
|
})
|
||||||
|
return result
|
||||||
403
linedance-api/web/public/live.html
Normal file
403
linedance-api/web/public/live.html
Normal file
@@ -0,0 +1,403 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="da">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>LineDance — Live</title>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--bg: #0a0b0d;
|
||||||
|
--surface: #13151a;
|
||||||
|
--border: #252830;
|
||||||
|
--accent: #e8a020;
|
||||||
|
--text: #eceef4;
|
||||||
|
--muted: #60687a;
|
||||||
|
--green: #27ae60;
|
||||||
|
--gray: #3a3f4b;
|
||||||
|
}
|
||||||
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||||
|
html, body { height: 100%; }
|
||||||
|
body {
|
||||||
|
background: var(--bg); color: var(--text);
|
||||||
|
font-family: 'Segoe UI', system-ui, sans-serif;
|
||||||
|
min-height: 100vh; display: flex; flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Header ── */
|
||||||
|
header {
|
||||||
|
padding: .75rem 1.5rem;
|
||||||
|
display: flex; align-items: center; justify-content: space-between;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.logo { font-size: .85rem; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
|
||||||
|
.logo b { color: var(--accent); }
|
||||||
|
.live-dot {
|
||||||
|
display: flex; align-items: center; gap: .4rem;
|
||||||
|
font-size: .75rem; color: var(--muted);
|
||||||
|
}
|
||||||
|
.dot {
|
||||||
|
width: 7px; height: 7px; border-radius: 50%;
|
||||||
|
background: var(--muted); transition: background .3s;
|
||||||
|
}
|
||||||
|
.dot.active { background: var(--green); animation: pulse 2s infinite; }
|
||||||
|
@keyframes pulse {
|
||||||
|
0%, 100% { opacity: 1; } 50% { opacity: .4; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Now playing ── */
|
||||||
|
#now-playing {
|
||||||
|
padding: 2rem 1.5rem 1.5rem;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.np-label {
|
||||||
|
font-size: .7rem; letter-spacing: .15em; text-transform: uppercase;
|
||||||
|
color: var(--accent); font-weight: 600; margin-bottom: .6rem;
|
||||||
|
}
|
||||||
|
.np-title {
|
||||||
|
font-size: clamp(1.8rem, 6vw, 3.5rem);
|
||||||
|
font-weight: 700; line-height: 1.1;
|
||||||
|
color: var(--text); margin-bottom: .3rem;
|
||||||
|
}
|
||||||
|
.np-artist {
|
||||||
|
font-size: clamp(1rem, 3vw, 1.6rem);
|
||||||
|
color: var(--muted); margin-bottom: .75rem;
|
||||||
|
}
|
||||||
|
.np-dance {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: clamp(.85rem, 2.5vw, 1.2rem);
|
||||||
|
font-weight: 600; color: #111;
|
||||||
|
background: var(--accent); padding: .3rem .9rem;
|
||||||
|
border-radius: 6px; margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
.np-dance:empty { display: none; }
|
||||||
|
|
||||||
|
/* Progress bar */
|
||||||
|
.progress-bar {
|
||||||
|
height: 4px; background: var(--border); border-radius: 2px; overflow: hidden;
|
||||||
|
margin-bottom: .5rem;
|
||||||
|
}
|
||||||
|
.progress-fill {
|
||||||
|
height: 100%; background: var(--accent);
|
||||||
|
border-radius: 2px; transition: width .3s;
|
||||||
|
width: 0%;
|
||||||
|
}
|
||||||
|
.progress-text {
|
||||||
|
font-size: .75rem; color: var(--muted);
|
||||||
|
display: flex; justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Divider ── */
|
||||||
|
.divider {
|
||||||
|
border: none; border-top: 1px solid var(--border);
|
||||||
|
margin: .5rem 1.5rem;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Next up label ── */
|
||||||
|
.next-label {
|
||||||
|
padding: .6rem 1.5rem .4rem;
|
||||||
|
font-size: .7rem; letter-spacing: .15em; text-transform: uppercase;
|
||||||
|
color: var(--muted); font-weight: 600; flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Song list ── */
|
||||||
|
#song-list {
|
||||||
|
flex: 1; overflow-y: auto;
|
||||||
|
padding: 0 1rem .5rem;
|
||||||
|
}
|
||||||
|
#song-list::-webkit-scrollbar { width: 3px; }
|
||||||
|
#song-list::-webkit-scrollbar-thumb { background: var(--border); }
|
||||||
|
|
||||||
|
.song-item {
|
||||||
|
display: flex; align-items: center; gap: .75rem;
|
||||||
|
padding: .55rem .5rem; border-radius: 8px;
|
||||||
|
transition: background .15s;
|
||||||
|
}
|
||||||
|
.song-item.playing {
|
||||||
|
background: rgba(232,160,32,.08);
|
||||||
|
border: 1px solid rgba(232,160,32,.2);
|
||||||
|
}
|
||||||
|
.song-item.played { opacity: .35; }
|
||||||
|
.song-item.skipped { opacity: .2; }
|
||||||
|
|
||||||
|
.song-num {
|
||||||
|
font-size: .72rem; color: var(--muted);
|
||||||
|
width: 1.6rem; text-align: right; flex-shrink: 0;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
.song-check {
|
||||||
|
width: 1.2rem; flex-shrink: 0; text-align: center;
|
||||||
|
font-size: .8rem;
|
||||||
|
}
|
||||||
|
.song-info { flex: 1; min-width: 0; }
|
||||||
|
.song-title-sm {
|
||||||
|
font-size: clamp(.82rem, 2vw, .95rem); font-weight: 500;
|
||||||
|
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.song-artist-sm {
|
||||||
|
font-size: clamp(.7rem, 1.8vw, .8rem); color: var(--muted);
|
||||||
|
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.song-dance-sm {
|
||||||
|
font-size: .7rem; color: var(--accent); flex-shrink: 0;
|
||||||
|
font-weight: 500; max-width: 100px;
|
||||||
|
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Empty / loading ── */
|
||||||
|
#empty {
|
||||||
|
display: flex; flex-direction: column; align-items: center;
|
||||||
|
justify-content: center; flex: 1; gap: 1rem;
|
||||||
|
color: var(--muted); text-align: center; padding: 2rem;
|
||||||
|
}
|
||||||
|
.spinner {
|
||||||
|
width: 32px; height: 32px; border: 2px solid var(--border);
|
||||||
|
border-top-color: var(--accent); border-radius: 50%;
|
||||||
|
animation: spin .8s linear infinite;
|
||||||
|
}
|
||||||
|
@keyframes spin { to { transform: rotate(360deg); } }
|
||||||
|
|
||||||
|
/* ── Footer ── */
|
||||||
|
footer {
|
||||||
|
padding: .6rem 1.5rem; border-top: 1px solid var(--border);
|
||||||
|
font-size: .7rem; color: var(--muted);
|
||||||
|
display: flex; justify-content: space-between; align-items: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
#last-updated { font-variant-numeric: tabular-nums; }
|
||||||
|
|
||||||
|
/* ── No event ── */
|
||||||
|
#no-event {
|
||||||
|
display: none; flex-direction: column; align-items: center;
|
||||||
|
justify-content: center; flex: 1; gap: .75rem;
|
||||||
|
color: var(--muted); text-align: center; padding: 3rem;
|
||||||
|
}
|
||||||
|
.no-event-icon { font-size: 2.5rem; opacity: .3; }
|
||||||
|
|
||||||
|
/* Playlist vælger */
|
||||||
|
#picker {
|
||||||
|
display: none; flex-direction: column; align-items: center;
|
||||||
|
justify-content: center; flex: 1; gap: 1rem; padding: 2rem;
|
||||||
|
}
|
||||||
|
#picker h2 { font-size: 1.1rem; color: var(--text); }
|
||||||
|
#picker p { font-size: .85rem; color: var(--muted); text-align: center; max-width: 320px; }
|
||||||
|
.playlist-pick-btn {
|
||||||
|
background: var(--surface); border: 1px solid var(--border);
|
||||||
|
border-radius: 10px; padding: .9rem 1.25rem; width: 100%; max-width: 340px;
|
||||||
|
text-align: left; cursor: pointer; transition: all .15s; color: var(--text);
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
.playlist-pick-btn:hover { border-color: var(--accent); background: rgba(232,160,32,.06); }
|
||||||
|
.playlist-pick-btn strong { display: block; font-size: .95rem; margin-bottom: .2rem; }
|
||||||
|
.playlist-pick-btn span { font-size: .78rem; color: var(--muted); }
|
||||||
|
|
||||||
|
@media (min-width: 600px) {
|
||||||
|
#now-playing { padding: 2.5rem 2.5rem 1.5rem; }
|
||||||
|
.next-label { padding-left: 2.5rem; }
|
||||||
|
#song-list { padding: 0 1.5rem .5rem; }
|
||||||
|
header, footer { padding-left: 2.5rem; padding-right: 2.5rem; }
|
||||||
|
.divider { margin-left: 2.5rem; margin-right: 2.5rem; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<div class="logo">LINE<b>DANCE</b></div>
|
||||||
|
<div class="live-dot">
|
||||||
|
<div class="dot" id="live-dot"></div>
|
||||||
|
<span id="live-label">Forbinder...</span>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- Playlist vælger -->
|
||||||
|
<div id="picker">
|
||||||
|
<h2>Vælg playliste</h2>
|
||||||
|
<p>Ingen aktiv playliste fundet. Vælg en nedenfor eller brug URL-parametret <code>?id=PLAYLIST_ID</code></p>
|
||||||
|
<div id="picker-list"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Ingen event -->
|
||||||
|
<div id="no-event">
|
||||||
|
<div class="no-event-icon">🎵</div>
|
||||||
|
<div style="font-size:1rem;color:var(--text)">Ingen aktiv playliste</div>
|
||||||
|
<div>Åbn LineDance Player og start et event</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Loading -->
|
||||||
|
<div id="empty" style="display:none">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<span>Henter data...</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Now playing -->
|
||||||
|
<div id="now-playing" style="display:none">
|
||||||
|
<div class="np-label">▶ Spiller nu</div>
|
||||||
|
<div class="np-title" id="np-title">—</div>
|
||||||
|
<div class="np-artist" id="np-artist"></div>
|
||||||
|
<div class="np-dance" id="np-dance"></div>
|
||||||
|
<div class="progress-bar"><div class="progress-fill" id="np-progress"></div></div>
|
||||||
|
<div class="progress-text">
|
||||||
|
<span id="np-played">0 afspillet</span>
|
||||||
|
<span id="np-remaining">0 tilbage</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr class="divider" id="divider" style="display:none">
|
||||||
|
<div class="next-label" id="next-label" style="display:none">Kommende</div>
|
||||||
|
<div id="song-list"></div>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<span id="pl-name"></span>
|
||||||
|
<span id="last-updated"></span>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const API = '/api';
|
||||||
|
let playlistId = new URLSearchParams(location.search).get('id');
|
||||||
|
let pollTimer = null;
|
||||||
|
let lastData = null;
|
||||||
|
|
||||||
|
function fmt(s) { return (s||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); }
|
||||||
|
function fmtTime(d) {
|
||||||
|
if (!d) return '';
|
||||||
|
const now = new Date(d);
|
||||||
|
return now.toLocaleTimeString('da-DK', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadAndRender() {
|
||||||
|
if (!playlistId) {
|
||||||
|
await showPicker();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const r = await fetch(`${API}/live/${playlistId}`);
|
||||||
|
if (!r.ok) { showNoEvent(); return; }
|
||||||
|
const data = await r.json();
|
||||||
|
lastData = data;
|
||||||
|
render(data);
|
||||||
|
} catch(e) {
|
||||||
|
setDot(false, 'Forbindelsesfejl');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function showPicker() {
|
||||||
|
try {
|
||||||
|
const r = await fetch(`${API}/live/`);
|
||||||
|
const lists = await r.json();
|
||||||
|
if (lists.length === 0) { showNoEvent(); return; }
|
||||||
|
if (lists.length === 1) { playlistId = lists[0].id; await loadAndRender(); return; }
|
||||||
|
|
||||||
|
document.getElementById('picker').style.display = 'flex';
|
||||||
|
document.getElementById('no-event').style.display = 'none';
|
||||||
|
const container = document.getElementById('picker-list');
|
||||||
|
container.innerHTML = lists.map(p => `
|
||||||
|
<button class="playlist-pick-btn" onclick="selectPlaylist('${p.id}')">
|
||||||
|
<strong>${fmt(p.name)}</strong>
|
||||||
|
<span>${p.now_playing ? '▶ ' + fmt(p.now_playing) : 'Ingen aktiv sang'}</span>
|
||||||
|
</button>`).join('');
|
||||||
|
} catch(e) {
|
||||||
|
showNoEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectPlaylist(id) {
|
||||||
|
playlistId = id;
|
||||||
|
history.replaceState(null, '', `?id=${id}`);
|
||||||
|
document.getElementById('picker').style.display = 'none';
|
||||||
|
loadAndRender();
|
||||||
|
}
|
||||||
|
|
||||||
|
function showNoEvent() {
|
||||||
|
document.getElementById('no-event').style.display = 'flex';
|
||||||
|
document.getElementById('picker').style.display = 'none';
|
||||||
|
document.getElementById('now-playing').style.display = 'none';
|
||||||
|
document.getElementById('divider').style.display = 'none';
|
||||||
|
document.getElementById('next-label').style.display = 'none';
|
||||||
|
document.getElementById('song-list').innerHTML = '';
|
||||||
|
setDot(false, 'Ikke aktiv');
|
||||||
|
}
|
||||||
|
|
||||||
|
function render(data) {
|
||||||
|
const songs = data.songs || [];
|
||||||
|
document.getElementById('picker').style.display = 'none';
|
||||||
|
document.getElementById('no-event').style.display = 'none';
|
||||||
|
document.getElementById('empty').style.display = 'none';
|
||||||
|
document.getElementById('pl-name').textContent = data.name || '';
|
||||||
|
document.getElementById('last-updated').textContent =
|
||||||
|
data.updated_at ? 'Opdateret ' + fmtTime(data.updated_at) : '';
|
||||||
|
|
||||||
|
const playing = songs.find(s => s.status === 'playing');
|
||||||
|
const pending = songs.filter(s => s.status === 'pending');
|
||||||
|
const played = songs.filter(s => s.status === 'played' || s.status === 'skipped').length;
|
||||||
|
const total = songs.length;
|
||||||
|
|
||||||
|
// Now playing
|
||||||
|
const npSection = document.getElementById('now-playing');
|
||||||
|
if (playing) {
|
||||||
|
npSection.style.display = '';
|
||||||
|
document.getElementById('np-title').textContent = playing.title;
|
||||||
|
document.getElementById('np-artist').textContent = playing.artist;
|
||||||
|
document.getElementById('np-dance').textContent = playing.dance || '';
|
||||||
|
const pct = total > 0 ? Math.round(played / total * 100) : 0;
|
||||||
|
document.getElementById('np-progress').style.width = pct + '%';
|
||||||
|
document.getElementById('np-played').textContent = `${played} afspillet`;
|
||||||
|
document.getElementById('np-remaining').textContent = `${pending.length} tilbage`;
|
||||||
|
setDot(true, 'Live');
|
||||||
|
} else if (songs.length > 0) {
|
||||||
|
npSection.style.display = '';
|
||||||
|
const next = pending[0];
|
||||||
|
document.getElementById('np-label') && (npSection.querySelector('.np-label').textContent = next ? '⏸ Pause' : '✓ Afsluttet');
|
||||||
|
document.getElementById('np-title').textContent = next ? next.title : (played > 0 ? 'Danselisten er afsluttet' : songs[0]?.title || '—');
|
||||||
|
document.getElementById('np-artist').textContent = next ? next.artist : '';
|
||||||
|
document.getElementById('np-dance').textContent = next ? (next.dance || '') : '';
|
||||||
|
const pct = total > 0 ? Math.round(played / total * 100) : 0;
|
||||||
|
document.getElementById('np-progress').style.width = pct + '%';
|
||||||
|
document.getElementById('np-played').textContent = `${played} afspillet`;
|
||||||
|
document.getElementById('np-remaining').textContent = `${pending.length} tilbage`;
|
||||||
|
setDot(!!data.updated_at, data.updated_at ? 'Live' : 'Afventer');
|
||||||
|
} else {
|
||||||
|
npSection.style.display = 'none';
|
||||||
|
setDot(false, 'Ingen sange');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Song list — vis pending og aktiv, skip played
|
||||||
|
const listSongs = songs.filter(s => s.status !== 'played' && s.status !== 'skipped' || songs.length <= 10);
|
||||||
|
const hasList = listSongs.length > 0;
|
||||||
|
document.getElementById('divider').style.display = hasList ? '' : 'none';
|
||||||
|
document.getElementById('next-label').style.display = hasList ? '' : 'none';
|
||||||
|
|
||||||
|
document.getElementById('song-list').innerHTML = songs.map((s, i) => {
|
||||||
|
const icon = s.status === 'played' ? '✓' :
|
||||||
|
s.status === 'skipped' ? '—' :
|
||||||
|
s.status === 'playing' ? '▶' : '';
|
||||||
|
const cls = s.status === 'played' ? 'song-item played' :
|
||||||
|
s.status === 'skipped' ? 'song-item skipped' :
|
||||||
|
s.status === 'playing' ? 'song-item playing' : 'song-item';
|
||||||
|
return `
|
||||||
|
<div class="${cls}">
|
||||||
|
<span class="song-num">${i+1}</span>
|
||||||
|
<span class="song-check">${icon}</span>
|
||||||
|
<div class="song-info">
|
||||||
|
<div class="song-title-sm">${fmt(s.title)}</div>
|
||||||
|
<div class="song-artist-sm">${fmt(s.artist)}</div>
|
||||||
|
</div>
|
||||||
|
${s.dance ? `<span class="song-dance-sm">${fmt(s.dance)}</span>` : ''}
|
||||||
|
</div>`;
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function setDot(active, label) {
|
||||||
|
const dot = document.getElementById('live-dot');
|
||||||
|
const lbl = document.getElementById('live-label');
|
||||||
|
dot.className = 'dot' + (active ? ' active' : '');
|
||||||
|
lbl.textContent = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start polling
|
||||||
|
loadAndRender();
|
||||||
|
pollTimer = setInterval(loadAndRender, 5000);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -18,9 +18,9 @@ from pathlib import Path
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# AcoustID API nøgle — gratis til open-source apps
|
# AcoustID API nøgle — kan overskrives i Indstillinger → Afspilning
|
||||||
# https://acoustid.org/api-key
|
# Registrér din egen på https://acoustid.org/new-application
|
||||||
ACOUSTID_API_KEY = "9JYq1saI1H"
|
ACOUSTID_API_KEY = "71W9SJdajAI"
|
||||||
ACOUSTID_API_URL = "https://api.acoustid.org/v2/lookup"
|
ACOUSTID_API_URL = "https://api.acoustid.org/v2/lookup"
|
||||||
|
|
||||||
# Pause mellem API-kald — rolig baggrundskørsel
|
# Pause mellem API-kald — rolig baggrundskørsel
|
||||||
|
|||||||
@@ -1241,11 +1241,12 @@ class MainWindow(QMainWindow):
|
|||||||
self._song_ended = False
|
self._song_ended = False
|
||||||
|
|
||||||
def _sync_event_status_to_playlist(self):
|
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:
|
try:
|
||||||
pl_id = self._playlist_panel.get_named_playlist_id()
|
pl_id = self._playlist_panel.get_named_playlist_id()
|
||||||
if not pl_id:
|
if not pl_id:
|
||||||
return
|
return
|
||||||
|
songs = self._playlist_panel.get_songs()
|
||||||
statuses = self._playlist_panel.get_statuses()
|
statuses = self._playlist_panel.get_statuses()
|
||||||
from local.local_db import get_db
|
from local.local_db import get_db
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
@@ -1255,9 +1256,54 @@ class MainWindow(QMainWindow):
|
|||||||
"WHERE playlist_id=? AND position=?",
|
"WHERE playlist_id=? AND position=?",
|
||||||
(status, pl_id, 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
|
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):
|
def _on_state_changed(self, state: str):
|
||||||
if state == "playing":
|
if state == "playing":
|
||||||
self._btn_play.setText("⏸")
|
self._btn_play.setText("⏸")
|
||||||
|
|||||||
Reference in New Issue
Block a user