retire ogvjs

This commit is contained in:
ed 2021-11-14 19:28:44 +01:00
parent b206c5d64e
commit 51e6c4852b
10 changed files with 90 additions and 211 deletions

View file

@ -30,7 +30,7 @@ class ThumbCli(object):
if is_vid and self.args.no_vthumb:
return None
want_opus = fmt == "opus"
want_opus = fmt in ("opus", "caf")
is_au = ext in FMT_FFA
if is_au:
if want_opus:

View file

@ -90,7 +90,7 @@ def thumb_path(histpath, rem, mtime, fmt):
h = hashlib.sha512(fsenc(fn)).digest()
fn = base64.urlsafe_b64encode(h).decode("ascii")[:24]
if fmt == "opus":
if fmt in ("opus", "caf"):
cat = "ac"
else:
fmt = "webp" if fmt == "w" else "jpg"
@ -216,7 +216,7 @@ class ThumbSrv(object):
elif ext in FMT_FFV:
fun = self.conv_ffmpeg
elif ext in FMT_FFA:
if tpath.endswith(".opus"):
if tpath.endswith(".opus") or tpath.endswith(".caf"):
fun = self.conv_opus
else:
fun = self.conv_spec
@ -406,6 +406,13 @@ class ThumbSrv(object):
if "ac" not in ret:
raise Exception("not audio")
src_opus = abspath.lower().endswith(".opus") or ret["ac"][1] == "opus"
want_caf = tpath.endswith(".caf")
tmp_opus = tpath
if want_caf:
tmp_opus = tpath.rsplit(".", 1)[0] + ".opus"
if not want_caf or (not src_opus and not bos.path.isfile(tmp_opus)):
# fmt: off
cmd = [
b"ffmpeg",
@ -413,13 +420,30 @@ class ThumbSrv(object):
b"-v", b"error",
b"-hide_banner",
b"-i", fsenc(abspath),
b"-map_metadata", b"-1",
b"-map", b"0:a:0",
b"-c:a", b"libopus",
b"-b:a", b"128k",
fsenc(tmp_opus)
]
# fmt: on
self._run_ff(cmd)
if want_caf:
# fmt: off
cmd = [
b"ffmpeg",
b"-nostdin",
b"-v", b"error",
b"-hide_banner",
b"-i", fsenc(abspath if src_opus else tmp_opus),
b"-map_metadata", b"-1",
b"-map", b"0:a:0",
b"-c:a", b"copy",
b"-f", b"caf",
fsenc(tpath)
]
# fmt: on
self._run_ff(cmd)
def poke(self, tdir):
@ -461,7 +485,7 @@ class ThumbSrv(object):
thumbpath = os.path.join(histpath, cat)
# self.log("cln {}".format(thumbpath))
exts = ["jpg", "webp"] if cat == "th" else ["opus"]
exts = ["jpg", "webp"] if cat == "th" else ["opus", "caf"]
maxage = getattr(self.args, cat + "_maxage")
now = time.time()
prev_b64 = None

View file

@ -104,6 +104,7 @@ MIMES = {
"txt": "text/plain",
"js": "text/javascript",
"opus": "audio/ogg; codecs=opus",
"caf": "audio/x-caf",
"mp3": "audio/mpeg",
"m4a": "audio/mp4",
"jpg": "image/jpeg",

View file

@ -397,13 +397,15 @@ var mpl = (function () {
c = r.ac_flac;
else if (/\.(aac|m4a)$/i.exec(url))
c = r.ac_aac;
else if (/\.opus$/i.exec(url) && !can_ogg)
c = true;
else if (re_au_native.exec(url))
c = false;
if (!c)
return url;
return url + (url.indexOf('?') < 0 ? '?' : '&') + 'th=opus';
return url + (url.indexOf('?') < 0 ? '?' : '&') + 'th=' + (can_ogg ? 'opus' : 'caf');
};
r.pp = function () {
@ -471,14 +473,10 @@ var mpl = (function () {
};
r.unbuffer = function (url) {
for (var a = 0; a < 2; a++) {
var au = a ? mp.au_native2 : mp.au_ogvjs2;
if (au && (!url || au.src == url)) {
au.src = '';
au.load();
if (mp.au2 && (!url || mp.au2.src == url)) {
mp.au2.src = '';
mp.au2.load();
}
}
if (!url)
mpl.preload_url = null;
}
@ -487,7 +485,18 @@ var mpl = (function () {
})();
var re_au_native = /\.(opus|ogg|m4a|aac|mp3|wav|flac)$/i,
var can_ogg = true;
try {
can_ogg = new Audio().canPlayType('audio/ogg; codecs=opus') === 'probably';
if (document.documentMode)
can_ogg = true; // ie8-11
}
catch (ex) { }
var re_au_native = can_ogg ? /\.(opus|ogg|m4a|aac|mp3|wav|flac)$/i :
have_acode ? /\.(opus|m4a|aac|mp3|wav|flac)$/i : /\.(m4a|aac|mp3|wav|flac)$/i,
re_au_all = /\.(aac|m4a|ogg|opus|flac|alac|mp3|mp2|ac3|dts|wma|ra|wav|aif|aiff|au|alaw|ulaw|mulaw|amr|gsm|ape|tak|tta|wv)$/i;
@ -496,10 +505,8 @@ function MPlayer() {
var r = this;
r.id = Date.now();
r.au = null;
r.au_native = null;
r.au_native2 = null;
r.au_ogvjs = null;
r.au_ogvjs2 = null;
r.au = null;
r.au2 = new Audio();
r.tracks = {};
r.order = [];
@ -604,7 +611,7 @@ function MPlayer() {
url += (url.indexOf('?') < 0 ? '?' : '&') + 'cache=987';
mpl.preload_url = full ? url : null;
var t0 = Date.now();
if (full && !need_ogv_for(url))
if (full)
return fetch(url).then(function (x) {
var rd = x.body.getReader(), n = 0;
function spd() {
@ -627,23 +634,8 @@ function MPlayer() {
drop();
});
var au = null;
if (need_ogv_for(url)) {
au = mp.au_ogvjs2;
if (!au && window['OGVPlayer'])
au = r.au_ogvjs2 = new OGVPlayer();
au.mdng = true;
bind_ogvjs();
} else {
au = mp.au_native2;
if (!au)
au = r.au_native2 = new Audio();
}
if (au) {
au.preload = "auto";
au.src = url;
}
mp.au2.preload = "auto";
mp.au2.src = url;
};
}
@ -804,7 +796,7 @@ var pbar = (function () {
bctx.clearRect(0, 0, bc.w, bc.h);
if (!mp.au || mp.au.mdng)
if (!mp.au)
return;
var sm = bc.w * 1.0 / mp.au.duration,
@ -831,7 +823,7 @@ var pbar = (function () {
pctx.clearRect(0, 0, pc.w, pc.h);
if (!mp.au || mp.au.mdng || isNaN(adur = mp.au.duration) || isNaN(apos = mp.au.currentTime) || apos < 0 || adur < apos)
if (!mp.au || isNaN(adur = mp.au.duration) || isNaN(apos = mp.au.currentTime) || apos < 0 || adur < apos)
return; // not-init || unsupp-codec
var sm = bc.w * 1.0 / adur;
@ -1101,7 +1093,7 @@ var mpui = (function () {
}
// preload next song
if (mpl.preload && !mp.au.mdng && preloaded != mp.au.src) {
if (mpl.preload && preloaded != mp.au.src) {
var pos = mp.au.currentTime,
len = mp.au.duration,
rem = pos > 0 ? len - pos : 999,
@ -1146,36 +1138,6 @@ function ev_play(e) {
}
var need_ogv = true;
try {
need_ogv = new Audio().canPlayType('audio/ogg; codecs=opus') !== 'probably';
if (document.documentMode)
need_ogv = false; // ie8-11
}
catch (ex) { }
function need_ogv_for(url) {
return need_ogv && /\.(ogg|opus)|\?th=opus/i.test(url);
}
function start_sinegen() {
var af = 'data:audio/wav;base64,UklGRlaxAgBXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAATElTVBoAAABJTkZPSVNGVA4AAABMYXZmNTguNzYuMTAwAGRhdGEQsQIAAAB',
body = 'iArcE8AYCCeEKggzaDeQOmA/0D/QPmQ/kDtsNggzhCgMJ8Qa4BGMCAQCe/Un7EPn+9h/1fvMm8hzxaPAM8AzwZ/Ac8SXyfvMf9f32D/lI+539//9';
while (af.length < 235304)
af += body;
var au = new Audio(af.slice(0, 235304));
au.onplay = au.pause.bind(au);
au.volume = 0.5;
au.play();
return au;
}
var audio_eq = (function () {
var r = {
"en": false,
@ -1261,9 +1223,6 @@ var audio_eq = (function () {
if (!r.en && !mp.ac)
return;
if (mp.au === mp.au_ogvjs)
return toast.warn(10, "apple devices can't equalize ogg/opus audio");
if (mp.ac) {
for (var a = 0; a < r.filters.length; a++)
r.filters[a].disconnect();
@ -1413,25 +1372,6 @@ var audio_eq = (function () {
})();
function bind_ogvjs() {
var a1 = mp.au_ogvjs,
a2 = mp.au_ogvjs2;
if (a2) {
a2.onerror = a2.onprogress = a2.onended = null;
a2.onloadedmetadata = a2.onloadeddata = function () {
a2.mdng = false;
};
}
a1.onerror = evau_error;
a1.onprogress = pbar.drawpos;
a1.onended = next_song;
a1.onloadedmetadata = a1.onloadeddata = function () {
a1.mdng = false;
};
}
// plays the tid'th audio file on the page
function play(tid, is_ev, seek, call_depth) {
if (mp.order.length == 0)
@ -1477,73 +1417,22 @@ function play(tid, is_ev, seek, call_depth) {
clmod(ebi('a' + mp.au.tid), 'act');
}
// ogv.js breaks on .play() unless directly user-triggered
var attempt_play = true;
var url = mpl.acode(mp.tracks[tid]);
if (need_ogv_for(url)) {
var m = /.* Version\/([0-9]+)\.[0-9\.]+ Mobile\/[^ ]+ Safari\/[0-9\.]+$/.exec(navigator.userAgent),
safari = m ? parseInt(m[1]) : 99;
if (mp.au_ogvjs) {
mp.au = mp.au_ogvjs;
}
else if (window['OGVPlayer']) {
try {
mp.au = mp.au_ogvjs = new OGVPlayer();
}
catch (ex) {
return toast.err(30, 'your browser cannot play ogg/vorbis/opus\n\n' + basenames(ex) +
'\n\n<a href="#" onclick="new OGVPlayer();">click here</a> for a full crash report');
}
attempt_play = is_ev;
mp.au.mdng = true;
bind_ogvjs();
widget.open();
}
else if (safari < 14) {
return toast.err(0, 'because this is an apple device,\nsafari 14 or newer is required to play ogg/vorbis/opus files\n\nyou are using safari ' + safari + '\n(every iOS browser is actually safari)');
}
else {
if (call_depth !== undefined)
return toast.err(0, 'failed to load ogv.js:\ncannot play ogg/opus in this browser\n(try a non-apple device)');
toast.inf(0, '<h1>loading ogv.js</h1><h2>thanks apple</h2>');
import_js('/.cpr/deps/ogv.js', function () {
toast.hide();
play(tid, false, seek, 1);
});
return;
}
}
else {
if (!mp.au_native) {
mp.au = mp.au_native = new Audio();
if (!mp.au) {
mp.au = new Audio();
mp.au.onerror = evau_error;
mp.au.onprogress = pbar.drawpos;
mp.au.onended = next_song;
widget.open();
}
mp.au = mp.au_native;
}
audio_eq.apply();
url += (url.indexOf('?') < 0 ? '?' : '&') + 'cache=987';
if (mp.au_ogvjs2 && mp.au_ogvjs2.src === url) {
mp.au = mp.au_ogvjs2;
mp.au_ogvjs2 = mp.au_ogvjs;
mp.au_ogvjs = mp.au;
bind_ogvjs();
}
if (mp.au.src == url)
mp.au.currentTime = 0;
else {
mp.au.mdng = mp.au == mp.au_ogvjs;
mp.au.src = url;
}
@ -1565,9 +1454,7 @@ function play(tid, is_ev, seek, call_depth) {
thegrid.loadsel();
try {
if (attempt_play)
mp.au.play();
if (mp.au.paused)
autoplay_blocked(seek);
else if (seek) {
@ -1633,15 +1520,9 @@ function autoplay_blocked(seek) {
fn = uricom_dec(fn.replace(/\+/g, ' '))[0];
modal.confirm('<h6>play this audio file?</h6>\n«' + esc(fn) + '»', function () {
if (mp.au !== mp.au_ogvjs)
// chrome 91 may permanently taint on a failed play()
// depending on win10 settings or something? idk
mp.au_native = null;
else
// iOS browsers allow playing ogg/vorbis/opus in the background
// if there is an <audio> tag which at some point played audio
if (!mp.sinegen)
mp.sinegen = start_sinegen();
mp.au = null;
play(tid, true, seek);
mp.fade_in();

View file

@ -286,6 +286,9 @@ function crc32(str) {
function clmod(el, cls, add) {
if (!el)
return;
if (el.classList) {
var have = el.classList.contains(cls);
if (add == 't')
@ -311,6 +314,9 @@ function clmod(el, cls, add) {
function clgot(el, cls) {
if (!el)
return;
if (el.classList)
return el.classList.contains(cls);

View file

@ -185,7 +185,7 @@ about:config >> devtools.debugger.prefs-schema-version = -1
git pull; git reset --hard origin/HEAD && git log --format=format:"%H %ai %d" --decorate=full > ../revs && cat ../{util,browser,up2k}.js >../vr && cat ../revs | while read -r rev extra; do (git reset --hard $rev >/dev/null 2>/dev/null && dsz=$(cat copyparty/web/{util,browser,up2k}.js >../vg 2>/dev/null && diff -wNarU0 ../{vg,vr} | wc -c) && printf '%s %6s %s\n' "$rev" $dsz "$extra") </dev/null; done
# download all sfx versions
curl https://api.github.com/repos/9001/copyparty/releases?per_page=100 | jq -r '.[] | .tag_name + " " + .name' | tr -d '\r' | while read v t; do fn="copyparty $v $t.py"; [ -e "$fn" ] || curl https://github.com/9001/copyparty/releases/download/$v/copyparty-sfx.py -Lo "$fn"; done
curl https://api.github.com/repos/9001/copyparty/releases?per_page=100 | jq -r '.[] | .tag_name + " " + .name' | tr -d '\r' | while read v t; do fn="$(printf '%s\n' "copyparty $v $t.py" | tr / -)"; [ -e "$fn" ] || curl https://github.com/9001/copyparty/releases/download/$v/copyparty-sfx.py -Lo "$fn"; done
##

View file

@ -140,10 +140,10 @@ repack() {
}
repack sfx-full "re gz no-sh"
repack sfx-ent "re no-dd no-ogv"
repack sfx-ent "re no-dd no-ogv gz no-sh"
repack sfx-lite "re no-dd no-ogv no-cm no-hl"
repack sfx-lite "re no-dd no-ogv no-cm no-hl gz no-sh"
repack sfx-ent "re no-dd"
repack sfx-ent "re no-dd gz no-sh"
repack sfx-lite "re no-dd no-cm no-hl"
repack sfx-lite "re no-dd no-cm no-hl gz no-sh"
# move fuse and up2k clients into copyparty-extras/,

View file

@ -3,7 +3,6 @@ WORKDIR /z
ENV ver_asmcrypto=5b994303a9d3e27e0915f72a10b6c2c51535a4dc \
ver_hashwasm=4.9.0 \
ver_marked=3.0.4 \
ver_ogvjs=1.8.4 \
ver_mde=2.15.0 \
ver_codemirror=5.62.3 \
ver_fontawesome=5.13.0 \
@ -15,7 +14,6 @@ ENV ver_asmcrypto=5b994303a9d3e27e0915f72a10b6c2c51535a4dc \
RUN mkdir -p /z/dist/no-pk \
&& wget https://fonts.gstatic.com/s/sourcecodepro/v11/HI_SiYsKILxRpg3hIP6sJ7fM7PqlPevW.woff2 -O scp.woff2 \
&& apk add cmake make g++ git bash npm patch wget tar pigz brotli gzip unzip python3 python3-dev brotli py3-brotli \
&& wget https://github.com/brion/ogv.js/releases/download/$ver_ogvjs/ogvjs-$ver_ogvjs.zip -O ogvjs.zip \
&& wget https://github.com/openpgpjs/asmcrypto.js/archive/$ver_asmcrypto.tar.gz -O asmcrypto.tgz \
&& wget https://github.com/markedjs/marked/archive/v$ver_marked.tar.gz -O marked.tgz \
&& wget https://github.com/Ionaru/easy-markdown-editor/archive/$ver_mde.tar.gz -O mde.tgz \
@ -23,7 +21,6 @@ RUN mkdir -p /z/dist/no-pk \
&& wget https://github.com/FortAwesome/Font-Awesome/releases/download/$ver_fontawesome/fontawesome-free-$ver_fontawesome-web.zip -O fontawesome.zip \
&& wget https://github.com/google/zopfli/archive/zopfli-$ver_zopfli.tar.gz -O zopfli.tgz \
&& wget https://github.com/Daninet/hash-wasm/releases/download/v$ver_hashwasm/hash-wasm@$ver_hashwasm.zip -O hash-wasm.zip \
&& unzip ogvjs.zip \
&& (mkdir hash-wasm \
&& cd hash-wasm \
&& unzip ../hash-wasm.zip) \
@ -77,21 +74,6 @@ RUN cd hash-wasm \
&& mv sha512.umd.min.js /z/dist/sha512.hw.js
# build ogvjs
RUN cd ogvjs-$ver_ogvjs \
&& cp -pv \
ogv-worker-audio.js \
ogv-demuxer-ogg-wasm.js \
ogv-demuxer-ogg-wasm.wasm \
ogv-decoder-audio-opus-wasm.js \
ogv-decoder-audio-opus-wasm.wasm \
ogv-decoder-audio-vorbis-wasm.js \
ogv-decoder-audio-vorbis-wasm.wasm \
/z/dist \
&& cp -pv \
ogv-es2017.js /z/dist/ogv.js
# build marked
COPY marked.patch /z/
COPY marked-ln.patch /z/

View file

@ -16,9 +16,6 @@ help() { exec cat <<'EOF'
#
# `no-sh` makes just the python sfx, skips the sh/unix sfx
#
# `no-ogv` saves ~192k by removing the opus/vorbis audio codecs
# (only affects apple devices; everything else has native support)
#
# `no-cm` saves ~82k by removing easymde/codemirror
# (the fancy markdown editor)
#
@ -75,7 +72,6 @@ while [ ! -z "$1" ]; do
clean) clean=1 ; ;;
re) repack=1 ; ;;
gz) use_gz=1 ; ;;
no-ogv) no_ogv=1 ; ;;
no-fnt) no_fnt=1 ; ;;
no-hl) no_hl=1 ; ;;
no-dd) no_dd=1 ; ;;
@ -218,9 +214,6 @@ cat have | while IFS= read -r x; do
done
rm have
[ $no_ogv ] &&
rm -rf copyparty/web/deps/{dynamicaudio,ogv}*
[ $no_cm ] && {
rm -rf copyparty/web/mde.* copyparty/web/deps/easymde*
echo h > copyparty/web/mde.html

View file

@ -49,14 +49,6 @@ copyparty/web/deps/easymde.js,
copyparty/web/deps/marked.js,
copyparty/web/deps/mini-fa.css,
copyparty/web/deps/mini-fa.woff,
copyparty/web/deps/ogv-decoder-audio-opus-wasm.js,
copyparty/web/deps/ogv-decoder-audio-opus-wasm.wasm,
copyparty/web/deps/ogv-decoder-audio-vorbis-wasm.js,
copyparty/web/deps/ogv-decoder-audio-vorbis-wasm.wasm,
copyparty/web/deps/ogv-demuxer-ogg-wasm.js,
copyparty/web/deps/ogv-demuxer-ogg-wasm.wasm,
copyparty/web/deps/ogv-worker-audio.js,
copyparty/web/deps/ogv.js,
copyparty/web/deps/prism.js,
copyparty/web/deps/prism.css,
copyparty/web/deps/prismd.css,