feat: bootstrap NAS music deduper

This commit is contained in:
OpenClaw Agent
2026-09-18 04:48:47 +08:00
commit 6154cd0752
17 changed files with 481 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
from __future__ import annotations
import sqlite3
from pathlib import Path
SCHEMA = """
CREATE TABLE IF NOT EXISTS audio_tracks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
file_path TEXT UNIQUE NOT NULL,
file_size INTEGER NOT NULL,
fast_hash TEXT NOT NULL,
sha256 TEXT,
duration REAL,
artist TEXT,
title TEXT,
album TEXT,
format TEXT,
bitrate INTEGER,
sample_rate INTEGER,
bit_depth INTEGER,
chromaprint TEXT,
score INTEGER,
status TEXT NOT NULL DEFAULT 'active',
inode INTEGER,
device INTEGER,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
trashed_at TEXT,
review_status TEXT
);
CREATE INDEX IF NOT EXISTS idx_fast_hash ON audio_tracks(fast_hash);
CREATE INDEX IF NOT EXISTS idx_sha256 ON audio_tracks(sha256);
CREATE INDEX IF NOT EXISTS idx_duration ON audio_tracks(duration);
CREATE INDEX IF NOT EXISTS idx_status ON audio_tracks(status);
"""
def connect(path: Path) -> sqlite3.Connection:
path.parent.mkdir(parents=True, exist_ok=True)
conn = sqlite3.connect(path)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA journal_mode=WAL")
conn.execute("PRAGMA foreign_keys=ON")
conn.executescript(SCHEMA)
return conn