option to disable caf transcoding + misc cleanup

This commit is contained in:
ed 2025-01-24 22:40:52 +00:00
parent c9eba39edd
commit f3b9bfc114
5 changed files with 15 additions and 16 deletions

View file

@ -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")

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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)