mtp incoming files too

This commit is contained in:
ed 2021-03-21 15:21:07 +01:00
parent 3d375d5114
commit 8dbbea473f

View file

@ -499,6 +499,8 @@ class Up2k(object):
return ret return ret
def _run_all_mtp(self): def _run_all_mtp(self):
self.mtp_force = {}
self.mtp_parsers = {}
for ptop, flags in self.flags.items(): for ptop, flags in self.flags.items():
if "mtp" in flags: if "mtp" in flags:
self._run_one_mtp(ptop) self._run_one_mtp(ptop)
@ -507,12 +509,17 @@ class Up2k(object):
db_path = os.path.join(ptop, ".hist", "up2k.db") db_path = os.path.join(ptop, ".hist", "up2k.db")
sz0 = os.path.getsize(db_path) // 1024 sz0 = os.path.getsize(db_path) // 1024
entags = self.entags[ptop]
force = {} force = {}
timeout = {} timeout = {}
parsers = {} parsers = {}
for parser in self.flags[ptop]["mtp"]: for parser in self.flags[ptop]["mtp"]:
orig = parser orig = parser
tag, parser = parser.split("=", 1) tag, parser = parser.split("=", 1)
if tag not in entags:
continue
while True: while True:
try: try:
bp = os.path.expanduser(parser) bp = os.path.expanduser(parser)
@ -540,6 +547,9 @@ class Up2k(object):
self.log("invalid argument: " + orig, 1) self.log("invalid argument: " + orig, 1)
return return
self.mtp_force[ptop] = force
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'"
with self.mutex: with self.mutex:
cur = self.cur[ptop] cur = self.cur[ptop]
@ -570,7 +580,7 @@ class Up2k(object):
have = cur.execute(q, (w,)).fetchall() have = cur.execute(q, (w,)).fetchall()
have = [x[0] for x in have] have = [x[0] for x in have]
if ".dur" not in have: if ".dur" not in have and ".dur" in entags:
# skip non-audio # skip non-audio
to_delete[w] = True to_delete[w] = True
n_left -= 1 n_left -= 1
@ -1268,8 +1278,20 @@ class Up2k(object):
def _tagger(self): def _tagger(self):
while True: while True:
ptop, wark, rd, fn = self.tagq.get() ptop, wark, rd, fn = self.tagq.get()
if "e2t" not in self.flags[ptop]:
continue
abspath = os.path.join(ptop, rd, fn) abspath = os.path.join(ptop, rd, fn)
self.log("tagging " + abspath) tags = self.mtag.get(abspath)
ntags1 = len(tags)
if self.mtp_parsers.get(ptop, {}):
parser = {
k: v
for k, v in self.mtp_parsers[ptop].items()
if k in self.mtp_force[ptop] or k not in tags
}
tags.update(self.mtag.get_bin(parser, abspath))
with self.mutex: with self.mutex:
cur = self.cur[ptop] cur = self.cur[ptop]
if not cur: if not cur:
@ -1281,11 +1303,11 @@ class Up2k(object):
self.log("no entags okay.jpg", c=3) self.log("no entags okay.jpg", c=3)
continue continue
if "e2t" in self.flags[ptop]: self._tag_file(cur, entags, wark, abspath, tags)
self._tag_file(cur, entags, wark, abspath)
cur.connection.commit() cur.connection.commit()
self.log("tagged {} ({}+{})".format(abspath, ntags1, len(tags) - ntags1))
def _hasher(self): def _hasher(self):
while True: while True:
ptop, rd, fn = self.hashq.get() ptop, rd, fn = self.hashq.get()