From a83d3f88012e2e40f95bfe8ca35071c7d0ef70f9 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 20 Mar 2021 01:00:57 +0100 Subject: [PATCH] prevent dupe tags from mtp (replace id3 tags) --- copyparty/up2k.py | 10 ++++++++++ docs/notes.sh | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 652054b7..e96f3869 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -700,6 +700,16 @@ class Up2k(object): # indicate scanned without tags tags = {"x": 0} + if not tags: + return 0 + + for k in tags.keys(): + q = "delete from mt where w = ? and ({})".format( + " or ".join(["k = ?"] * len(tags)) + ) + args = [wark[:16]] + list(tags.keys()) + write_cur.execute(q, tuple(args)) + ret = 0 for k, v in tags.items(): q = "insert into mt values (?,?,?)" diff --git a/docs/notes.sh b/docs/notes.sh index 6f6e6ce2..d4898113 100644 --- a/docs/notes.sh +++ b/docs/notes.sh @@ -67,6 +67,17 @@ wget -S --header='Accept-Encoding: gzip' -U 'MSIE 6.0; SV1' http://127.0.0.1:392 shab64() { sp=$1; f="$2"; v=0; sz=$(stat -c%s "$f"); while true; do w=$((v+sp*1024*1024)); printf $(tail -c +$((v+1)) "$f" | head -c $((w-v)) | sha512sum | cut -c-64 | sed -r 's/ .*//;s/(..)/\\x\1/g') | base64 -w0 | cut -c-43 | tr '+/' '-_'; v=$w; [ $v -lt $sz ] || break; done; } +## +## sqlite3 stuff + +# find dupe metadata keys +sqlite3 up2k.db 'select mt1.w, mt1.k, mt1.v, mt2.v from mt mt1 inner join mt mt2 on mt1.w = mt2.w where mt1.k = mt2.k and mt1.rowid != mt2.rowid' + +# partial reindex by deleting all tags for a list of files +sqlite3 up2k.db 'select mt1.w from mt mt1 inner join mt mt2 on mt1.w = mt2.w where mt1.k = mt2.k and mt1.rowid != mt2.rowid' > warks +cat warks | while IFS= read -r x; do sqlite3 up2k.db "delete from mt where w = '$x'"; done + + ## ## vscode