add mtp debug mode

This commit is contained in:
ed 2022-09-03 19:58:10 +02:00
parent a7f921abb9
commit c930d8f773
2 changed files with 32 additions and 2 deletions

View file

@ -627,6 +627,7 @@ def run_argparse(argv: list[str], formatter: Any, retry: bool) -> argparse.Names
ap2.add_argument("--no-mtag-ff", action="store_true", help="never use FFprobe as tag reader; is probably safer") ap2.add_argument("--no-mtag-ff", action="store_true", help="never use FFprobe as tag reader; is probably safer")
ap2.add_argument("--mtag-mt", metavar="CORES", type=int, default=CORES, help="num cpu cores to use for tag scanning") ap2.add_argument("--mtag-mt", metavar="CORES", type=int, default=CORES, help="num cpu cores to use for tag scanning")
ap2.add_argument("--mtag-v", action="store_true", help="verbose tag scanning; print errors from mtp subprocesses and such") ap2.add_argument("--mtag-v", action="store_true", help="verbose tag scanning; print errors from mtp subprocesses and such")
ap2.add_argument("--mtag-vv", action="store_true", help="debug mtp settings")
ap2.add_argument("-mtm", metavar="M=t,t,t", type=u, action="append", help="add/replace metadata mapping") ap2.add_argument("-mtm", metavar="M=t,t,t", type=u, action="append", help="add/replace metadata mapping")
ap2.add_argument("-mte", metavar="M,M,M", type=u, help="tags to index/display (comma-sep.)", ap2.add_argument("-mte", metavar="M,M,M", type=u, help="tags to index/display (comma-sep.)",
default="circle,album,.tn,artist,title,.bpm,key,.dur,.q,.vq,.aq,vc,ac,fmt,res,.fps,ahash,vhash") default="circle,album,.tn,artist,title,.bpm,key,.dur,.q,.vq,.aq,vc,ac,fmt,res,.fps,ahash,vhash")

View file

@ -1424,6 +1424,10 @@ class Up2k(object):
if tag in parser.tags: if tag in parser.tags:
parsers[parser.tag] = parser parsers[parser.tag] = parser
if self.args.mtag_vv:
t = "parsers for {}: \033[0m{}"
self.log(t.format(ptop, list(parsers.keys())), "1;30")
self.mtp_parsers[ptop] = parsers self.mtp_parsers[ptop] = parsers
q = "select count(w) from mt where k = 't:mtp'" q = "select count(w) from mt where k = 't:mtp'"
@ -1552,6 +1556,8 @@ class Up2k(object):
try: try:
all_parsers = self.mtp_parsers[ptop] all_parsers = self.mtp_parsers[ptop]
except: except:
if self.args.mtag_vv:
self.log("no mtp defined for {}".format(ptop), "1;30")
return {} return {}
entags = self.entags[ptop] entags = self.entags[ptop]
@ -1561,9 +1567,15 @@ class Up2k(object):
if "ac" in have or ".aq" in have: if "ac" in have or ".aq" in have:
# is audio, require non-audio? # is audio, require non-audio?
if v.audio == "n": if v.audio == "n":
if self.args.mtag_vv:
t = "skip mtp {}; is no-audio, have audio"
self.log(t.format(k), "1;30")
continue continue
# is not audio, require audio? # is not audio, require audio?
elif v.audio == "y": elif v.audio == "y":
if self.args.mtag_vv:
t = "skip mtp {}; is audio, have no-audio"
self.log(t.format(k), "1;30")
continue continue
if v.ext: if v.ext:
@ -1574,6 +1586,9 @@ class Up2k(object):
break break
if not match: if not match:
if self.args.mtag_vv:
t = "skip mtp {}; need file-ext {}, have {}"
self.log(t.format(k, v.ext, abspath.rsplit(".")[-1]), "1;30")
continue continue
parsers[k] = v parsers[k] = v
@ -1619,8 +1634,16 @@ class Up2k(object):
try: try:
if not qe.mtp: if not qe.mtp:
if self.args.mtag_vv:
t = "tag-thr: {}({})"
self.log(t.format(self.mtag.backend, qe.abspath), "1;30")
tags = self.mtag.get(qe.abspath) tags = self.mtag.get(qe.abspath)
else: else:
if self.args.mtag_vv:
t = "tag-thr: {}({})"
self.log(t.format(list(qe.mtp.keys()), qe.abspath), "1;30")
tags = self.mtag.get_bin(qe.mtp, qe.abspath, qe.oth_tags) tags = self.mtag.get_bin(qe.mtp, qe.abspath, qe.oth_tags)
vtags = [ vtags = [
"\033[36m{} \033[33m{}".format(k, v) for k, v in tags.items() "\033[36m{} \033[33m{}".format(k, v) for k, v in tags.items()
@ -1651,7 +1674,7 @@ class Up2k(object):
wark: str, wark: str,
abspath: str, abspath: str,
ip: str, ip: str,
at: float at: float,
) -> int: ) -> int:
"""will mutex""" """will mutex"""
assert self.mtag assert self.mtag
@ -1668,7 +1691,7 @@ class Up2k(object):
if ip: if ip:
tags["up_ip"] = ip tags["up_ip"] = ip
tags["up_at"] = at 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)
@ -2966,6 +2989,12 @@ class Up2k(object):
tags = self.mtag.get(abspath) tags = self.mtag.get(abspath)
ntags1 = len(tags) ntags1 = len(tags)
parsers = self._get_parsers(ptop, tags, abspath) parsers = self._get_parsers(ptop, tags, abspath)
if self.args.mtag_vv:
t = "parsers({}): {}\n{} {} tags: {}".format(
ptop, list(parsers.keys()), ntags1, self.mtag.backend, tags
)
self.log(t)
if parsers: if parsers:
tags["up_ip"] = ip tags["up_ip"] = ip
tags["up_at"] = at tags["up_at"] = at