feat: automate exact dedupe and improve web feedback

This commit is contained in:
OpenClaw Agent
2026-09-18 07:30:38 +08:00
parent 0fbadf0c9c
commit f10e92a5cd
8 changed files with 283 additions and 163 deletions
+14 -1
View File
@@ -22,14 +22,27 @@ def index_file(conn, path: Path) -> None:
fh = fast_hash(path)
meta = read_metadata(path)
flags = ",".join(meta.get("version_flags", []))
old = conn.execute("SELECT file_size,fast_hash,inode,device FROM audio_tracks WHERE file_path=?", (str(path),)).fetchone()
identity_changed = old is not None and (old["file_size"], old["fast_hash"], old["inode"], old["device"]) != (st.st_size, fh, st.st_ino, st.st_dev)
conn.execute("""
INSERT INTO audio_tracks(file_path,file_size,fast_hash,duration,artist,title,album,format,bitrate,sample_rate,bit_depth,version_flags,inode,device,status)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,'active')
ON CONFLICT(file_path) DO UPDATE SET file_size=excluded.file_size, fast_hash=excluded.fast_hash,
duration=excluded.duration,artist=excluded.artist,title=excluded.title,album=excluded.album,format=excluded.format,
bitrate=excluded.bitrate,sample_rate=excluded.sample_rate,bit_depth=excluded.bit_depth,version_flags=excluded.version_flags,
inode=excluded.inode,device=excluded.device,updated_at=CURRENT_TIMESTAMP,status='active'
inode=excluded.inode,device=excluded.device,updated_at=CURRENT_TIMESTAMP,status='active',
sha256=CASE WHEN excluded.file_size!=audio_tracks.file_size OR excluded.fast_hash!=audio_tracks.fast_hash
OR excluded.inode!=audio_tracks.inode OR excluded.device!=audio_tracks.device
THEN NULL ELSE audio_tracks.sha256 END,
chromaprint=CASE WHEN excluded.file_size!=audio_tracks.file_size OR excluded.fast_hash!=audio_tracks.fast_hash
OR excluded.inode!=audio_tracks.inode OR excluded.device!=audio_tracks.device
THEN NULL ELSE audio_tracks.chromaprint END,
review_status=CASE WHEN excluded.file_size!=audio_tracks.file_size OR excluded.fast_hash!=audio_tracks.fast_hash
OR excluded.inode!=audio_tracks.inode OR excluded.device!=audio_tracks.device
THEN NULL ELSE audio_tracks.review_status END
""", (str(path),st.st_size,fh,meta.get("duration"),meta.get("artist"),meta.get("title"),meta.get("album"),meta.get("format"),meta.get("bitrate"),meta.get("sample_rate"),meta.get("bit_depth"),flags,st.st_ino,st.st_dev))
if identity_changed:
conn.execute("UPDATE audio_tracks SET updated_at=CURRENT_TIMESTAMP WHERE file_path=?", (str(path),))
def scan(root: Path, db_path: Path) -> int: