first commit
This commit is contained in:
commit
c30064b531
93 files changed
+26367
No files matched your search
@@ -0,0 +1,193 @@
|
||||
/* simply-dvb – UI translation engine.
|
||||
* The UI source text is English and doubles as the translation key (gettext style).
|
||||
* Language packs live in langs/<locale>.json ({meta, translations, patterns}); build.rs
|
||||
* validates them and embeds them in the bundle as window.SDVB_LANGS. When a language other
|
||||
* than English is active, every text node inserted into the DOM (and placeholder/title/
|
||||
* aria-label) is translated; missing entries fall back to the English source text.
|
||||
* Pattern replacements use $1..$9 for raw groups and $t1..$t9 for groups translated again. */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var LANG_KEY = 'sdvb-lang';
|
||||
var DEFAULT = 'en_US';
|
||||
var LANGS = {};
|
||||
(window.SDVB_LANGS || []).forEach(function (p) {
|
||||
var code = p.meta.locale;
|
||||
LANGS[code] = {
|
||||
name: p.meta.native_name || p.meta.name || code,
|
||||
english: p.meta.name || code,
|
||||
dir: p.meta.direction || 'ltr',
|
||||
dict: p.translations || {},
|
||||
rx: (p.patterns || []).map(function (x) { return [new RegExp(x.match), x.replace]; })
|
||||
};
|
||||
});
|
||||
if (!LANGS[DEFAULT]) LANGS[DEFAULT] = { name: 'English', english: 'English', dir: 'ltr', dict: {}, rx: [] };
|
||||
|
||||
/** Resolves a stored or requested code ("pl", "pl-PL", "pl_PL") to an available locale. */
|
||||
function resolve(code) {
|
||||
if (!code) return null;
|
||||
var c = String(code).replace('-', '_');
|
||||
if (LANGS[c]) return c;
|
||||
var base = c.split('_')[0].toLowerCase();
|
||||
var keys = Object.keys(LANGS);
|
||||
for (var i = 0; i < keys.length; i++) if (keys[i].split('_')[0].toLowerCase() === base) return keys[i];
|
||||
return null;
|
||||
}
|
||||
|
||||
var saved = null;
|
||||
try { saved = localStorage.getItem(LANG_KEY); } catch (e) {}
|
||||
var lang = resolve(saved) || DEFAULT;
|
||||
var active = lang !== DEFAULT;
|
||||
|
||||
function expand(tpl, m) {
|
||||
return tpl.replace(/\$(t?)(\d)/g, function (_, t, n) {
|
||||
var g = m[+n] == null ? '' : m[+n];
|
||||
return t ? tr(g) : g;
|
||||
});
|
||||
}
|
||||
|
||||
function lookup(k) {
|
||||
var L = LANGS[lang];
|
||||
if (Object.prototype.hasOwnProperty.call(L.dict, k)) return L.dict[k];
|
||||
for (var i = 0; i < L.rx.length; i++) {
|
||||
var m = L.rx[i][0].exec(k);
|
||||
if (m) return expand(L.rx[i][1], m);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function tr(s) {
|
||||
if (!active || s == null) return s;
|
||||
var str = String(s);
|
||||
var k = str.trim();
|
||||
if (!k) return str;
|
||||
var v = lookup(k);
|
||||
if (v === undefined || v === '') return str;
|
||||
return str.replace(k, function () { return v; });
|
||||
}
|
||||
|
||||
var SKIP = { SCRIPT: 1, STYLE: 1, CODE: 1, TEXTAREA: 1 };
|
||||
var ATTRS = ['placeholder', 'title', 'aria-label'];
|
||||
|
||||
function translateTree(root) {
|
||||
if (!active || !root) return;
|
||||
if (root.nodeType === 3) {
|
||||
var p = root.parentNode;
|
||||
if (p && !SKIP[p.nodeName]) { var n = tr(root.nodeValue); if (n !== root.nodeValue) root.nodeValue = n; }
|
||||
return;
|
||||
}
|
||||
if (root.nodeType !== 1 || SKIP[root.nodeName] || (root.hasAttribute && root.hasAttribute('data-no-i18n'))) return;
|
||||
var els = [root].concat(Array.prototype.slice.call(root.querySelectorAll('[placeholder],[title],[aria-label]')));
|
||||
els.forEach(function (el) {
|
||||
ATTRS.forEach(function (a) {
|
||||
if (el.hasAttribute(a)) { var v = el.getAttribute(a), n = tr(v); if (n !== v) el.setAttribute(a, n); }
|
||||
});
|
||||
});
|
||||
var w = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
|
||||
acceptNode: function (node) {
|
||||
for (var e = node.parentNode; e && e !== root.parentNode; e = e.parentNode) {
|
||||
if (SKIP[e.nodeName] || (e.hasAttribute && e.hasAttribute('data-no-i18n'))) return NodeFilter.FILTER_REJECT;
|
||||
}
|
||||
return NodeFilter.FILTER_ACCEPT;
|
||||
}
|
||||
});
|
||||
var node;
|
||||
while ((node = w.nextNode())) {
|
||||
var nv = tr(node.nodeValue);
|
||||
if (nv !== node.nodeValue) node.nodeValue = nv;
|
||||
}
|
||||
}
|
||||
|
||||
function boot() {
|
||||
document.documentElement.lang = lang.replace('_', '-');
|
||||
document.documentElement.dir = LANGS[lang].dir;
|
||||
if (!active) return;
|
||||
translateTree(document.body);
|
||||
new MutationObserver(function (list) {
|
||||
list.forEach(function (m) {
|
||||
if (m.type === 'attributes') { translateTree(m.target); return; }
|
||||
m.addedNodes.forEach(translateTree);
|
||||
});
|
||||
}).observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ATTRS });
|
||||
}
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot);
|
||||
else Promise.resolve().then(boot);
|
||||
|
||||
window.I18N = {
|
||||
get lang() { return lang; },
|
||||
/** Short UI code of the active language, e.g. "EN". */
|
||||
get short() { return lang.split('_')[0].toUpperCase(); },
|
||||
tr: tr,
|
||||
/** Available languages: [{code, short, name, english}], English first, then by name. */
|
||||
languages: function () {
|
||||
return Object.keys(LANGS).sort(function (a, b) {
|
||||
return (a === DEFAULT ? -1 : b === DEFAULT ? 1 : 0) || LANGS[a].english.localeCompare(LANGS[b].english);
|
||||
}).map(function (c) {
|
||||
return { code: c, short: c.split('_')[0].toUpperCase(), name: LANGS[c].name, english: LANGS[c].english };
|
||||
});
|
||||
},
|
||||
setLang: function (l) {
|
||||
try { localStorage.setItem(LANG_KEY, resolve(l) || DEFAULT); } catch (e) {}
|
||||
location.reload();
|
||||
},
|
||||
/** For tooling: English keys with no translation in the given language. */
|
||||
missing: function (code) {
|
||||
var c = resolve(code) || code, d = (LANGS[c] || {}).dict || {}, en = LANGS[DEFAULT].dict;
|
||||
return Object.keys(en).filter(function (k) { return !Object.prototype.hasOwnProperty.call(d, k); });
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
/* UI personalization (stored in localStorage, applied before the first render). */
|
||||
(function () {
|
||||
'use strict';
|
||||
var KEY = 'sdvb-prefs';
|
||||
var DEFAULTS = { chartWindow: 10, theme: 'dark', accent: 'orange', density: 'comfortable', scale: 100, sidebar: 'hover', start: 'overview',
|
||||
logos: true, progress: true, autoplay: false, epgZoom: 4, clock: false, motion: true };
|
||||
var ACCENTS = {
|
||||
orange: ['#f69b74', '#ffb090', '#221810', '#b85b38'],
|
||||
green: ['#bdd293', '#d3e6ad', '#1b2410', '#5f783f'],
|
||||
blue: ['#8ebcff', '#b0d0ff', '#0c1a2e', '#2d6bc4'],
|
||||
violet: ['#c5a3ff', '#d8c0ff', '#1d1230', '#7a4fc4'],
|
||||
red: ['#ff8a80', '#ffaaa2', '#2b0f0c', '#b64a43'],
|
||||
teal: ['#6fd6c6', '#94e6d9', '#0c2420', '#1f8a7a'],
|
||||
amber: ['#f2c14e', '#f7d47e', '#2a2008', '#9a6a00']
|
||||
};
|
||||
var prefs = {};
|
||||
function load() {
|
||||
var p = {};
|
||||
try { p = JSON.parse(localStorage.getItem(KEY) || '{}') || {}; } catch (e) {}
|
||||
prefs = {};
|
||||
Object.keys(DEFAULTS).forEach(function (k) { prefs[k] = p[k] === undefined ? DEFAULTS[k] : p[k]; });
|
||||
}
|
||||
var mq = window.matchMedia ? window.matchMedia('(prefers-color-scheme: light)') : null;
|
||||
function apply() {
|
||||
var html = document.documentElement;
|
||||
var theme = prefs.theme === 'system' ? (mq && mq.matches ? 'light' : 'dark') : prefs.theme;
|
||||
html.dataset.theme = theme;
|
||||
html.dataset.density = prefs.density;
|
||||
html.dataset.sidebar = prefs.sidebar;
|
||||
html.dataset.motion = prefs.motion ? 'on' : 'off';
|
||||
var a = ACCENTS[prefs.accent] || ACCENTS.orange;
|
||||
var light = theme === 'light';
|
||||
html.style.setProperty('--accent', light ? a[3] : a[0]);
|
||||
html.style.setProperty('--accent-hover', light ? a[3] : a[1]);
|
||||
html.style.setProperty('--accent-ink', light ? '#fff' : a[2]);
|
||||
html.style.zoom = prefs.scale && prefs.scale !== 100 ? (prefs.scale / 100) : '';
|
||||
}
|
||||
load();
|
||||
apply();
|
||||
if (mq && mq.addEventListener) mq.addEventListener('change', function () { if (prefs.theme === 'system') apply(); });
|
||||
window.SDVB_PREFS = {
|
||||
get: function (k) { return prefs[k]; },
|
||||
all: function () { return JSON.parse(JSON.stringify(prefs)); },
|
||||
set: function (k, v) {
|
||||
prefs[k] = v;
|
||||
try { localStorage.setItem(KEY, JSON.stringify(prefs)); } catch (e) {}
|
||||
apply();
|
||||
},
|
||||
reset: function () { try { localStorage.removeItem(KEY); } catch (e) {} load(); apply(); },
|
||||
accents: Object.keys(ACCENTS),
|
||||
accentColor: function (k) { return (ACCENTS[k] || ACCENTS.orange)[0]; }
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,230 @@
|
||||
/* simply-dvb – HLS player (hls.js / native HLS in Safari) with automatic profile selection */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var CODECS = {
|
||||
'H.264': 'video/mp4; codecs="avc1.640028"',
|
||||
'HEVC': ['video/mp4; codecs="hvc1.1.6.L120.90"', 'video/mp4; codecs="hvc1.1.6.L123.B0"', 'video/mp4; codecs="hev1.1.6.L120.90"', 'video/mp4; codecs="hvc1.2.4.L120.90"'],
|
||||
'MPEG-2': null,
|
||||
'AAC': 'audio/mp4; codecs="mp4a.40.2"',
|
||||
'MP2': 'audio/mpeg',
|
||||
'AC-3': 'audio/mp4; codecs="ac-3"',
|
||||
'E-AC-3': 'audio/mp4; codecs="ec-3"',
|
||||
'AAC-LATM': null
|
||||
};
|
||||
|
||||
function mse() {
|
||||
return window.ManagedMediaSource || window.MediaSource;
|
||||
}
|
||||
|
||||
function supported(label) {
|
||||
if (!label) return true;
|
||||
var c = CODECS[label];
|
||||
if (c === undefined) return true;
|
||||
if (c === null) return false;
|
||||
var M = mse();
|
||||
if (!M || !M.isTypeSupported) return false;
|
||||
var list = Array.isArray(c) ? c : [c];
|
||||
for (var i = 0; i < list.length; i++) if (M.isTypeSupported(list[i])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function list(x) { return Array.isArray(x) ? x : (x ? [x] : []); }
|
||||
/** Codec label without the language suffix, e.g. "MP2 (pol)" -> "MP2". */
|
||||
function codec(label) { return String(label || '').replace(/ \(.*\)$/, ''); }
|
||||
/** True when at least one of the audio tracks can be decoded (or there is no audio info). */
|
||||
function audioOk(audio) {
|
||||
var a = list(audio).map(codec);
|
||||
return !a.length || a.some(supported);
|
||||
}
|
||||
|
||||
/**
|
||||
* Best profile for this browser: pass → aac → h264. Without ffmpeg on the server only
|
||||
* "pass" is possible, so it is always tried first.
|
||||
*/
|
||||
function pickProfile(video, audio, transcode) {
|
||||
if (transcode === false) return 'pass';
|
||||
if (!supported(codec(video))) return 'h264';
|
||||
if (!audioOk(audio)) return 'aac';
|
||||
return 'pass';
|
||||
}
|
||||
|
||||
function tr(x) { return window.I18N ? window.I18N.tr(x) : x; }
|
||||
|
||||
/** Human-readable (translated) explanation why the original stream cannot be decoded here. */
|
||||
function explain(video, audio) {
|
||||
var parts = [];
|
||||
var v = codec(video);
|
||||
if (v && !supported(v)) {
|
||||
parts.push(tr(v === 'HEVC'
|
||||
? 'This browser reports no HEVC (H.265) support. Chrome/Edge decode it only with hardware acceleration (on Linux: VA-API); Safari plays it natively.'
|
||||
: 'This browser reports no support for ' + v + ' video.'));
|
||||
}
|
||||
if (!audioOk(audio)) parts.push(tr('This browser reports no support for any audio track (' + list(audio).map(codec).join(', ') + ').'));
|
||||
return parts.join(' ');
|
||||
}
|
||||
|
||||
function el(tag, cls, text) {
|
||||
var e = document.createElement(tag);
|
||||
if (cls) e.className = cls;
|
||||
if (text != null) e.textContent = text;
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* opts: { channelId, share, token, video, audio, profile ('auto'|'pass'|'aac'|'h264'), src (full playlist URL), live, onProfile }
|
||||
*/
|
||||
function create(container, opts) {
|
||||
container.innerHTML = '';
|
||||
var video = el('video');
|
||||
video.controls = true;
|
||||
video.playsInline = true;
|
||||
video.autoplay = true;
|
||||
var overlay = el('div', 'overlay');
|
||||
var badge = el('div', 'badge', opts.live === false ? 'RECORDING' : 'LIVE');
|
||||
container.appendChild(video);
|
||||
container.appendChild(overlay);
|
||||
container.appendChild(badge);
|
||||
var hls = null;
|
||||
var destroyed = false;
|
||||
var fallbackOrder = opts.transcode === false ? ['pass'] : ['pass', 'aac', 'h264'];
|
||||
var profile = opts.profile && opts.profile !== 'auto' ? opts.profile : pickProfile(opts.video, opts.audio, opts.transcode);
|
||||
var auto = !opts.profile || opts.profile === 'auto';
|
||||
var retries = 0;
|
||||
|
||||
function status(msg, err, hint) {
|
||||
overlay.innerHTML = '';
|
||||
if (!msg) { overlay.classList.add('hidden'); return; }
|
||||
overlay.classList.remove('hidden');
|
||||
overlay.classList.toggle('err', !!err);
|
||||
if (!err) overlay.appendChild(el('div', 'spinner'));
|
||||
overlay.appendChild(el('div', null, msg));
|
||||
if (hint) overlay.appendChild(el('div', 'hint', hint));
|
||||
if (err && opts.vlcUrl) {
|
||||
var a = el('a', 'btn small', '▶ Open in VLC');
|
||||
a.href = opts.vlcUrl;
|
||||
a.setAttribute('download', '');
|
||||
overlay.appendChild(a);
|
||||
}
|
||||
}
|
||||
/** Final failure: explain codecs and what can be done. */
|
||||
function failed(msg) {
|
||||
var why = explain(opts.video, opts.audio);
|
||||
var hint = why;
|
||||
if (opts.transcode === false) hint = (why ? why + ' ' : '') + tr('Install ffmpeg on the server to enable transcoding, or open the channel in VLC.');
|
||||
status(tr('Could not play: ' + msg), true, hint);
|
||||
}
|
||||
|
||||
function url() {
|
||||
if (opts.src) return opts.src;
|
||||
var q = [];
|
||||
if (profile !== 'pass') q.push('profile=' + profile);
|
||||
if (opts.share) q.push('share=' + encodeURIComponent(opts.share));
|
||||
if (opts.token) q.push('token=' + encodeURIComponent(opts.token));
|
||||
return '/hls/' + opts.channelId + '/index.m3u8' + (q.length ? '?' + q.join('&') : '');
|
||||
}
|
||||
|
||||
function nextProfile() {
|
||||
if (!auto || opts.src) return false;
|
||||
var i = fallbackOrder.indexOf(profile);
|
||||
if (i < 0 || i + 1 >= fallbackOrder.length) return false;
|
||||
profile = fallbackOrder[i + 1];
|
||||
return true;
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
if (hls) { try { hls.destroy(); } catch (e) {} hls = null; }
|
||||
video.removeAttribute('src');
|
||||
try { video.load(); } catch (e) {}
|
||||
}
|
||||
|
||||
function start() {
|
||||
teardown();
|
||||
if (destroyed) return;
|
||||
if (opts.onProfile) opts.onProfile(profile);
|
||||
status(opts.live === false ? 'Loading recording…' : 'Tuning and buffering…');
|
||||
var src = url();
|
||||
if (window.Hls && window.Hls.isSupported()) {
|
||||
hls = new window.Hls({
|
||||
liveSyncDurationCount: 2,
|
||||
liveMaxLatencyDurationCount: 6,
|
||||
manifestLoadingTimeOut: 30000,
|
||||
manifestLoadingMaxRetry: 3,
|
||||
levelLoadingTimeOut: 20000,
|
||||
fragLoadingTimeOut: 30000,
|
||||
enableWorker: true,
|
||||
backBufferLength: 30
|
||||
});
|
||||
hls.on(window.Hls.Events.MANIFEST_PARSED, function () {
|
||||
var p = video.play();
|
||||
if (p && p.catch) p.catch(function () { status('Click ▶ to play', true); });
|
||||
});
|
||||
hls.on(window.Hls.Events.FRAG_BUFFERED, function () { status(null); retries = 0; });
|
||||
hls.on(window.Hls.Events.ERROR, function (_e, data) {
|
||||
if (!data.fatal) return;
|
||||
var codecProblem = data.type === window.Hls.ErrorTypes.MEDIA_ERROR ||
|
||||
/codec|incompatible|bufferAddCodec|addSourceBuffer/i.test(String(data.details) + ' ' + String(data.reason || ''));
|
||||
if (codecProblem && nextProfile()) {
|
||||
status('Browser lacks the codec – switching to the “' + profile + '” profile…');
|
||||
setTimeout(start, 300);
|
||||
return;
|
||||
}
|
||||
if (data.type === window.Hls.ErrorTypes.MEDIA_ERROR && retries < 2) {
|
||||
retries++;
|
||||
hls.recoverMediaError();
|
||||
return;
|
||||
}
|
||||
if (data.type === window.Hls.ErrorTypes.NETWORK_ERROR && retries < 4) {
|
||||
retries++;
|
||||
status('Connection problem – retrying (' + retries + ')…');
|
||||
setTimeout(start, 2000);
|
||||
return;
|
||||
}
|
||||
var msg = (data.response && data.response.data) || data.details || 'playback error';
|
||||
failed(String(msg));
|
||||
});
|
||||
hls.loadSource(src);
|
||||
hls.attachMedia(video);
|
||||
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
video.src = src;
|
||||
video.addEventListener('playing', function () { status(null); }, { once: true });
|
||||
video.addEventListener('error', function () {
|
||||
if (nextProfile()) { start(); return; }
|
||||
failed('the stream');
|
||||
}, { once: true });
|
||||
var p = video.play();
|
||||
if (p && p.catch) p.catch(function () {});
|
||||
} else {
|
||||
status('This browser does not support HLS', true);
|
||||
}
|
||||
}
|
||||
|
||||
video.addEventListener('waiting', function () { if (!overlay.classList.contains('err')) status('Buffering…'); });
|
||||
video.addEventListener('playing', function () { status(null); });
|
||||
start();
|
||||
|
||||
return {
|
||||
video: video,
|
||||
get profile() { return profile; },
|
||||
setProfile: function (p) { auto = p === 'auto'; profile = auto ? pickProfile(opts.video, opts.audio) : p; start(); },
|
||||
destroy: function () { destroyed = true; teardown(); container.innerHTML = ''; }
|
||||
};
|
||||
}
|
||||
|
||||
window.SDVB = { createPlayer: create, pickProfile: pickProfile, codecSupported: supported, explain: explain };
|
||||
|
||||
// Public page /watch/<token>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
if (!document.body.classList.contains('watch')) return;
|
||||
var box = document.getElementById('player');
|
||||
if (!box) return;
|
||||
create(box, {
|
||||
channelId: box.getAttribute('data-channel'),
|
||||
share: box.getAttribute('data-share'),
|
||||
video: box.getAttribute('data-video'),
|
||||
audio: (box.getAttribute('data-audio') || '').split('|').filter(Boolean),
|
||||
transcode: box.getAttribute('data-transcode') !== '0',
|
||||
profile: 'auto'
|
||||
});
|
||||
});
|
||||
})();
|
||||
+1559
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user