order-significant --th-covers;

the first matching filename as listed in the
`--th-covers` global-option will always be selected
This commit is contained in:
ed 2024-07-13 00:54:38 +02:00
parent d5de3f2fe0
commit 1cdb170290
4 changed files with 44 additions and 12 deletions

View file

@ -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`) 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` 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) * 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 in the grid/thumbnail view, if the audio player panel is open, songs will start playing when clicked

View file

@ -479,8 +479,10 @@ class SvcHub(object):
zsl = al.th_covers.split(",") zsl = al.th_covers.split(",")
zsl = [x.strip() for x in zsl] zsl = [x.strip() for x in zsl]
zsl = [x for x in zsl if x] zsl = [x for x in zsl if x]
al.th_covers = set(zsl) al.th_covers = zsl
al.th_coversd = set(zsl + ["." + x for x in 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(" "): for k in "c".split(" "):
vl = getattr(al, k) vl = getattr(al, k)

View file

@ -1195,6 +1195,9 @@ class Up2k(object):
fat32 = True fat32 = True
cv = "" cv = ""
th_cvd = self.args.th_coversd
th_cvds = self.args.th_coversd_set
assert self.pp and self.mem_cur assert self.pp and self.mem_cur
self.pp.msg = "a%d %s" % (self.pp.n, cdir) self.pp.msg = "a%d %s" % (self.pp.n, cdir)
@ -1279,12 +1282,21 @@ class Up2k(object):
files.append((sz, lmod, iname)) files.append((sz, lmod, iname))
liname = iname.lower() liname = iname.lower()
if sz and ( if (
iname in self.args.th_coversd sz
or ( and (
liname in th_cvds
or (
not cv
and liname.rsplit(".", 1)[-1] in CV_EXTS
and not iname.startswith(".")
)
)
and (
not cv not cv
and liname.rsplit(".", 1)[-1] in CV_EXTS or liname not in th_cvds
and not iname.startswith(".") or cv.lower() not in th_cvds
or th_cvd.index(iname) < th_cvd.index(cv)
) )
): ):
cv = iname cv = iname
@ -3319,15 +3331,29 @@ class Up2k(object):
with self.rescan_cond: with self.rescan_cond:
self.rescan_cond.notify_all() 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 # wasteful; db_add will re-index actual covers
# but that won't catch existing files # but that won't catch existing files
crd, cdn = rd.rsplit("/", 1) if "/" in rd else ("", rd) crd, cdn = rd.rsplit("/", 1) if "/" in rd else ("", rd)
try: try:
db.execute("delete from cv where rd=? and dn=?", (crd, cdn)) q = "select fn from cv where rd=? and dn=?"
db.execute("insert into cv values (?,?,?)", (crd, cdn, fn)) 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: 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( def handle_rm(
self, self,

View file

@ -135,7 +135,7 @@ class Cfg(Namespace):
ex = "grp on403 on404 xad xar xau xban xbd xbr xbu xiu xm" ex = "grp on403 on404 xad xar xau xban xbd xbr xbu xiu xm"
ka.update(**{k: [] for k in ex.split()}) 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(**{k: {} for k in ex.split()})
ka.update(ka0) ka.update(ka0)
@ -163,6 +163,9 @@ class Cfg(Namespace):
sort="href", sort="href",
srch_hits=99999, srch_hits=99999,
th_covers=["folder.png"], th_covers=["folder.png"],
th_coversd=["folder.png"],
th_covers_set=set(["folder.png"]),
th_coversd_set=set(["folder.png"]),
th_crop="y", th_crop="y",
th_size="320x256", th_size="320x256",
th_x3="n", th_x3="n",