From 1cdb1702908256ee1343d6a3e239ba82fbf5d01f Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 13 Jul 2024 00:54:38 +0200 Subject: [PATCH] order-significant `--th-covers`; the first matching filename as listed in the `--th-covers` global-option will always be selected --- README.md | 1 + copyparty/svchub.py | 6 ++++-- copyparty/up2k.py | 44 +++++++++++++++++++++++++++++++++++--------- tests/util.py | 5 ++++- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d418dca0..67a70e2c 100644 --- a/README.md +++ b/README.md @@ -575,6 +575,7 @@ it does static images with Pillow / pyvips / FFmpeg, and uses FFmpeg for video f audio files are covnerted into spectrograms using FFmpeg unless you `--no-athumb` (and some FFmpeg builds may need `--th-ff-swr`) images with the following names (see `--th-covers`) become the thumbnail of the folder they're in: `folder.png`, `folder.jpg`, `cover.png`, `cover.jpg` +* the order is significant, so if both `cover.png` and `folder.jpg` exist in a folder, it will pick the first matching `--th-covers` entry (`folder.jpg`) * and, if you enable [file indexing](#file-indexing), it will also try those names as dotfiles (`.folder.jpg` and so), and then fallback on the first picture in the folder (if it has any pictures at all) in the grid/thumbnail view, if the audio player panel is open, songs will start playing when clicked diff --git a/copyparty/svchub.py b/copyparty/svchub.py index 50cc14ed..aed389ad 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -479,8 +479,10 @@ class SvcHub(object): zsl = al.th_covers.split(",") zsl = [x.strip() for x in zsl] zsl = [x for x in zsl if x] - al.th_covers = set(zsl) - al.th_coversd = set(zsl + ["." + x for x in zsl]) + al.th_covers = zsl + al.th_coversd = zsl + ["." + x for x in zsl] + al.th_covers_set = set(al.th_covers) + al.th_coversd_set = set(al.th_coversd) for k in "c".split(" "): vl = getattr(al, k) diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 4d239dec..4d209dba 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -1195,6 +1195,9 @@ class Up2k(object): fat32 = True cv = "" + th_cvd = self.args.th_coversd + th_cvds = self.args.th_coversd_set + assert self.pp and self.mem_cur self.pp.msg = "a%d %s" % (self.pp.n, cdir) @@ -1279,12 +1282,21 @@ class Up2k(object): files.append((sz, lmod, iname)) liname = iname.lower() - if sz and ( - iname in self.args.th_coversd - or ( + if ( + sz + and ( + liname in th_cvds + or ( + not cv + and liname.rsplit(".", 1)[-1] in CV_EXTS + and not iname.startswith(".") + ) + ) + and ( not cv - and liname.rsplit(".", 1)[-1] in CV_EXTS - and not iname.startswith(".") + or liname not in th_cvds + or cv.lower() not in th_cvds + or th_cvd.index(iname) < th_cvd.index(cv) ) ): cv = iname @@ -3319,15 +3331,29 @@ class Up2k(object): with self.rescan_cond: self.rescan_cond.notify_all() - if rd and sz and fn.lower() in self.args.th_coversd: + if rd and sz and fn.lower() in self.args.th_coversd_set: # wasteful; db_add will re-index actual covers # but that won't catch existing files crd, cdn = rd.rsplit("/", 1) if "/" in rd else ("", rd) try: - db.execute("delete from cv where rd=? and dn=?", (crd, cdn)) - db.execute("insert into cv values (?,?,?)", (crd, cdn, fn)) + q = "select fn from cv where rd=? and dn=?" + db_cv = db.execute(q, (crd, cdn)).fetchone()[0] + db_lcv = db_cv.lower() + if db_lcv in self.args.th_coversd_set: + idx_db = self.args.th_coversd.index(db_lcv) + idx_fn = self.args.th_coversd.index(fn.lower()) + add_cv = idx_fn < idx_db + else: + add_cv = True except: - pass + add_cv = True + + if add_cv: + try: + db.execute("delete from cv where rd=? and dn=?", (crd, cdn)) + db.execute("insert into cv values (?,?,?)", (crd, cdn, fn)) + except: + pass def handle_rm( self, diff --git a/tests/util.py b/tests/util.py index 85fb202f..c1feca8b 100644 --- a/tests/util.py +++ b/tests/util.py @@ -135,7 +135,7 @@ class Cfg(Namespace): ex = "grp on403 on404 xad xar xau xban xbd xbr xbu xiu xm" ka.update(**{k: [] for k in ex.split()}) - ex = "exp_lg exp_md th_coversd" + ex = "exp_lg exp_md" ka.update(**{k: {} for k in ex.split()}) ka.update(ka0) @@ -163,6 +163,9 @@ class Cfg(Namespace): sort="href", srch_hits=99999, th_covers=["folder.png"], + th_coversd=["folder.png"], + th_covers_set=set(["folder.png"]), + th_coversd_set=set(["folder.png"]), th_crop="y", th_size="320x256", th_x3="n",