MBID
This commit is contained in:
@@ -89,10 +89,25 @@ def scan_library(library_id: int, library_path: str, db_path: str,
|
||||
tags = read_tags(fp)
|
||||
extra = json.dumps(tags.get("extra_tags", {}), ensure_ascii=False)
|
||||
|
||||
# Match 0: MBID-match — sikrest mulige match
|
||||
existing = None
|
||||
mbid_from_file = tags.get("mbid", "")
|
||||
if mbid_from_file:
|
||||
existing = conn.execute(
|
||||
"SELECT id, bpm FROM songs WHERE mbid=? LIMIT 1",
|
||||
(mbid_from_file,)
|
||||
).fetchone()
|
||||
if existing:
|
||||
conn.execute(
|
||||
"UPDATE songs SET local_path=? WHERE id=?",
|
||||
(path_str, existing["id"])
|
||||
)
|
||||
|
||||
# Match 1: præcis sti-match
|
||||
existing = conn.execute(
|
||||
"SELECT id, bpm FROM songs WHERE local_path=?", (path_str,)
|
||||
).fetchone()
|
||||
if not existing:
|
||||
existing = conn.execute(
|
||||
"SELECT id, bpm FROM songs WHERE local_path=?", (path_str,)
|
||||
).fetchone()
|
||||
|
||||
# Match 2: titel+artist match — fil er flyttet eller var missing
|
||||
if not existing:
|
||||
@@ -131,28 +146,31 @@ def scan_library(library_id: int, library_path: str, db_path: str,
|
||||
bpm = tags.get("bpm", 0)
|
||||
if not overwrite_bpm and existing["bpm"] and existing["bpm"] > 0:
|
||||
bpm = existing["bpm"] # behold eksisterende BPM
|
||||
mbid = tags.get("mbid", "")
|
||||
conn.execute("""
|
||||
UPDATE songs SET
|
||||
library_id=?, title=?, artist=?, album=?,
|
||||
bpm=?, duration_sec=?, file_format=?,
|
||||
file_modified_at=?, file_missing=0, extra_tags=?
|
||||
file_modified_at=?, file_missing=0, extra_tags=?,
|
||||
mbid=CASE WHEN ? != '' THEN ? ELSE mbid END
|
||||
WHERE id=?
|
||||
""", (library_id, tags.get("title",""), tags.get("artist",""),
|
||||
tags.get("album",""), bpm, tags.get("duration_sec",0),
|
||||
tags.get("file_format",""), mtime, extra, existing["id"]))
|
||||
tags.get("file_format",""), mtime, extra,
|
||||
mbid, mbid, existing["id"]))
|
||||
song_id = existing["id"]
|
||||
else:
|
||||
song_id = str(uuid.uuid4())
|
||||
conn.execute("""
|
||||
INSERT OR IGNORE INTO songs
|
||||
(id, library_id, local_path, title, artist, album,
|
||||
bpm, duration_sec, file_format, file_modified_at, extra_tags)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?)
|
||||
bpm, duration_sec, file_format, file_modified_at, extra_tags, mbid)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
""", (song_id, library_id, path_str,
|
||||
tags.get("title",""), tags.get("artist",""),
|
||||
tags.get("album",""), tags.get("bpm",0),
|
||||
tags.get("duration_sec",0), tags.get("file_format",""),
|
||||
mtime, extra))
|
||||
mtime, extra, tags.get("mbid","")))
|
||||
|
||||
# Importer dans-tags fra filen hvis de ikke allerede er i DB
|
||||
file_dances = tags.get("dances", [])
|
||||
|
||||
Reference in New Issue
Block a user