Diverse rettelser
This commit is contained in:
@@ -744,4 +744,28 @@ def get_community_alts_for_song(song_id: str) -> list:
|
||||
WHERE cad.song_id = ?
|
||||
ORDER BY cad.avg_rating DESC
|
||||
""", (song_id,)).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
def refresh_file_availability():
|
||||
"""Tjek hurtigt om alle kendte filer stadig eksisterer — opdater file_missing.
|
||||
Køres ved opstart i baggrundstråd."""
|
||||
from pathlib import Path
|
||||
try:
|
||||
with get_db() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT id, local_path, file_missing FROM files"
|
||||
).fetchall()
|
||||
for row in rows:
|
||||
try:
|
||||
exists = Path(row["local_path"]).exists()
|
||||
expected = 0 if exists else 1
|
||||
if row["file_missing"] != expected:
|
||||
conn.execute(
|
||||
"UPDATE files SET file_missing=? WHERE id=?",
|
||||
(expected, row["id"])
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
logger.info("Fil-tilgængelighed opdateret")
|
||||
except Exception as e:
|
||||
logger.warning(f"refresh_file_availability fejl: {e}")
|
||||
@@ -410,19 +410,21 @@ def read_dances_from_file(path: str | Path) -> list[str]:
|
||||
return tags.get("dances", [])
|
||||
|
||||
|
||||
def write_dance_to_file(path: str | Path, dances: list[str]) -> bool:
|
||||
"""Alias for write_dances — skriv danse-liste til fil."""
|
||||
return write_dances(path, dances)
|
||||
|
||||
|
||||
# ── BPM-analyse ───────────────────────────────────────────────────────────────
|
||||
|
||||
# Formater der ikke understøttes af librosa uden ffmpeg
|
||||
_BPM_UNSUPPORTED = {".wma", ".ac3", ".dts", ".ra", ".rm", ".rmvb"}
|
||||
|
||||
def analyze_bpm(path: str | Path) -> float | None:
|
||||
"""
|
||||
Analysér BPM fra lydfilen ved hjælp af librosa.
|
||||
Returnerer BPM som float eller None ved fejl.
|
||||
Tager 2-5 sekunder per sang — kør i baggrundstråd.
|
||||
"""
|
||||
suffix = Path(path).suffix.lower()
|
||||
if suffix in _BPM_UNSUPPORTED:
|
||||
logger.debug(f"BPM-analyse ikke understøttet for {suffix}: {path}")
|
||||
return None
|
||||
try:
|
||||
import librosa
|
||||
# Indlæs kun de første 60 sekunder for hastighed
|
||||
|
||||
Reference in New Issue
Block a user