Diverse rettelser
This commit is contained in:
@@ -2,6 +2,45 @@
|
||||
playlist_panel.py — Danseliste med Ny/Gem/Hent knapper, autogem og event-overblik.
|
||||
"""
|
||||
|
||||
import sys as _sys
|
||||
from pathlib import Path as _Path
|
||||
|
||||
|
||||
def _is_local_path(path: str) -> bool:
|
||||
"""Returnerer True hvis stien er på et lokalt/USB-drev, False hvis netværk."""
|
||||
try:
|
||||
if _sys.platform == "win32":
|
||||
import ctypes
|
||||
drive = path[:3]
|
||||
# GetDriveType: 2=Removable, 3=Fixed, 4=Remote(netværk), 5=CDROM, 6=RAMdisk
|
||||
dtype = ctypes.windll.kernel32.GetDriveTypeW(drive)
|
||||
return dtype not in (4,) # 4 = netværksdrev
|
||||
else:
|
||||
# Linux/Mac — tjek /proc/mounts
|
||||
NETWORK_FS = {
|
||||
"nfs", "nfs4", "cifs", "smb", "smb2", "smb3",
|
||||
"fuse.sshfs", "fuse.gvfsd-fuse", "fuse.s3fs",
|
||||
"davfs", "ncpfs", "afs", "glusterfs", "fuse.glusterfs",
|
||||
}
|
||||
try:
|
||||
with open("/proc/mounts") as f:
|
||||
mounts = []
|
||||
for line in f:
|
||||
parts = line.split()
|
||||
if len(parts) >= 3:
|
||||
mounts.append((parts[1], parts[2]))
|
||||
# Find længste matchende mount-punkt
|
||||
mounts.sort(key=lambda x: len(x[0]), reverse=True)
|
||||
for mount_point, fs_type in mounts:
|
||||
if path.startswith(mount_point):
|
||||
return fs_type not in NETWORK_FS
|
||||
except Exception:
|
||||
pass
|
||||
return True # Antag lokal
|
||||
except Exception:
|
||||
return True # Antag lokal ved fejl
|
||||
|
||||
|
||||
from PyQt6.QtWidgets import (
|
||||
QWidget, QVBoxLayout, QListWidget, QListWidgetItem,
|
||||
QLabel, QHBoxLayout, QPushButton, QMenu, QAbstractItemView,
|
||||
@@ -799,30 +838,20 @@ class PlaylistPanel(QWidget):
|
||||
self._save_alt_dance_rating(song, chosen, rating)
|
||||
|
||||
def _sync_alt_dance_to_db(self, idx: int, song: dict, alt_dance: str):
|
||||
"""Gem alt_dance_override til playlist_songs — både aktiv og navngiven liste."""
|
||||
pl_ids = []
|
||||
if self._active_playlist_id:
|
||||
pl_ids.append(self._active_playlist_id)
|
||||
if self._named_playlist_id and self._named_playlist_id not in pl_ids:
|
||||
pl_ids.append(self._named_playlist_id)
|
||||
if not pl_ids:
|
||||
"""Gem alt_dance_override til playlist_songs."""
|
||||
if not self._named_playlist_id:
|
||||
return
|
||||
try:
|
||||
import logging
|
||||
from local.local_db import get_db
|
||||
with get_db() as conn:
|
||||
for pl_id in pl_ids:
|
||||
conn.execute(
|
||||
"UPDATE playlist_songs SET alt_dance_override=? "
|
||||
"WHERE playlist_id=? AND position=?",
|
||||
(alt_dance, pl_id, idx + 1)
|
||||
)
|
||||
logging.getLogger(__name__).info(
|
||||
f"alt_dance_override='{alt_dance}' gemt på pos {idx+1} i {pl_id}"
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE playlist_songs SET alt_dance_override=? "
|
||||
"WHERE playlist_id=? AND position=?",
|
||||
(alt_dance, self._named_playlist_id, idx + 1)
|
||||
)
|
||||
except Exception as e:
|
||||
import logging
|
||||
logging.getLogger(__name__).warning(f"alt_dance_to_db fejl: {e}", exc_info=True)
|
||||
logging.getLogger(__name__).warning(f"alt_dance_to_db fejl: {e}")
|
||||
|
||||
def _save_alt_dance_rating(self, song: dict, dance_name: str, rating: int):
|
||||
"""Gem brugerens rating på en alternativ-dans."""
|
||||
@@ -1148,7 +1177,8 @@ class PlaylistPanel(QWidget):
|
||||
for song in songs:
|
||||
path = song.get("local_path", "")
|
||||
if path and Path(path).exists():
|
||||
song["availability"] = "green"
|
||||
# Grøn = lokal, Gul = netværk men tilgængeligt
|
||||
song["availability"] = "green" if _is_local_path(path) else "yellow"
|
||||
continue
|
||||
|
||||
# Forsøg auto-match via titel+artist
|
||||
@@ -1185,9 +1215,9 @@ class PlaylistPanel(QWidget):
|
||||
with get_db() as conn:
|
||||
for song in self._songs:
|
||||
path = song.get("local_path", "")
|
||||
# Grøn — filen eksisterer lokalt
|
||||
# Grøn = lokal, Gul = netværk men tilgængeligt
|
||||
if path and Path(path).exists():
|
||||
song["availability"] = "green"
|
||||
song["availability"] = "green" if _is_local_path(path) else "yellow"
|
||||
song["file_missing"] = False
|
||||
# Opdater files tabellen
|
||||
conn.execute(
|
||||
@@ -1211,7 +1241,7 @@ class PlaylistPanel(QWidget):
|
||||
if match and Path(match["local_path"]).exists():
|
||||
song["local_path"] = match["local_path"]
|
||||
song["file_id"] = match["file_id"]
|
||||
song["availability"] = "green"
|
||||
song["availability"] = "green" if _is_local_path(match["local_path"]) else "yellow"
|
||||
song["file_missing"] = False
|
||||
# Opdater playlist_songs til at pege på den fundne fil
|
||||
if self._named_playlist_id:
|
||||
@@ -1439,7 +1469,6 @@ class PlaylistPanel(QWidget):
|
||||
if not active:
|
||||
dances = song.get("dances", [])
|
||||
active = dances[0] if dances else "— ingen dans —"
|
||||
alt = song.get("alt_dance", "")
|
||||
ws_tag = " 🎓" if song.get("is_workshop") else ""
|
||||
|
||||
# Tilgængeligheds-dot til højre — kun hvis tjekket (ikke yellow)
|
||||
@@ -1447,11 +1476,7 @@ class PlaylistPanel(QWidget):
|
||||
avail_color = {"green": "#27ae60", "red": "#e74c3c"}.get(avail, None)
|
||||
avail_tip = {"green": "Tilgængelig lokalt", "red": "Ikke fundet lokalt"}.get(avail, "")
|
||||
|
||||
dance_line = f"{active}{ws_tag}"
|
||||
if alt:
|
||||
dance_line += f" / {alt}"
|
||||
|
||||
text = (f"{i+1:>2}. {dance_line}\n"
|
||||
text = (f"{i+1:>2}. {active}{ws_tag}\n"
|
||||
f" {song.get('title','—')} · {song.get('artist','')}")
|
||||
item = QListWidgetItem(f"{icon} {text}")
|
||||
item.setData(Qt.ItemDataRole.UserRole, i)
|
||||
|
||||
Reference in New Issue
Block a user