Sync alternativer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""
|
||||
bpm_worker.py — QThread til BPM-analyse i baggrunden.
|
||||
Ny v0.9 arkitektur: sange er i songs, filer i files, libraries i libraries.
|
||||
"""
|
||||
import sqlite3
|
||||
from PyQt6.QtCore import QThread, pyqtSignal
|
||||
@@ -15,10 +16,10 @@ class BpmScanWorker(QThread):
|
||||
self._library_id = library_id
|
||||
self._db_path = db_path
|
||||
self._scan_all = scan_all
|
||||
self._cancelled = False
|
||||
|
||||
def cancel(self):
|
||||
self.requestInterruption()
|
||||
# Afbryd hurtigt ved at sætte et flag
|
||||
self._cancelled = True
|
||||
|
||||
def run(self):
|
||||
@@ -28,20 +29,34 @@ class BpmScanWorker(QThread):
|
||||
from local.tag_reader import analyze_bpm
|
||||
conn = sqlite3.connect(self._db_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
conn.execute("PRAGMA journal_mode=WAL")
|
||||
|
||||
# Ny arkitektur: JOIN songs + files + libraries
|
||||
lib_row = conn.execute(
|
||||
"SELECT path FROM libraries WHERE id=?", (self._library_id,)
|
||||
).fetchone()
|
||||
if not lib_row:
|
||||
self.finished.emit(0)
|
||||
conn.close()
|
||||
return
|
||||
|
||||
lib_path = lib_row["path"]
|
||||
|
||||
if self._scan_all:
|
||||
songs = conn.execute(
|
||||
"SELECT id, local_path FROM songs "
|
||||
"WHERE library_id=? AND file_missing=0",
|
||||
(self._library_id,)
|
||||
).fetchall()
|
||||
songs = conn.execute("""
|
||||
SELECT s.id, f.local_path
|
||||
FROM songs s
|
||||
JOIN files f ON f.song_id = s.id AND f.file_missing = 0
|
||||
WHERE f.local_path LIKE ?
|
||||
""", (lib_path + "%",)).fetchall()
|
||||
else:
|
||||
songs = conn.execute(
|
||||
"SELECT id, local_path FROM songs "
|
||||
"WHERE library_id=? AND file_missing=0 "
|
||||
"AND (bpm IS NULL OR bpm=0)",
|
||||
(self._library_id,)
|
||||
).fetchall()
|
||||
songs = conn.execute("""
|
||||
SELECT s.id, f.local_path
|
||||
FROM songs s
|
||||
JOIN files f ON f.song_id = s.id AND f.file_missing = 0
|
||||
WHERE f.local_path LIKE ?
|
||||
AND (s.bpm IS NULL OR s.bpm = 0)
|
||||
""", (lib_path + "%",)).fetchall()
|
||||
|
||||
total = len(songs)
|
||||
done = 0
|
||||
@@ -61,9 +76,9 @@ class BpmScanWorker(QThread):
|
||||
pass
|
||||
done += 1
|
||||
self.progress.emit(done, total)
|
||||
time.sleep(0.01) # Yield så GUI ikke hænger
|
||||
time.sleep(0.01)
|
||||
|
||||
conn.close()
|
||||
self.finished.emit(done)
|
||||
except Exception as e:
|
||||
self.finished.emit(0)
|
||||
except Exception:
|
||||
self.finished.emit(0)
|
||||
Reference in New Issue
Block a user