provide tagparsers with uploader info

This commit is contained in:
ed 2022-08-15 20:23:17 +02:00
parent 389a00ce59
commit d48a7d2398
3 changed files with 64 additions and 10 deletions

38
bin/mtag/mousepad.py Normal file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env python3
import os
import sys
import subprocess as sp
"""
mtp test -- opens a texteditor
usage:
-vsrv/v1:v1:r:c,mte=+x1:c,mtp=x1=ad,p,bin/mtag/mousepad.py
explained:
c,mte: list of tags to index in this volume
c,mtp: add new tag provider
x1: dummy tag to provide
ad: dontcare if audio or not
p: priority 1 (run after initial tag-scan with ffprobe or mutagen)
"""
def main():
env = os.environ.copy()
env["DISPLAY"] = ":0.0"
if False:
# open the uploaded file
fp = sys.argv[-1]
else:
# display stdin contents (`oth_tags`)
fp = "/dev/stdin"
p = sp.Popen(["/usr/bin/mousepad", fp])
p.communicate()
main()

View file

@ -313,7 +313,6 @@ class MTag(object):
"tope", "tope",
], ],
"title": ["title", "tit2", "\u00a9nam"], "title": ["title", "tit2", "\u00a9nam"],
"comment": ["comment"],
"circle": [ "circle": [
"album-artist", "album-artist",
"tpe2", "tpe2",

View file

@ -125,7 +125,7 @@ class Up2k(object):
self.mtp_parsers: dict[str, dict[str, MParser]] = {} self.mtp_parsers: dict[str, dict[str, MParser]] = {}
self.pending_tags: list[tuple[set[str], str, str, dict[str, Any]]] = [] self.pending_tags: list[tuple[set[str], str, str, dict[str, Any]]] = []
self.hashq: Queue[tuple[str, str, str, str, float]] = Queue() self.hashq: Queue[tuple[str, str, str, str, float]] = Queue()
self.tagq: Queue[tuple[str, str, str, str]] = Queue() self.tagq: Queue[tuple[str, str, str, str, str, float]] = Queue()
self.tag_event = threading.Condition() self.tag_event = threading.Condition()
self.n_hashq = 0 self.n_hashq = 0
self.n_tagq = 0 self.n_tagq = 0
@ -1288,8 +1288,8 @@ class Up2k(object):
with self.mutex: with self.mutex:
try: try:
q = "select rd, fn from up where substr(w,1,16)=? and +w=?" q = "select rd, fn, ip, at from up where substr(w,1,16)=? and +w=?"
rd, fn = cur.execute(q, (w[:16], w)).fetchone() rd, fn, ip, at = cur.execute(q, (w[:16], w)).fetchone()
except: except:
# file modified/deleted since spooling # file modified/deleted since spooling
continue continue
@ -1304,9 +1304,14 @@ class Up2k(object):
abspath = os.path.join(ptop, rd, fn) abspath = os.path.join(ptop, rd, fn)
self.pp.msg = "c{} {}".format(nq, abspath) self.pp.msg = "c{} {}".format(nq, abspath)
if not mpool: if not mpool:
n_tags = self._tagscan_file(cur, entags, w, abspath) n_tags = self._tagscan_file(cur, entags, w, abspath, ip, at)
else: else:
mpool.put(Mpqe({}, entags, w, abspath, {})) if ip:
oth_tags = {"up_ip": ip, "up_at": at}
else:
oth_tags = {}
mpool.put(Mpqe({}, entags, w, abspath, oth_tags))
with self.mutex: with self.mutex:
n_tags = len(self._flush_mpool(cur)) n_tags = len(self._flush_mpool(cur))
@ -1449,8 +1454,8 @@ class Up2k(object):
if w in in_progress: if w in in_progress:
continue continue
q = "select rd, fn from up where substr(w,1,16)=? limit 1" q = "select rd, fn, ip, at from up where substr(w,1,16)=? limit 1"
rd, fn = cur.execute(q, (w,)).fetchone() rd, fn, ip, at = cur.execute(q, (w,)).fetchone()
rd, fn = s3dec(rd, fn) rd, fn = s3dec(rd, fn)
abspath = os.path.join(ptop, rd, fn) abspath = os.path.join(ptop, rd, fn)
@ -1472,6 +1477,10 @@ class Up2k(object):
else: else:
oth_tags = {} oth_tags = {}
if ip:
oth_tags["up_ip"] = ip
oth_tags["up_at"] = at
jobs.append(Mpqe(parsers, set(), w, abspath, oth_tags)) jobs.append(Mpqe(parsers, set(), w, abspath, oth_tags))
in_progress[w] = True in_progress[w] = True
@ -1641,6 +1650,8 @@ class Up2k(object):
entags: set[str], entags: set[str],
wark: str, wark: str,
abspath: str, abspath: str,
ip: str,
at: float
) -> int: ) -> int:
"""will mutex""" """will mutex"""
assert self.mtag assert self.mtag
@ -1654,6 +1665,10 @@ class Up2k(object):
self._log_tag_err("", abspath, ex) self._log_tag_err("", abspath, ex)
return 0 return 0
if ip:
tags["up_ip"] = ip
tags["up_at"] = at
with self.mutex: with self.mutex:
return self._tag_file(write_cur, entags, wark, abspath, tags) return self._tag_file(write_cur, entags, wark, abspath, tags)
@ -2295,7 +2310,7 @@ class Up2k(object):
raise raise
if "e2t" in self.flags[ptop]: if "e2t" in self.flags[ptop]:
self.tagq.put((ptop, wark, rd, fn)) self.tagq.put((ptop, wark, rd, fn, ip, at))
self.n_tagq += 1 self.n_tagq += 1
return True return True
@ -2941,7 +2956,7 @@ class Up2k(object):
with self.mutex: with self.mutex:
self.n_tagq -= 1 self.n_tagq -= 1
ptop, wark, rd, fn = self.tagq.get() ptop, wark, rd, fn, ip, at = self.tagq.get()
if "e2t" not in self.flags[ptop]: if "e2t" not in self.flags[ptop]:
continue continue
@ -2952,6 +2967,8 @@ class Up2k(object):
ntags1 = len(tags) ntags1 = len(tags)
parsers = self._get_parsers(ptop, tags, abspath) parsers = self._get_parsers(ptop, tags, abspath)
if parsers: if parsers:
tags["up_ip"] = ip
tags["up_at"] = at
tags.update(self.mtag.get_bin(parsers, abspath, tags)) tags.update(self.mtag.get_bin(parsers, abspath, tags))
except Exception as ex: except Exception as ex:
self._log_tag_err("", abspath, ex) self._log_tag_err("", abspath, ex)