From f3b9bfc1146a03c8d8133ef2ffb518d52be1a4c6 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 24 Jan 2025 22:40:52 +0000 Subject: [PATCH] option to disable caf transcoding + misc cleanup --- copyparty/__main__.py | 1 + copyparty/th_cli.py | 6 ++++-- copyparty/th_srv.py | 14 +++++++++----- copyparty/web/svcs.js | 8 -------- copyparty/web/util.js | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 0ecbdcb9..8451ca7b 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1373,6 +1373,7 @@ def add_transcoding(ap): ap2 = ap.add_argument_group('transcoding options') ap2.add_argument("--q-opus", metavar="KBPS", type=int, default=128, help="target bitrate for transcoding to opus; set 0 to disable") ap2.add_argument("--q-mp3", metavar="QUALITY", type=u, default="q2", help="target quality for transcoding to mp3, for example [\033[32m192k\033[0m] (CBR) or [\033[32mq0\033[0m] (CQ/CRF, q0=maxquality, q9=smallest); set 0 to disable") + ap2.add_argument("--no-caf", action="store_true", help="disable transcoding to caf-opus (iOS v12 and later), use mp3 instead") ap2.add_argument("--no-acode", action="store_true", help="disable audio transcoding") ap2.add_argument("--no-bacode", action="store_true", help="disable batch audio transcoding by folder download (zip/tar)") ap2.add_argument("--ac-maxage", metavar="SEC", type=int, default=86400, help="delete cached transcode output after \033[33mSEC\033[0m seconds") diff --git a/copyparty/th_cli.py b/copyparty/th_cli.py index 9b6e0dd8..7dafea5f 100644 --- a/copyparty/th_cli.py +++ b/copyparty/th_cli.py @@ -6,7 +6,7 @@ import os from .__init__ import TYPE_CHECKING from .authsrv import VFS from .bos import bos -from .th_srv import HAVE_WEBP, thumb_path +from .th_srv import EXTS_AC, HAVE_WEBP, thumb_path from .util import Cooldown if True: # pylint: disable=using-constant-test @@ -57,13 +57,15 @@ class ThumbCli(object): if is_vid and "dvthumb" in dbv.flags: return None - want_opus = fmt in ("opus", "caf", "mp3") + want_opus = fmt in EXTS_AC is_au = ext in self.fmt_ffa is_vau = want_opus and ext in self.fmt_ffv if is_au or is_vau: if want_opus: if self.args.no_acode: return None + elif fmt == "caf" and self.args.no_caf: + fmt = "mp3" else: if "dathumb" in dbv.flags: return None diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index 70f6d644..a3d9d660 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -46,6 +46,9 @@ HAVE_HEIF = False HAVE_AVIF = False HAVE_WEBP = False +EXTS_TH = set(["jpg", "webp", "png"]) +EXTS_AC = set(["opus", "caf", "mp3"]) + try: if os.environ.get("PRTY_NO_PIL"): raise Exception() @@ -139,7 +142,7 @@ def thumb_path(histpath: str, rem: str, mtime: float, fmt: str, ffa: set[str]) - h = hashlib.sha512(afsenc(fn)).digest() fn = ub64enc(h).decode("ascii")[:24] - if fmt in ("opus", "caf", "mp3"): + if fmt in EXTS_AC: cat = "ac" else: fc = fmt[:1] @@ -334,9 +337,10 @@ class ThumbSrv(object): ap_unpk = abspath if not bos.path.exists(tpath): - want_mp3 = tpath.endswith(".mp3") - want_opus = tpath.endswith(".opus") or tpath.endswith(".caf") - want_png = tpath.endswith(".png") + tex = tpath.rsplit(".", 1)[-1] + want_mp3 = tex == "mp3" + want_opus = tex in ("opus", "caf") + want_png = tex == "png" want_au = want_mp3 or want_opus for lib in self.args.th_dec: can_au = lib == "ff" and ( @@ -891,7 +895,7 @@ class ThumbSrv(object): def _clean(self, cat: str, thumbpath: str) -> int: # self.log("cln {}".format(thumbpath)) - exts = ["jpg", "webp", "png"] if cat == "th" else ["opus", "caf", "mp3"] + exts = EXTS_TH if cat == "th" else EXTS_AC maxage = getattr(self.args, cat + "_maxage") now = time.time() prev_b64 = None diff --git a/copyparty/web/svcs.js b/copyparty/web/svcs.js index 7f251c35..10513fd2 100644 --- a/copyparty/web/svcs.js +++ b/copyparty/web/svcs.js @@ -1,11 +1,3 @@ -function QSA(x) { - return document.querySelectorAll(x); -} -var LINUX = /Linux/.test(UA), - MACOS = /[^a-z]mac ?os/i.test(UA), - WINDOWS = /Windows/.test(UA); - - var oa = QSA('pre'); for (var a = 0; a < oa.length; a++) { var html = oa[a].innerHTML, diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 53a5d76d..a267f0eb 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -36,7 +36,7 @@ var wah = '', FIREFOX = ('netscape' in window) && / rv:/.test(UA), IPHONE = TOUCH && /iPhone|iPad|iPod/i.test(UA), LINUX = /Linux/.test(UA), - MACOS = /[^a-z]mac ?os/i.test(UA), + MACOS = /Macintosh/.test(UA), WINDOWS = /Windows/.test(UA); if (!window.WebAssembly || !WebAssembly.Memory)