From d56230573dc63f9aa1ee5f3100112e3f00886894 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 14 Aug 2025 20:02:32 +0000 Subject: [PATCH] separate audio-transcode timeout (#598) --- copyparty/__main__.py | 3 ++- copyparty/authsrv.py | 2 +- copyparty/cfg.py | 4 +++- copyparty/th_srv.py | 26 +++++++++++++------------- tests/util.py | 2 +- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index b538b6a9..4ae60e61 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1435,7 +1435,8 @@ def add_thumbnail(ap): ap2.add_argument("--no-athumb", action="store_true", help="disable audio thumbnails (spectrograms) (volflag=dathumb)") ap2.add_argument("--th-size", metavar="WxH", default="320x256", help="thumbnail res (volflag=thsize)") ap2.add_argument("--th-mt", metavar="CORES", type=int, default=CORES, help="num cpu cores to use for generating thumbnails") - ap2.add_argument("--th-convt", metavar="SEC", type=float, default=60.0, help="conversion timeout in seconds (volflag=convt)") + ap2.add_argument("--th-convt", metavar="SEC", type=float, default=60.0, help="convert-to-image timeout in seconds (volflag=convt)") + ap2.add_argument("--ac-convt", metavar="SEC", type=float, default=150.0, help="convert-to-audio timeout in seconds (volflag=aconvt)") ap2.add_argument("--th-ram-max", metavar="GB", type=float, default=th_ram, help="max memory usage (GiB) permitted by thumbnailer; not very accurate") ap2.add_argument("--th-crop", metavar="TXT", type=u, default="y", help="crop thumbnails to 4:3 or keep dynamic height; client can override in UI unless force. [\033[32my\033[0m]=crop, [\033[32mn\033[0m]=nocrop, [\033[32mfy\033[0m]=force-y, [\033[32mfn\033[0m]=force-n (volflag=crop)") ap2.add_argument("--th-x3", metavar="TXT", type=u, default="n", help="show thumbs at 3x resolution; client can override in UI unless force. [\033[32my\033[0m]=yes, [\033[32mn\033[0m]=no, [\033[32mfy\033[0m]=force-yes, [\033[32mfn\033[0m]=force-no (volflag=th3x)") diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index 63613cc8..d65169ed 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -2220,7 +2220,7 @@ class AuthSrv(object): if k in vol.flags: vol.flags[k] = int(vol.flags[k]) - zs = "convt tail_fd tail_rate tail_tmax" + zs = "aconvt convt tail_fd tail_rate tail_tmax" for k in zs.split(): if k in vol.flags: vol.flags[k] = float(vol.flags[k]) diff --git a/copyparty/cfg.py b/copyparty/cfg.py index 8a07f956..5b1651c4 100644 --- a/copyparty/cfg.py +++ b/copyparty/cfg.py @@ -68,6 +68,7 @@ def vf_bmap() -> dict[str, str]: def vf_vmap() -> dict[str, str]: """argv-to-volflag: simple values""" ret = { + "ac_convt": "aconvt", "no_hash": "nohash", "no_idx": "noidx", "re_maxage": "scan", @@ -260,7 +261,8 @@ flagcats = { "thsize": "thumbnail res; WxH", "crop": "center-cropping (y/n/fy/fn)", "th3x": "3x resolution (y/n/fy/fn)", - "convt": "conversion timeout in seconds", + "convt": "convert-to-image timeout in seconds", + "aconvt": "convert-to-audio timeout in seconds", "ext_th=s=/b.png": "use /b.png as thumbnail for file-extension s", }, "handlers\n(better explained in --help-handlers)": { diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index 537c748a..2522f3a6 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -662,11 +662,11 @@ class ThumbSrv(object): ] cmd += [fsenc(tpath)] - self._run_ff(cmd, vn) + self._run_ff(cmd, vn, "convt") - def _run_ff(self, cmd: list[bytes], vn: VFS, oom: int = 400) -> None: + def _run_ff(self, cmd: list[bytes], vn: VFS, kto: str, oom: int = 400) -> None: # self.log((b" ".join(cmd)).decode("utf-8")) - ret, _, serr = runcmd(cmd, timeout=vn.flags["convt"], nice=True, oom=oom) + ret, _, serr = runcmd(cmd, timeout=vn.flags[kto], nice=True, oom=oom) if not ret: return @@ -748,7 +748,7 @@ class ThumbSrv(object): # fmt: on cmd += [fsenc(tpath)] - self._run_ff(cmd, vn) + self._run_ff(cmd, vn, "convt") if "pngquant" in vn.flags: wtpath = tpath + ".png" @@ -809,7 +809,7 @@ class ThumbSrv(object): b"-y", fsenc(infile), ] # fmt: on - self._run_ff(cmd, vn) + self._run_ff(cmd, vn, "convt") fc = "[0:a:0]aresample=48000{},showspectrumpic=s=" if "3" in fmt: @@ -851,7 +851,7 @@ class ThumbSrv(object): ] cmd += [fsenc(tpath)] - self._run_ff(cmd, vn) + self._run_ff(cmd, vn, "convt") def conv_mp3(self, abspath: str, tpath: str, fmt: str, vn: VFS) -> None: quality = self.args.q_mp3.lower() @@ -890,7 +890,7 @@ class ThumbSrv(object): fsenc(tpath) ] # fmt: on - self._run_ff(cmd, vn, oom=300) + self._run_ff(cmd, vn, "aconvt", oom=300) def conv_flac(self, abspath: str, tpath: str, fmt: str, vn: VFS) -> None: if self.args.no_acode or not self.args.allow_flac: @@ -915,7 +915,7 @@ class ThumbSrv(object): fsenc(tpath) ] # fmt: on - self._run_ff(cmd, vn, oom=300) + self._run_ff(cmd, vn, "aconvt", oom=300) def conv_wav(self, abspath: str, tpath: str, fmt: str, vn: VFS) -> None: if self.args.no_acode or not self.args.allow_wav: @@ -950,7 +950,7 @@ class ThumbSrv(object): fsenc(tpath) ] # fmt: on - self._run_ff(cmd, vn, oom=300) + self._run_ff(cmd, vn, "aconvt", oom=300) def conv_opus(self, abspath: str, tpath: str, fmt: str, vn: VFS) -> None: if self.args.no_acode or not self.args.q_opus: @@ -1006,7 +1006,7 @@ class ThumbSrv(object): fsenc(tpath) ] # fmt: on - self._run_ff(cmd, vn, oom=300) + self._run_ff(cmd, vn, "aconvt", oom=300) def _conv_caf( self, @@ -1046,7 +1046,7 @@ class ThumbSrv(object): fsenc(tmp_opus) ] # fmt: on - self._run_ff(cmd, vn, oom=300) + self._run_ff(cmd, vn, "aconvt", oom=300) # iOS fails to play some "insufficiently complex" files # (average file shorter than 8 seconds), so of course we @@ -1073,7 +1073,7 @@ class ThumbSrv(object): fsenc(tpath) ] # fmt: on - self._run_ff(cmd, vn, oom=300) + self._run_ff(cmd, vn, "aconvt", oom=300) else: # simple remux should be safe @@ -1092,7 +1092,7 @@ class ThumbSrv(object): fsenc(tpath) ] # fmt: on - self._run_ff(cmd, vn, oom=300) + self._run_ff(cmd, vn, "aconvt", oom=300) try: wunlink(self.log, tmp_opus, vn.flags) diff --git a/tests/util.py b/tests/util.py index 16c75e92..80e3067e 100644 --- a/tests/util.py +++ b/tests/util.py @@ -158,7 +158,7 @@ class Cfg(Namespace): ex = "hash_mt hsortn qdel safe_dedup srch_time tail_fd tail_rate u2abort u2j u2sz" ka.update(**{k: 1 for k in ex.split()}) - ex = "au_vol dl_list mtab_age reg_cap s_thead s_tbody tail_tmax tail_who th_convt ups_who zip_who" + ex = "ac_convt au_vol dl_list mtab_age reg_cap s_thead s_tbody tail_tmax tail_who th_convt ups_who zip_who" ka.update(**{k: 9 for k in ex.split()}) ex = "ctl_re db_act forget_ip idp_cookie idp_store k304 loris no304 nosubtle qr_pin re_maxage rproxy rsp_jtr rsp_slp s_wr_slp snap_wri theme themes turbo u2ow zipmaxn zipmaxs"