1 parent
052a27bc48
commit
528017b0e6
36 files changed
+3394
-216
No files matched your search
+69
-4
@@ -5,6 +5,69 @@
|
||||
* 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. */
|
||||
/* Personal settings store: localStorage on this device, mirrored to the user's profile on
|
||||
* the server (GET/PUT /api/me/prefs) so language, theme and filters follow the account. */
|
||||
(function () {
|
||||
'use strict';
|
||||
var SYNCED = ['sdvb-lang', 'sdvb-prefs', 'sdvb-chfilter', 'sdvb-group', 'sdvb-fav', 'sdvb-remind'];
|
||||
var enabled = false;
|
||||
function local() {
|
||||
var o = {};
|
||||
SYNCED.forEach(function (k) {
|
||||
var v = null;
|
||||
try { v = localStorage.getItem(k); } catch (e) {}
|
||||
if (v !== null) o[k] = v;
|
||||
});
|
||||
return o;
|
||||
}
|
||||
function push() {
|
||||
if (!enabled) return;
|
||||
try {
|
||||
// keepalive: a language change reloads the page right away
|
||||
fetch('/api/me/prefs', { method: 'PUT', keepalive: true, credentials: 'same-origin',
|
||||
headers: { 'X-Requested-With': 'simply-dvb', 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(local()) }).catch(function () {});
|
||||
} catch (e) {}
|
||||
}
|
||||
window.SDVB_STORE = {
|
||||
get: function (k) { try { return localStorage.getItem(k); } catch (e) { return null; } },
|
||||
set: function (k, v) {
|
||||
try { localStorage.setItem(k, v); } catch (e) {}
|
||||
if (SYNCED.indexOf(k) >= 0) push();
|
||||
},
|
||||
remove: function (k) {
|
||||
try { localStorage.removeItem(k); } catch (e) {}
|
||||
if (SYNCED.indexOf(k) >= 0) push();
|
||||
},
|
||||
/** After login: takes the profile's settings (or uploads this device's ones when the
|
||||
* profile has none yet). Resolves to the list of keys that changed. */
|
||||
pull: function () {
|
||||
return fetch('/api/me/prefs', { credentials: 'same-origin', headers: { 'X-Requested-With': 'simply-dvb' } })
|
||||
.then(function (r) { return r.ok ? r.json() : null; })
|
||||
.then(function (remote) {
|
||||
enabled = true;
|
||||
if (!remote) return [];
|
||||
var keys = Object.keys(remote).filter(function (k) { return SYNCED.indexOf(k) >= 0; });
|
||||
if (!keys.length) { push(); return []; }
|
||||
var changed = [];
|
||||
SYNCED.forEach(function (k) {
|
||||
var cur = null;
|
||||
try { cur = localStorage.getItem(k); } catch (e) {}
|
||||
var nv = Object.prototype.hasOwnProperty.call(remote, k) ? remote[k] : null;
|
||||
if (nv !== cur) {
|
||||
changed.push(k);
|
||||
try { if (nv === null) localStorage.removeItem(k); else localStorage.setItem(k, nv); } catch (e) {}
|
||||
}
|
||||
});
|
||||
return changed;
|
||||
})
|
||||
.catch(function () { enabled = true; return []; });
|
||||
},
|
||||
/** On logout: stop mirroring until the next login. */
|
||||
stop: function () { enabled = false; }
|
||||
};
|
||||
})();
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
@@ -127,7 +190,7 @@
|
||||
});
|
||||
},
|
||||
setLang: function (l) {
|
||||
try { localStorage.setItem(LANG_KEY, resolve(l) || DEFAULT); } catch (e) {}
|
||||
window.SDVB_STORE.set(LANG_KEY, resolve(l) || DEFAULT);
|
||||
location.reload();
|
||||
},
|
||||
/** For tooling: English keys with no translation in the given language. */
|
||||
@@ -142,7 +205,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var KEY = 'sdvb-prefs';
|
||||
var DEFAULTS = { chartWindow: 10, theme: 'dark', accent: 'orange', density: 'comfortable', scale: 100, sidebar: 'hover', start: 'overview',
|
||||
var DEFAULTS = { chartWindow: 10, theme: 'midnight', 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'],
|
||||
@@ -183,10 +246,12 @@
|
||||
all: function () { return JSON.parse(JSON.stringify(prefs)); },
|
||||
set: function (k, v) {
|
||||
prefs[k] = v;
|
||||
try { localStorage.setItem(KEY, JSON.stringify(prefs)); } catch (e) {}
|
||||
window.SDVB_STORE.set(KEY, JSON.stringify(prefs));
|
||||
apply();
|
||||
},
|
||||
reset: function () { try { localStorage.removeItem(KEY); } catch (e) {} load(); apply(); },
|
||||
reset: function () { window.SDVB_STORE.remove(KEY); load(); apply(); },
|
||||
/** Re-reads the stored values (after the profile's settings were pulled). */
|
||||
reload: function () { load(); apply(); },
|
||||
accents: Object.keys(ACCENTS),
|
||||
accentColor: function (k) { return (ACCENTS[k] || ACCENTS.orange)[0]; }
|
||||
};
|
||||
|
||||
+4
-3
@@ -39,7 +39,7 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Best profile for this browser: pass → aac → h264. Without ffmpeg on the server only
|
||||
* Best profile for this browser: pass, then aac, then h264. Without ffmpeg on the server only
|
||||
* "pass" is possible, so it is always tried first.
|
||||
*/
|
||||
function pickProfile(video, audio, transcode) {
|
||||
@@ -101,7 +101,8 @@
|
||||
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');
|
||||
var a = el('a', 'btn small', 'Open in VLC');
|
||||
if (window.SDVB_ICON) a.innerHTML = window.SDVB_ICON('vlc') + a.innerHTML;
|
||||
a.href = opts.vlcUrl;
|
||||
a.setAttribute('download', '');
|
||||
overlay.appendChild(a);
|
||||
@@ -157,7 +158,7 @@
|
||||
});
|
||||
hls.on(window.Hls.Events.MANIFEST_PARSED, function () {
|
||||
var p = video.play();
|
||||
if (p && p.catch) p.catch(function () { status('Click ▶ to play', true); });
|
||||
if (p && p.catch) p.catch(function () { status('Click Play to start', true); });
|
||||
});
|
||||
hls.on(window.Hls.Events.FRAG_BUFFERED, function () { status(null); retries = 0; });
|
||||
hls.on(window.Hls.Events.ERROR, function (_e, data) {
|
||||
|
||||
+439
-55
@@ -47,6 +47,32 @@
|
||||
t.remove();
|
||||
}
|
||||
}
|
||||
/** Line icons (same style as the side menu) – used instead of emoji/special characters. */
|
||||
var ICONS = {
|
||||
play: '<path class="f" d="M7.5 4.8v14.4L19 12z"/>',
|
||||
prev: '<path d="M15 5l-7 7 7 7"/>',
|
||||
next: '<path d="M9 5l7 7-7 7"/>',
|
||||
record: '<circle class="f" cx="12" cy="12" r="6"/>',
|
||||
stop: '<rect class="f" x="6.5" y="6.5" width="11" height="11" rx="1"/>',
|
||||
pip: '<rect x="2.5" y="4.5" width="19" height="15" rx="1.5"/><rect class="f" x="12" y="11.5" width="7" height="5.5" rx=".5"/>',
|
||||
fullscreen: '<path d="M3.5 9V3.5H9M20.5 9V3.5H15M3.5 15v5.5H9M20.5 15v5.5H15"/>',
|
||||
check: '<path d="M4.5 12.5l4.8 4.8L19.5 7"/>',
|
||||
cross: '<path d="M6 6l12 12M18 6L6 18"/>',
|
||||
star: '<path d="M12 3.2l2.7 5.6 6.1.8-4.5 4.2 1.1 6.1L12 17l-5.4 2.9 1.1-6.1-4.5-4.2 6.1-.8z"/>',
|
||||
starOn: '<path class="f" d="M12 3.2l2.7 5.6 6.1.8-4.5 4.2 1.1 6.1L12 17l-5.4 2.9 1.1-6.1-4.5-4.2 6.1-.8z"/>',
|
||||
bell: '<path d="M6 16.5V11a6 6 0 0 1 12 0v5.5l1.8 1.8H4.2z"/><path d="M10 21h4"/>',
|
||||
antenna: '<path d="M5 12.5a10 10 0 0 1 14 0M8.5 16a5 5 0 0 1 7 0M2 9a14.5 14.5 0 0 1 20 0"/><circle class="f" cx="12" cy="19.5" r="1"/>',
|
||||
download: '<path d="M12 3.5v11.5M7 10l5 5 5-5M4 20.5h16"/>',
|
||||
upload: '<path d="M12 15.5V4M7 9l5-5 5 5M4 20.5h16"/>',
|
||||
warn: '<path d="M12 3.5l9.5 17h-19z"/><path d="M12 10v4.5M12 17.5v.2"/>',
|
||||
grip: '<circle class="f" cx="9" cy="6" r="1.3"/><circle class="f" cx="15" cy="6" r="1.3"/><circle class="f" cx="9" cy="12" r="1.3"/><circle class="f" cx="15" cy="12" r="1.3"/><circle class="f" cx="9" cy="18" r="1.3"/><circle class="f" cx="15" cy="18" r="1.3"/>',
|
||||
volume: '<path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z"/><path d="M15.5 9a4 4 0 0 1 0 6M18 6.5a7.5 7.5 0 0 1 0 11"/>',
|
||||
mute: '<path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z"/><path d="M16 9.5l5 5M21 9.5l-5 5"/>',
|
||||
vlc: '<path d="M9 3.5h6l4.5 16h-15z"/><path d="M7.2 13h9.6"/>'
|
||||
};
|
||||
function ico(name) { return '<svg class="i" viewBox="0 0 24 24" aria-hidden="true">' + (ICONS[name] || '') + '</svg>'; }
|
||||
window.SDVB_ICON = ico;
|
||||
|
||||
function toast(msg, err) {
|
||||
var t = document.createElement('div');
|
||||
t.className = 'toast' + (err ? ' err' : '');
|
||||
@@ -116,6 +142,8 @@
|
||||
app.cleanup.push(function () { document.removeEventListener('visibilitychange', onVis); });
|
||||
}
|
||||
function resetPage() {
|
||||
// a dialog belongs to the page it was opened on (e.g. Watch in an EPG event)
|
||||
if (!$('#modal').classList.contains('hidden')) closeModal();
|
||||
app.timers.forEach(clearInterval); app.timers = [];
|
||||
app.cleanup.forEach(function (f) { try { f(); } catch (e) {} }); app.cleanup = [];
|
||||
}
|
||||
@@ -128,6 +156,8 @@
|
||||
channels: ['Channels', pageChannels],
|
||||
recordings: ['Recordings', pageRecordings],
|
||||
tuners: ['Tuners & scanning', pageTuners],
|
||||
stats: ['Statistics', pageStats],
|
||||
signal: ['Antenna meter', pageSignal],
|
||||
access: ['Access & sharing', pageAccess],
|
||||
logs: ['Logs', pageLogs],
|
||||
settings: ['Settings', pageSettings]
|
||||
@@ -156,6 +186,10 @@
|
||||
$('#login').classList.remove('hidden');
|
||||
}
|
||||
function boot() {
|
||||
// installable app (PWA); service workers need HTTPS or localhost
|
||||
if ('serviceWorker' in navigator && window.isSecureContext) {
|
||||
navigator.serviceWorker.register('/sw.js').catch(function () {});
|
||||
}
|
||||
renderLangSwitch();
|
||||
applyClock();
|
||||
api('GET', '/api/info').then(function (i) {
|
||||
@@ -165,6 +199,13 @@
|
||||
}).catch(function () {});
|
||||
api('GET', '/api/me').then(function (me) {
|
||||
app.me = me;
|
||||
return window.SDVB_STORE.pull().then(function (changed) {
|
||||
// the profile has another language: reload once with it
|
||||
if (changed.indexOf('sdvb-lang') >= 0) { location.reload(); throw new Error('reload'); }
|
||||
if (changed.length) { window.SDVB_PREFS.reload(); applyClock(); }
|
||||
return me;
|
||||
});
|
||||
}).then(function (me) {
|
||||
$('#who').textContent = me.username + ' · ' + (me.role === 'admin' ? 'administrator' : 'viewer');
|
||||
$('#login').classList.add('hidden');
|
||||
$('#shell').classList.remove('hidden');
|
||||
@@ -174,12 +215,13 @@
|
||||
$('#login-form').addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
var f = e.target;
|
||||
$('#login-error').textContent = '';
|
||||
var le = $('#login-error');
|
||||
le.textContent = ''; le.classList.add('hidden');
|
||||
api('POST', '/api/login', { username: f.username.value, password: f.password.value })
|
||||
.then(function () { f.password.value = ''; boot(); })
|
||||
.catch(function (err) { $('#login-error').textContent = err.message; });
|
||||
.catch(function (err) { var le = $('#login-error'); var m = T(err.message); le.textContent = m.charAt(0).toUpperCase() + m.slice(1); le.classList.remove('hidden'); });
|
||||
});
|
||||
$('#logout').addEventListener('click', function () { api('POST', '/api/logout').then(showLogin).catch(showLogin); });
|
||||
$('#logout').addEventListener('click', function () { window.SDVB_STORE.stop(); api('POST', '/api/logout').then(showLogin).catch(showLogin); });
|
||||
var THEMES = ['dark', 'midnight', 'light', 'system'];
|
||||
$('#theme-toggle').addEventListener('click', function () {
|
||||
var i = THEMES.indexOf(P.get('theme'));
|
||||
@@ -190,7 +232,8 @@
|
||||
/** Language picker built from the packs embedded at build time (langs/*.json). */
|
||||
function langSelect(id, short) {
|
||||
return '<select class="lang-select" id="' + id + '" data-no-i18n title="Language">' + window.I18N.languages().map(function (l) {
|
||||
var label = short ? l.short + ' · ' + l.name : l.name + (l.name !== l.english ? ' (' + l.english + ')' : '');
|
||||
var phone = window.matchMedia && window.matchMedia('(max-width: 640px)').matches;
|
||||
var label = short ? (phone ? l.short : l.short + ' · ' + l.name) : l.name + (l.name !== l.english ? ' (' + l.english + ')' : '');
|
||||
return '<option value="' + esc(l.code) + '"' + (l.code === window.I18N.lang ? ' selected' : '') + '>' + esc(label) + '</option>';
|
||||
}).join('') + '</select>';
|
||||
}
|
||||
@@ -229,6 +272,7 @@
|
||||
if (unit === 'dB') return v.toFixed(1) + ' dB';
|
||||
if (unit === 'dBm') return v.toFixed(1) + ' dBm';
|
||||
if (unit === 'bps') return bps(v);
|
||||
if (unit === 'ber') return v === 0 ? '0' : v.toExponential(1);
|
||||
return (Math.round(v * 100) / 100) + (unit ? ' ' + unit : '');
|
||||
}
|
||||
/**
|
||||
@@ -274,9 +318,9 @@
|
||||
var area = si === 0 && !opts.noArea && first != null ? '<path class="area" style="fill:' + color + '" d="' + d + ' L' + x(last).toFixed(1) + ',' + (H - 4) + ' L' + x(first).toFixed(1) + ',' + (H - 4) + ' Z"/>' : '';
|
||||
return area + '<path class="ln" style="stroke:' + color + '" d="' + d + '"/>';
|
||||
}).join('');
|
||||
return '<svg class="chart" viewBox="0 0 ' + W + ' ' + H + '" preserveAspectRatio="none">' + grid + paths +
|
||||
return '<div class="chart-box"><svg class="chart" viewBox="0 0 ' + W + ' ' + H + '" preserveAspectRatio="none">' + grid + paths +
|
||||
'<line class="cursor hidden" x1="0" x2="0" y1="0" y2="' + H + '"/></svg>' +
|
||||
'<div class="chart-scale"><span>' + esc(fmtNum(max, opts.unit)) + '</span><span>' + esc(fmtNum(min, opts.unit)) + '</span></div>';
|
||||
'<div class="chart-scale"><span>' + esc(fmtNum(max, opts.unit)) + '</span><span>' + esc(fmtNum(min, opts.unit)) + '</span></div></div>';
|
||||
}
|
||||
/** A chart panel: title, current values and the chart; hovering shows the value at that time. */
|
||||
function chartCard(id, title, series, times, opts) {
|
||||
@@ -321,10 +365,45 @@
|
||||
'<div class="small muted mono">' + (sig.locked ? 'LOCK' : sig.has_signal ? 'signal, no lock' : 'no signal') + '</div></div></div>';
|
||||
}
|
||||
|
||||
/** Demodulator lock stages: signal, carrier, FEC, sync, lock. */
|
||||
function lockBits(sig) {
|
||||
if (!sig) return '';
|
||||
return '<div class="lock-bits">' + [['SIGNAL', sig.has_signal], ['CARRIER', sig.has_carrier], ['FEC', sig.has_viterbi], ['SYNC', sig.has_sync], ['LOCK', sig.locked]].map(function (b) {
|
||||
return '<span class="pill ' + (b[1] ? 'ok' : '') + '">' + b[0] + '</span>';
|
||||
}).join('') + (sig.ber != null ? '<span class="mono small muted">BER ' + esc(fmtNum(sig.ber, 'ber')) + '</span>' : '') + '</div>';
|
||||
}
|
||||
/** Transport stream health since tuning (lost packets, damaged packets, stuffing). */
|
||||
function tsHealth(a) {
|
||||
var ts = a.ts, tu = a.tuned;
|
||||
if (!ts || !ts.packets) return '';
|
||||
var pct = function (n) { return (n * 100 / ts.packets).toFixed(n * 100 / ts.packets < 1 ? 2 : 1) + '%'; };
|
||||
return '<div class="kv ts-kv">' +
|
||||
(tu ? '<span>Transmission</span><span class="mono">' + esc([tu.modulation, tu.code_rate && 'FEC ' + tu.code_rate, tu.guard_interval && 'GI ' + tu.guard_interval, tu.transmission_mode].filter(Boolean).join(' · ')) + '</span>' : '') +
|
||||
'<span>Packets</span><span class="mono">' + ts.packets.toLocaleString() + ' · ' + ts.pids + ' PIDs · ' + esc(T('stuffing')) + ' ' + pct(ts.null_packets) + (ts.scrambled ? ' · ' + esc(T('scrambled')) + ' ' + pct(ts.scrambled) : '') + '</span>' +
|
||||
'<span>Errors</span><span class="mono ' + (ts.cc_errors || ts.tei_errors ? 'warn-text' : '') + '">CC ' + ts.cc_errors + ' · TEI ' + ts.tei_errors + '</span></div>';
|
||||
}
|
||||
/** Adapter hardware: bus, driver, product, ids, frequency range, capabilities. */
|
||||
function hardwareBlock(t) {
|
||||
var d = t.device;
|
||||
if (!d) return '';
|
||||
var rows = [
|
||||
['Bus', [d.bus && d.bus.toUpperCase(), d.usb_speed && d.usb_speed + ' Mbit/s'].filter(Boolean).join(' · ')],
|
||||
['Driver', d.driver],
|
||||
['Device', [d.vendor, d.product].filter(Boolean).join(' ')],
|
||||
['IDs', d.ids],
|
||||
['Frequency range', d.freq_min_mhz != null && d.freq_max_mhz != null ? d.freq_min_mhz.toFixed(0) + '–' + d.freq_max_mhz.toFixed(0) + ' MHz' : ''],
|
||||
['Capabilities', (d.caps || []).join(', ')]
|
||||
].filter(function (r) { return r[1]; });
|
||||
if (!rows.length) return '';
|
||||
return '<details class="hw" data-hw="' + esc(t.id) + '"><summary>' + esc(T('Hardware')) + '</summary><div class="kv">' + rows.map(function (r) {
|
||||
return '<span>' + esc(T(r[0])) + '</span><span class="mono">' + esc(r[1]) + '</span>';
|
||||
}).join('') + '</div></details>';
|
||||
}
|
||||
|
||||
function pageOverview(view) {
|
||||
var windowMin = +P.get('chartWindow') || 10;
|
||||
view.innerHTML = head('Connected to server', 'Television, in focus.', 'Tuners, streams, clients and EPG in one place.',
|
||||
'<a class="btn" href="#/tv">▶ Watch</a><a class="btn" href="#/tuners">Scan channels</a>') +
|
||||
'<a class="btn" href="#/tv">' + ico('play') + 'Watch</a><a class="btn" href="#/tuners">Scan channels</a>') +
|
||||
'<div class="grid g4" id="ov-stats"></div>' +
|
||||
'<div class="section-head"><h2>Live</h2><div class="seg" id="ov-window">' + [5, 10, 15].map(function (m) {
|
||||
return '<button data-w="' + m + '"' + (m === windowMin ? ' class="on"' : '') + '>' + m + ' min</button>';
|
||||
@@ -357,7 +436,7 @@
|
||||
add('mem', 'Memory', [{ name: 'used', values: pick(S, 'mem') }], { unit: '%', min: 0, max: 100 });
|
||||
add('rss', 'Process memory (RSS)', [{ name: 'RSS', values: pick(S, 'rss') }], { unit: 'B', min: 0 });
|
||||
add('stream', 'Streaming throughput', [{ name: 'to clients', values: pick(S, 'out_bps') }, { name: 'recordings', values: pick(S, 'rec_bps') }], { unit: 'Bps', min: 0, floor: 1000 });
|
||||
add('net', 'Network', [{ name: 'out', values: pick(S, 'net_tx') }, { name: 'in', values: pick(S, 'net_rx') }], { unit: 'Bps', min: 0, floor: 1000 });
|
||||
add('net', 'Application traffic', [{ name: 'MPEG-TS', values: pick(S, 'out_ts_bps') }, { name: 'HLS', values: pick(S, 'out_hls_bps') }, { name: 'HTSP', values: pick(S, 'out_htsp_bps') }, { name: 'from tuners', values: pick(S, 'tuner_in_bps') }], { unit: 'Bps', min: 0, floor: 1000, noArea: true });
|
||||
add('clients', 'Clients & sessions', [{ name: 'clients', values: pick(S, 'clients') }, { name: 'HLS sessions', values: pick(S, 'hls_sessions') }, { name: 'active tuners', values: pick(S, 'tuners_active') }], { min: 0, floor: 2, noArea: true });
|
||||
add('temp', 'Temperature', [{ name: 'max', values: pick(S, 'temp') }], { unit: '°C', auto: true });
|
||||
add('load', 'Load average (1 min)', [{ name: 'load', values: pick(S, 'load1') }], { min: 0, floor: 1 });
|
||||
@@ -368,6 +447,8 @@
|
||||
function renderTuners() {
|
||||
if (!status) return;
|
||||
var tdata = {};
|
||||
// keep the "Hardware" sections the user opened across the 2 s refreshes
|
||||
var openHw = $$('details.hw[open]', $('#ov-tuners')).map(function (d) { return d.getAttribute('data-hw'); });
|
||||
$('#ov-tuners').className = 'grid ' + (status.tuners.length > 1 ? 'g2' : 'g1');
|
||||
$('#ov-tuners').innerHTML = status.tuners.map(function (t) {
|
||||
var a = t.active;
|
||||
@@ -384,16 +465,20 @@
|
||||
add('dbm', 'Signal level', [{ name: 'dBm', values: pick(TS, 'strength_dbm') }], { unit: 'dBm', auto: true, noArea: true });
|
||||
add('snr', 'SNR', [{ name: 'SNR', values: pick(TS, 'snr') }], { unit: 'dB', min: 0, floor: 10 });
|
||||
add('unc', 'Uncorrected blocks', [{ name: 'per 2 s', values: pick(TS, 'unc') }], { min: 0, floor: 1, bars: true });
|
||||
add('ber', 'Bit error rate (BER)', [{ name: 'BER', values: pick(TS, 'ber') }], { unit: 'ber', min: 0, floor: 1e-6, noArea: true });
|
||||
add('tserr', 'Stream errors', [{ name: 'CC', values: pick(TS, 'cc') }, { name: 'TEI', values: pick(TS, 'tei') }], { min: 0, floor: 1, bars: true });
|
||||
return '<div class="panel tuner"><div class="t-head"><div><h3>' + esc(t.name) + '</h3><div class="t-meta">' + esc(t.id) + ' · ' + esc(t.delivery_systems.join(' / ')) + ' · ' + esc(t.path) + '</div></div>' +
|
||||
'<div class="actions">' + (!t.enabled ? '<span class="pill">disabled</span>' : t.busy ? '<span class="pill warn">scanning</span>' :
|
||||
a ? '<span class="pill ' + (a.state === 'locked' ? 'ok' : a.state === 'tuning' ? 'warn' : 'err') + '">' + esc(a.state === 'locked' ? 'LOCK' : a.state) + '</span>' : '<span class="pill">idle</span>') + '</div></div>' +
|
||||
(a ? '<div class="kv"><span>Mux</span><span>' + esc(a.tuning) + (a.network_name ? ' · ' + esc(a.network_name) : '') + '</span>' +
|
||||
'<span>Clients</span><span>' + a.subscribers + (a.top_priority ? ' · priority ' + esc(a.top_priority) : '') + '</span>' +
|
||||
'<span>Stream</span><span class="mono">' + bps(a.bitrate_bps) + ' · ' + dur(a.uptime_secs) + '</span></div>' + signalBlock(a.signal)
|
||||
'<span>Stream</span><span class="mono">' + bps(a.bitrate_bps) + ' · ' + dur(a.uptime_secs) + (a.pid_filtered ? ' · <span title="' + esc(T('Only the PIDs that clients need are read from the tuner – less CPU. The bitrate covers just these PIDs.')) + '">' + esc(T('PID filter')) + '</span>' : '') + '</span></div>' + signalBlock(a.signal) + lockBits(a.signal) + tsHealth(a)
|
||||
: '<div class="muted small">' + (t.last_error ? 'Last error: ' + esc(t.last_error) : 'Tuner is waiting for clients.') + '</div>') +
|
||||
hardwareBlock(t) +
|
||||
(charts ? '<div class="grid ' + (status.tuners.length > 1 ? 'g2' : 'g4') + ' tuner-charts">' + charts + '</div>' : '') +
|
||||
'</div>';
|
||||
}).join('') || '<div class="panel"><div class="empty">No DVB adapters detected. Check /dev/dvb and permissions (group <code>video</code>).</div></div>';
|
||||
openHw.forEach(function (id) { var d = $('details.hw[data-hw="' + id + '"]', $('#ov-tuners')); if (d) d.open = true; });
|
||||
bindChartHover($('#ov-tuners'), tdata);
|
||||
}
|
||||
function renderStatus(s) {
|
||||
@@ -431,6 +516,18 @@
|
||||
|
||||
// ------------------------------------------------------------ TV
|
||||
function loadChannels() { return api('GET', '/api/channels'); }
|
||||
/** Favourite channels (ids), kept in the user's profile. */
|
||||
var FAV = {
|
||||
list: function () { try { var v = JSON.parse(SDVB_STORE.get('sdvb-fav') || '[]'); return Array.isArray(v) ? v : []; } catch (e) { return []; } },
|
||||
has: function (id) { return FAV.list().indexOf(id) >= 0; },
|
||||
toggle: function (id) {
|
||||
var l = FAV.list(), i = l.indexOf(id);
|
||||
if (i >= 0) l.splice(i, 1); else l.push(id);
|
||||
SDVB_STORE.set('sdvb-fav', JSON.stringify(l));
|
||||
return i < 0;
|
||||
}
|
||||
};
|
||||
var FAV_GROUP = '__fav';
|
||||
|
||||
function pageTv(view, args) {
|
||||
view.innerHTML = '<div class="tv"><div class="panel tv-list" id="tv-list"></div><div><div class="player" id="tv-player"><div class="overlay"><div>Pick a channel from the list</div></div></div>' +
|
||||
@@ -444,22 +541,38 @@
|
||||
var f = filter.toLowerCase();
|
||||
var groups = [];
|
||||
channels.forEach(function (c) { if (c.enabled && c.grp && groups.indexOf(c.grp) < 0) groups.push(c.grp); });
|
||||
if (group && groups.indexOf(group) < 0) group = '';
|
||||
var list = channels.filter(function (c) { return c.enabled && (!group || c.grp === group) && (!f || c.name.toLowerCase().indexOf(f) >= 0 || String(c.number) === f); });
|
||||
var favs = FAV.list();
|
||||
var hasFav = channels.some(function (c) { return c.enabled && favs.indexOf(c.id) >= 0; });
|
||||
if (group && group !== FAV_GROUP && groups.indexOf(group) < 0) group = '';
|
||||
if (group === FAV_GROUP && !hasFav) group = '';
|
||||
var list = channels.filter(function (c) {
|
||||
return c.enabled && (!group || (group === FAV_GROUP ? favs.indexOf(c.id) >= 0 : c.grp === group)) && (!f || c.name.toLowerCase().indexOf(f) >= 0 || String(c.number) === f);
|
||||
});
|
||||
$('#tv-list').classList.toggle('hide-logos', !P.get('logos'));
|
||||
$('#tv-list').classList.toggle('hide-progress', !P.get('progress'));
|
||||
$('#tv-list').innerHTML = '<div class="search"><input id="tv-search" placeholder="Search channel…" value="' + esc(filter) + '">' +
|
||||
(groups.length > 1 ? '<select id="tv-group"><option value="">' + esc(T('All')) + '</option>' + groups.map(function (g) { return '<option' + (g === group ? ' selected' : '') + '>' + esc(g) + '</option>'; }).join('') + '</select>' : '') + '</div>' +
|
||||
(groups.length > 1 || hasFav ? '<select id="tv-group"><option value="">' + esc(T('All')) + '</option>' +
|
||||
(hasFav ? '<option value="' + FAV_GROUP + '"' + (group === FAV_GROUP ? ' selected' : '') + '>' + esc(T('Favourites')) + '</option>' : '') +
|
||||
(groups.length > 1 ? groups.map(function (g) { return '<option' + (g === group ? ' selected' : '') + '>' + esc(g) + '</option>'; }).join('') : '') + '</select>' : '') + '</div>' +
|
||||
(list.length ? list.map(function (c) {
|
||||
var fav = favs.indexOf(c.id) >= 0;
|
||||
return '<div class="ch-item' + (current && current.id === c.id ? ' active' : '') + '" data-id="' + c.id + '"><div class="n">' + c.number + '</div>' + logo(c) +
|
||||
'<div class="t"><div class="name">' + esc(c.name) + '</div><div class="now">' + (c.now ? hm(c.now.start) + ' ' + esc(c.now.title) : (c.kind === 'radio' ? 'radio' : ' ')) + '</div>' +
|
||||
'<div class="t"><div class="name">' + esc(c.name) + '<button class="fav' + (fav ? ' on' : '') + '" data-fav="' + c.id + '" title="' + esc(T(fav ? 'Remove from favourites' : 'Add to favourites')) + '">' + ico(fav ? 'starOn' : 'star') + '</button></div><div class="now">' + (c.now ? hm(c.now.start) + ' ' + esc(c.now.title) : (c.kind === 'radio' ? 'radio' : ' ')) + '</div>' +
|
||||
(c.now ? '<div class="meter"><i style="width:' + progressPct(c.now) + '%"></i></div>' : '') + '</div></div>';
|
||||
}).join('') : '<div class="empty">No channels – run a scan on the Tuners page.</div>');
|
||||
var gs = $('#tv-group');
|
||||
if (gs) gs.addEventListener('change', function () { group = gs.value; try { localStorage.setItem('sdvb-group', group); } catch (e) {} renderList(); });
|
||||
if (gs) gs.addEventListener('change', function () { group = gs.value; try { SDVB_STORE.set('sdvb-group', group); } catch (e) {} renderList(); });
|
||||
var s = $('#tv-search');
|
||||
s.addEventListener('input', function () { filter = s.value; var pos = s.selectionStart; renderList(); var n = $('#tv-search'); n.focus(); n.setSelectionRange(pos, pos); });
|
||||
$$('.ch-item', $('#tv-list')).forEach(function (e) { e.addEventListener('click', function () { play(+e.getAttribute('data-id')); }); });
|
||||
$$('[data-fav]', $('#tv-list')).forEach(function (b) {
|
||||
b.addEventListener('click', function (ev) {
|
||||
ev.stopPropagation();
|
||||
var on = FAV.toggle(+b.getAttribute('data-fav'));
|
||||
toast(T(on ? 'Added to favourites' : 'Removed from favourites'));
|
||||
renderList();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function renderInfo() {
|
||||
@@ -471,8 +584,8 @@
|
||||
'<div class="desc">' + esc(n.description || n.summary || '') + '</div>' : '<h2>' + esc(c.name) + '</h2><div class="muted">No EPG data for this moment.</div>') +
|
||||
(nx ? '<div class="small muted" style="margin-top:8px">Next: <b>' + hm(nx.start) + '</b> ' + esc(nx.title) + '</div>' : '') +
|
||||
'</div><div class="actions" style="align-items:flex-start">' +
|
||||
(n && isAdmin() ? '<button class="btn" id="tv-rec">● Record programme</button>' : '') +
|
||||
'<button class="btn" id="tv-pip" title="Picture-in-picture (P)">⧉ PiP</button><button class="btn" id="tv-full" title="F">⛶ Fullscreen</button></div></div>';
|
||||
(n && isAdmin() ? '<button class="btn" id="tv-rec">' + ico('record') + 'Record programme</button>' : '') +
|
||||
'<button class="btn" id="tv-pip" title="Picture-in-picture (P)">' + ico('pip') + 'PiP</button><button class="btn" id="tv-full" title="F">' + ico('fullscreen') + 'Fullscreen</button></div></div>';
|
||||
var r = $('#tv-rec');
|
||||
if (r) r.addEventListener('click', function () { api('POST', '/api/recordings', { event_id: n.id }).then(function () { toast('Recording scheduled: ' + n.title); }).catch(fail); });
|
||||
$('#tv-full').addEventListener('click', fullscreen);
|
||||
@@ -489,7 +602,7 @@
|
||||
(evs.length ? evs.map(function (e) {
|
||||
var cls = e.stop < t ? 'past' : e.start <= t ? 'cur' : '';
|
||||
return '<div class="ev ' + cls + '"><span class="tm">' + hm(e.start) + '</span><span>' + esc(e.title) + '</span>' +
|
||||
(e.start > t && isAdmin() ? '<button class="btn small ghost" data-rec="' + e.id + '" title="Record">●</button>' : '<span></span>') + '</div>';
|
||||
(e.start > t && isAdmin() ? '<button class="btn small ghost" data-rec="' + e.id + '" title="Record">' + ico('record') + '</button>' : '<span></span>') + '</div>';
|
||||
}).join('') : '<div class="muted">No EPG yet. Data appears after EIT is collected from the mux or XMLTV is imported.</div>') + '</div>';
|
||||
$$('[data-rec]', $('#tv-day')).forEach(function (b) {
|
||||
b.addEventListener('click', function () { api('POST', '/api/recordings', { event_id: +b.getAttribute('data-rec') }).then(function () { toast('Recording scheduled'); renderDay(); }).catch(fail); });
|
||||
@@ -501,12 +614,12 @@
|
||||
var c = current;
|
||||
if (!c) return;
|
||||
var svc = c.service || {};
|
||||
var profiles = [['auto', 'Automatic'], ['pass', 'Original'], ['aac', 'Audio → AAC'], ['h264', 'H.264 720p']];
|
||||
var profiles = [['auto', 'Automatic'], ['pass', 'Original'], ['aac', 'AAC audio'], ['h264', 'H.264 720p']];
|
||||
var noFfmpeg = app.info && app.info.ffmpeg === false;
|
||||
var caps = [svc.video].concat((svc.audio || []).map(function (a) { return a.replace(/ \(.*\)$/, ''); })).filter(function (x, i, a) { return x && a.indexOf(x) === i; });
|
||||
var capsHtml = caps.map(function (x) {
|
||||
var ok = window.SDVB.codecSupported(x);
|
||||
return '<span class="pill ' + (ok ? 'ok' : 'err') + '" title="' + esc(T(ok ? 'Supported by this browser' : 'Not supported by this browser')) + '">' + esc(x) + ' ' + (ok ? '✓' : '✗') + '</span>';
|
||||
return '<span class="pill ' + (ok ? 'ok' : 'err') + '" title="' + esc(T(ok ? 'Supported by this browser' : 'Not supported by this browser')) + '">' + esc(x) + ' ' + ico(ok ? 'check' : 'cross') + '</span>';
|
||||
}).join(' ');
|
||||
var why = window.SDVB.explain(svc.video, svc.audio);
|
||||
$('#tv-tools').innerHTML = '<header><h2>Stream</h2><span class="pill">' + esc(svc.video || (c.kind === 'radio' ? 'radio' : '?')) + ' · ' + esc((svc.audio || []).join(', ') || '–') + '</span></header>' +
|
||||
@@ -521,8 +634,8 @@
|
||||
(why ? '<p class="hint">' + esc(why) + (noFfmpeg ? ' ' + esc(T('Without ffmpeg on the server use VLC or a browser/device that decodes these codecs.')) : '') + '</p>' : '') +
|
||||
'<div style="margin-top:10px" class="copy-row"><code>' + esc(location.origin + '/hls/' + c.id + '/index.m3u8') + '</code><button class="btn small" data-copy="hls">HLS</button></div>' +
|
||||
'<div class="copy-row"><code>' + esc(location.origin + '/stream/channelid/' + c.id + '?profile=pass') + '</code><button class="btn small" data-copy="ts">TS</button></div>' +
|
||||
'<div class="row" style="margin-top:6px"><a class="btn small" href="/playlist/channelid/' + c.id + '" download="' + esc(c.name) + '.m3u">▶ VLC (.m3u)</a></div>' +
|
||||
'<p class="hint">' + esc(T('Shortcuts: ↑/↓ channel, digits – number, F – fullscreen, P – picture-in-picture, M – mute, ? – help.')) + '</p>' +
|
||||
'<div class="row" style="margin-top:6px"><a class="btn small" href="/playlist/channelid/' + c.id + '" download="' + esc(c.name) + '.m3u">' + ico('vlc') + 'VLC (.m3u)</a></div>' +
|
||||
'<p class="hint">' + esc(T('Shortcuts: arrow up/down – channel, digits – number, F – fullscreen, P – picture-in-picture, M – mute, ? – help.')) + '</p>' +
|
||||
'<p class="hint">The “Automatic” profile checks which codecs your browser supports (e.g. HEVC, AC-3) and enables ffmpeg transcoding when needed.</p>';
|
||||
$('#tv-profile').addEventListener('change', function (e) {
|
||||
wantProfile = e.target.value;
|
||||
@@ -540,7 +653,7 @@
|
||||
current = c;
|
||||
if (app.player) { app.player.destroy(); app.player = null; }
|
||||
$('#tv-player').innerHTML = '<div class="overlay"><div style="text-align:center"><div class="eyebrow">' + esc(c.number + ' · ' + c.name) + '</div>' +
|
||||
'<button class="btn primary" id="tv-start" style="margin-top:10px">▶ ' + esc(T('Play')) + '</button></div></div>';
|
||||
'<button class="btn primary" id="tv-start" style="margin-top:10px">' + ico('play') + esc(T('Play')) + '</button></div></div>';
|
||||
$('#tv-start').addEventListener('click', function () { play(c.id); });
|
||||
renderList(); renderInfo(); renderDay(); renderTools('');
|
||||
}
|
||||
@@ -582,11 +695,11 @@
|
||||
play(list[(i + delta + list.length) % list.length].id);
|
||||
}
|
||||
var digits = '', digitTimer = null;
|
||||
function osd(text) {
|
||||
function osd(text, icon) {
|
||||
var box = $('#tv-player');
|
||||
var o = $('.osd', box);
|
||||
if (!o) { o = document.createElement('div'); o.className = 'osd'; box.appendChild(o); }
|
||||
o.textContent = text;
|
||||
o.innerHTML = (icon ? ico(icon) : '') + esc(text);
|
||||
o.classList.add('show');
|
||||
clearTimeout(o._t);
|
||||
o._t = setTimeout(function () { o.classList.remove('show'); }, 1500);
|
||||
@@ -600,7 +713,7 @@
|
||||
else if (k === 'ArrowDown' || k === 'PageDown') { zap(1); e.preventDefault(); }
|
||||
else if (k === 'f' || k === 'F') fullscreen();
|
||||
else if (k === 'p' || k === 'P') pip();
|
||||
else if ((k === 'm' || k === 'M') && v) { v.muted = !v.muted; osd(v.muted ? '🔇' : '🔊'); }
|
||||
else if ((k === 'm' || k === 'M') && v) { v.muted = !v.muted; osd(T(v.muted ? 'Sound off' : 'Sound on'), v.muted ? 'mute' : 'volume'); }
|
||||
else if (k === ' ' && v) { if (v.paused) v.play(); else v.pause(); e.preventDefault(); }
|
||||
else if (k === '?') shortcutsHelp();
|
||||
else if (/^[0-9]$/.test(k)) {
|
||||
@@ -615,7 +728,7 @@
|
||||
}
|
||||
}
|
||||
function shortcutsHelp() {
|
||||
modal('Keyboard shortcuts', '<div class="kv">' + [['↑ / ↓', 'Previous / next channel'], ['0–9', 'Select channel by number'], ['F', 'Fullscreen'], ['P', 'Picture-in-picture'], ['M', 'Mute'], ['Space', 'Pause / resume'], ['?', 'This help']].map(function (x) {
|
||||
modal('Keyboard shortcuts', '<div class="kv">' + [['Arrow up / down', 'Previous / next channel'], ['0–9', 'Select channel by number'], ['F', 'Fullscreen'], ['P', 'Picture-in-picture'], ['M', 'Mute'], ['Space', 'Pause / resume'], ['?', 'This help']].map(function (x) {
|
||||
return '<span>' + esc(x[0]) + '</span><span>' + esc(x[1]) + '</span>';
|
||||
}).join('') + '</div>');
|
||||
}
|
||||
@@ -628,7 +741,7 @@
|
||||
var id = +(args[0] || 0) || (function () { try { return +localStorage.getItem('sdvb-last') || 0; } catch (e) { return 0; } })();
|
||||
if (id && channels.some(function (c) { return c.id === id; })) {
|
||||
// the TV tab (also #/tv/<id> after a reload or history navigation) only selects
|
||||
// the channel; playback starts on click, from an explicit ▶ link (#/tv/<id>/play)
|
||||
// the channel; playback starts on click, from an explicit play link (#/tv/<id>/play)
|
||||
// or when autoplay is on in Preferences – so visiting the tab does not take a tuner
|
||||
if (args[1] === 'play' || P.get('autoplay')) play(id); else select(id);
|
||||
}
|
||||
@@ -645,13 +758,63 @@
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ EPG
|
||||
/** Programme reminders (kept in the profile): a notification 2 min before the start
|
||||
* while the panel is open in any tab or on any device. */
|
||||
var REMIND = {
|
||||
LEAD: 120,
|
||||
list: function () { try { var v = JSON.parse(SDVB_STORE.get('sdvb-remind') || '[]'); return Array.isArray(v) ? v : []; } catch (x) { return []; } },
|
||||
save: function (l) { SDVB_STORE.set('sdvb-remind', JSON.stringify(l)); },
|
||||
key: function (e) { return e.channel_id + ':' + e.start; },
|
||||
has: function (e) { var k = REMIND.key(e); return REMIND.list().some(function (r) { return r.k === k; }); },
|
||||
toggle: function (e, ch) {
|
||||
var k = REMIND.key(e), l = REMIND.list(), i = -1;
|
||||
l.forEach(function (r, j) { if (r.k === k) i = j; });
|
||||
if (i >= 0) { l.splice(i, 1); REMIND.save(l); return false; }
|
||||
l.push({ k: k, ch: ch.id, chName: ch.name, title: e.title, start: e.start });
|
||||
REMIND.save(l);
|
||||
if (window.Notification && Notification.permission === 'default') { try { Notification.requestPermission(); } catch (x) {} }
|
||||
return true;
|
||||
},
|
||||
check: function () {
|
||||
var t = now(), l = REMIND.list(), keep = [], fired = false;
|
||||
l.forEach(function (r) {
|
||||
if (r.start - t > REMIND.LEAD) { keep.push(r); return; }
|
||||
fired = true;
|
||||
if (r.start < t - 600) return; // missed long ago (panel was closed)
|
||||
var msg = r.title + ' – ' + r.chName + ' ' + hm(r.start);
|
||||
toast(msg);
|
||||
if (window.Notification && Notification.permission === 'granted') {
|
||||
try {
|
||||
var opts = { body: msg, tag: r.k, icon: '/assets/icon-192.png', data: { url: '/#/tv/' + r.ch + '/play' } };
|
||||
// installed app (service worker): the notification also works from the background
|
||||
if (navigator.serviceWorker && navigator.serviceWorker.controller) {
|
||||
navigator.serviceWorker.ready.then(function (reg) { reg.showNotification(T('Starting soon'), opts); });
|
||||
} else {
|
||||
var n = new Notification(T('Starting soon'), opts);
|
||||
n.onclick = function () { window.focus(); location.hash = '#/tv/' + r.ch + '/play'; n.close(); };
|
||||
}
|
||||
} catch (x) {}
|
||||
}
|
||||
});
|
||||
if (fired) REMIND.save(keep);
|
||||
}
|
||||
};
|
||||
setInterval(function () { if (app.me) REMIND.check(); }, 20000);
|
||||
|
||||
function eventModal(e, ch) {
|
||||
var body = modal(e.title,
|
||||
'<div class="kv"><span>Channel</span><span>' + esc(ch ? ch.number + ' · ' + ch.name : '') + '</span><span>Time</span><span>' + dt(e.start) + ' – ' + hm(e.stop) + ' (' + dur(e.stop - e.start) + ')</span>' +
|
||||
(e.genre ? '<span>Genre</span><span>' + esc(e.genre) + '</span>' : '') + (e.rating ? '<span>Age</span><span>' + e.rating + '+</span>' : '') +
|
||||
'<span>Source</span><span>' + esc(e.source === 'xmltv' ? 'XMLTV' : 'EIT (broadcast)') + '</span></div>' +
|
||||
(e.summary ? '<p><b>' + esc(e.summary) + '</b></p>' : '') + '<p style="white-space:pre-line">' + esc(e.description || '') + '</p>' +
|
||||
'<div class="modal-foot">' + (ch ? '<a class="btn" href="#/tv/' + ch.id + '/play">▶ Watch channel</a>' : '') + (isAdmin() && e.stop > now() ? '<button class="btn primary" id="ev-rec">● Record</button>' : '') + '</div>');
|
||||
'<div class="modal-foot">' + (ch && e.start > now() ? '<button class="btn" id="ev-remind">' + ico('bell') + '<span>' + esc(T(REMIND.has(e) ? 'Reminder set' : 'Remind me')) + '</span></button>' : '') +
|
||||
(ch ? '<a class="btn" href="#/tv/' + ch.id + '/play">' + ico('play') + 'Watch channel</a>' : '') + (isAdmin() && e.stop > now() ? '<button class="btn primary" id="ev-rec">' + ico('record') + 'Record</button>' : '') + '</div>');
|
||||
var rm = $('#ev-remind', body);
|
||||
if (rm) rm.addEventListener('click', function () {
|
||||
var on = REMIND.toggle(e, ch);
|
||||
$('span', rm).textContent = T(on ? 'Reminder set' : 'Remind me');
|
||||
toast(on ? T('You will be reminded 2 minutes before the start') : T('Reminder removed'));
|
||||
});
|
||||
var r = $('#ev-rec', body);
|
||||
if (r) r.addEventListener('click', function () {
|
||||
api('POST', '/api/recordings', { event_id: e.id }).then(function () { toast('Recording scheduled: ' + e.title); closeModal(); }).catch(fail);
|
||||
@@ -664,7 +827,7 @@
|
||||
var start = Math.floor((now() - 3600) / 1800) * 1800;
|
||||
var hours = 12;
|
||||
view.innerHTML = head('Electronic programme guide', 'TV guide', 'EPG from the broadcast (EIT) and external XMLTV sources.',
|
||||
'<button class="btn" id="epg-prev">◀ 6 h</button><button class="btn" id="epg-now">Now</button><button class="btn" id="epg-next">6 h ▶</button>' +
|
||||
'<button class="btn" id="epg-prev">' + ico('prev') + '6 h</button><button class="btn" id="epg-now">Now</button><button class="btn" id="epg-next">6 h' + ico('next') + '</button>' +
|
||||
(isAdmin() ? '<button class="btn" id="epg-grab">Grab EPG now</button>' : '')) + '<div class="epg" id="epg"></div>';
|
||||
function render() {
|
||||
var end = start + hours * 3600;
|
||||
@@ -742,7 +905,7 @@
|
||||
return true;
|
||||
});
|
||||
}
|
||||
function saveFilters() { try { localStorage.setItem('sdvb-chfilter', JSON.stringify(F)); } catch (e) {} }
|
||||
function saveFilters() { try { SDVB_STORE.set('sdvb-chfilter', JSON.stringify(F)); } catch (e) {} }
|
||||
function renderFilters() {
|
||||
var groups = [];
|
||||
channels.forEach(function (c) { if (c.grp && groups.indexOf(c.grp) < 0) groups.push(c.grp); });
|
||||
@@ -795,13 +958,13 @@
|
||||
list.map(function (c) {
|
||||
var s = c.service || {};
|
||||
var pr = problem(c);
|
||||
return '<tr data-id="' + c.id + '" draggable="' + (isAdmin() ? 'true' : 'false') + '"' + (c.enabled ? '' : ' class="off"') + '><td class="drag">⠿</td><td class="num">' + c.number + '</td><td>' + logo(c) + '</td><td><b>' + esc(c.name) + '</b>' +
|
||||
return '<tr data-id="' + c.id + '" draggable="' + (isAdmin() ? 'true' : 'false') + '"' + (c.enabled ? '' : ' class="off"') + '><td class="drag">' + ico('grip') + '</td><td class="num">' + c.number + '</td><td>' + logo(c) + '</td><td><b>' + esc(c.name) + '</b>' +
|
||||
(pr ? ' <span class="pill err">' + esc(T(pr)) + '</span>' : '') + (!pr && unknownStreams(c) ? ' <span class="pill" title="' + esc(T('The scan did not see this service\'s stream list in time. It is filled in when the channel is played or with “Detect streams”.')) + '">' + esc(T('streams unknown')) + '</span>' : '') + (s.scrambled ? ' <span class="pill warn">scrambled</span>' : '') + (c.kind === 'radio' ? ' <span class="pill">radio</span>' : '') + '</td><td>' + esc(c.grp) + '</td>' +
|
||||
'<td class="small mono">' + esc([s.video].concat(s.audio || []).filter(Boolean).join(' · ')) + '</td><td class="small muted">' + esc(c.mux || '') + '</td>' +
|
||||
'<td class="small">' + (c.now ? esc(c.now.title) : '<span class="muted">–</span>') + '</td>' +
|
||||
'<td>' + sw(c.enabled, 'data-en="' + c.id + '"' + (isAdmin() ? '' : ' disabled')) + '</td>' +
|
||||
'<td>' + sw(c.share_enabled, 'data-sh="' + c.id + '"' + (isAdmin() ? '' : ' disabled')) + (c.share_enabled && c.share_token ? ' <button class="btn small" data-shcopy="' + esc(c.share_token) + '">Copy link</button>' : '') + '</td>' +
|
||||
'<td class="actions-cell"><a class="btn small" href="#/tv/' + c.id + '/play">▶</a> <a class="btn small" href="/playlist/channelid/' + c.id + '" download="' + esc(c.name) + '.m3u" title="VLC">VLC</a>' + (isAdmin() ? ' <button class="btn small" data-edit="' + c.id + '">Edit</button>' : '') + '</td></tr>';
|
||||
'<td class="actions-cell"><a class="btn small" href="#/tv/' + c.id + '/play" title="Watch">' + ico('play') + '</a> <a class="btn small" href="/playlist/channelid/' + c.id + '" download="' + esc(c.name) + '.m3u" title="VLC">VLC</a>' + (isAdmin() ? ' <button class="btn small" data-edit="' + c.id + '">Edit</button>' : '') + '</td></tr>';
|
||||
}).join('') + '</tbody></table>';
|
||||
bind();
|
||||
}
|
||||
@@ -931,7 +1094,7 @@
|
||||
function pageRecordings(view) {
|
||||
view.innerHTML = head('Video recorder', 'Recordings', 'Schedule from the EPG or manually. Play finished recordings in the browser or download them as .ts.',
|
||||
isAdmin() ? '<button class="btn primary" id="rec-new">+ New recording</button>' : '') +
|
||||
'<div class="panel"><div class="tabs" id="rec-tabs"><button data-t="upcoming" class="active">Scheduled & running</button><button data-t="schedule">Schedule</button><button data-t="done">Finished</button><button data-t="failed">Failed / cancelled</button><button data-t="rules">Rules (series)</button></div><div class="table-wrap" id="rec-table"></div></div>';
|
||||
'<div class="panel"><div class="tabs" id="rec-tabs"><button data-t="upcoming" class="active">Scheduled & running</button><button data-t="schedule">Timeline</button><button data-t="done">Finished</button><button data-t="failed">Failed / cancelled</button><button data-t="rules">Rules (series)</button></div><div class="table-wrap" id="rec-table"></div></div>';
|
||||
var tab = 'upcoming', recs = [];
|
||||
/** Timeline of upcoming recordings, one row per day, with tuner-conflict warnings. */
|
||||
function renderSchedule() {
|
||||
@@ -972,7 +1135,7 @@
|
||||
var left = (x._s0 - day) / 864, width = Math.max(0.4, (x._s1 - x._s0) / 864);
|
||||
var cls = 'sched-bar' + (x.conflict ? ' conflict' : '') + (x.status === 'recording' ? ' live' : '');
|
||||
return '<div class="' + cls + '" style="left:' + left + '%;width:' + width + '%;top:' + (x._lane * 26 + 16) + 'px;--c:' + color(x.mux_id) + '" title="' + esc(x.title + '\n' + x.channel_name + '\n' + hm(x.start) + '–' + hm(x.stop) + (x.conflict ? '\n' + T('Conflict: not enough tuners') : '')) + '">' +
|
||||
(x.conflict ? '⚠ ' : '') + esc(x.title) + ' <span class="muted">' + esc(x.channel_name) + '</span></div>';
|
||||
(x.conflict ? ico('warn') : '') + esc(x.title) + ' <span class="muted">' + esc(x.channel_name) + '</span></div>';
|
||||
}).join('') + '</div></div>';
|
||||
});
|
||||
html += '<table style="margin-top:12px"><thead><tr><th>Start</th><th>End</th><th>Title</th><th>Channel</th><th>Status</th></tr></thead><tbody>' + list.map(function (x) {
|
||||
@@ -1046,8 +1209,8 @@
|
||||
var st = REC_STATUS[r.status] || [r.status, ''];
|
||||
return '<tr><td><span class="pill ' + st[1] + '">' + st[0] + '</span></td><td><b>' + esc(r.title) + '</b>' + (r.error ? '<div class="small error-text">' + esc(r.error) + '</div>' : '') + '</td><td>' + esc(r.channel_name) + '</td>' +
|
||||
'<td class="mono small">' + dt(r.start) + '</td><td class="mono small">' + hm(r.stop) + '</td><td class="num">' + (r.duration ? dur(r.duration) : dur(r.stop - r.start)) + '</td><td class="num">' + (r.size ? bytes(r.size) : '–') + '</td>' +
|
||||
'<td class="actions-cell">' + (r.autorec_id ? '<span class="pill blue" title="' + esc(T('From a rule')) + '">R</span> ' : '') + (r.file && r.size ? '<button class="btn small" data-play="' + r.id + '">▶ Play</button> <a class="btn small" href="/recordings/' + r.id + '/file" download>Download</a> ' : '') +
|
||||
(isAdmin() && (r.status === 'scheduled' || r.status === 'recording') ? '<button class="btn small" data-stop="' + r.id + '">' + (r.status === 'recording' ? '■ Stop' : 'Cancel') + '</button> ' : '') +
|
||||
'<td class="actions-cell">' + (r.autorec_id ? '<span class="pill blue" title="' + esc(T('From a rule')) + '">R</span> ' : '') + (r.file && r.size ? '<button class="btn small" data-play="' + r.id + '">' + ico('play') + 'Play</button> <a class="btn small" href="/recordings/' + r.id + '/file" download>Download</a> ' : '') +
|
||||
(isAdmin() && (r.status === 'scheduled' || r.status === 'recording') ? '<button class="btn small" data-stop="' + r.id + '">' + (r.status === 'recording' ? ico('stop') + 'Stop' : 'Cancel') + '</button> ' : '') +
|
||||
(isAdmin() ? '<button class="btn small danger" data-del="' + r.id + '">Delete</button>' : '') + '</td></tr>';
|
||||
}).join('') + '</tbody></table>' : '<div class="empty">No recordings in this category.</div>';
|
||||
$$('[data-play]').forEach(function (b) {
|
||||
@@ -1095,7 +1258,7 @@
|
||||
// ------------------------------------------------------------ TUNERS
|
||||
function pageTuners(view) {
|
||||
view.innerHTML = head('Hardware & muxes', 'Tuners & scanning', 'DVB-T/T2/C cards (e.g. Si2168), frequency scanning and saved muxes.',
|
||||
isAdmin() ? '<button class="btn" id="ad-refresh">Detect adapters</button>' : '') +
|
||||
'<a class="btn" href="#/signal">' + ico('antenna') + 'Antenna meter</a>' + (isAdmin() ? '<button class="btn" id="ad-refresh">Detect adapters</button>' : '')) +
|
||||
'<div class="grid g2"><div class="panel"><header><h2>Adapters</h2></header><div id="ad-list"></div></div>' +
|
||||
'<div class="panel"><header><h2>Scanning</h2><span id="scan-pill"></span></header><div id="scan-box"></div></div></div>' +
|
||||
'<div class="panel"><header><h2>Muxes</h2>' + (isAdmin() ? '<button class="btn small" id="mux-add">+ Add manually</button>' : '') + '</header><div class="table-wrap" id="mux-table"></div></div>';
|
||||
@@ -1176,7 +1339,7 @@
|
||||
if (idle && s.idle_scan) {
|
||||
idle.textContent = s.idle_scan.enabled
|
||||
? T('Background scan of saved muxes when tuners are idle: every') + ' ' + s.idle_scan.every_hours + ' h · ' + T('last:') + ' ' + (s.idle_scan.last ? dt(s.idle_scan.last) : '–')
|
||||
: T('Background scanning is off (Settings → Scanning).');
|
||||
: T('Background scanning is off (Settings, section Scanning).');
|
||||
}
|
||||
var go = $('#scan-go'), stop = $('#scan-stop');
|
||||
// a manual scan may replace a background one
|
||||
@@ -1257,6 +1420,7 @@
|
||||
'<p class="hint">A token allows playing streams from outside the local network (e.g. a TV at your family’s place). It can be limited to selected addresses/networks.</p></div>' +
|
||||
'<div class="panel"><header><h2>Panel users</h2>' + (isAdmin() ? '<button class="btn small" id="usr-add">+ New user</button>' : '') + '</header><div id="users"></div>' +
|
||||
'<div class="row" style="margin-top:10px"><button class="btn small" id="pw-change">Change my password</button></div></div></div>' +
|
||||
'<div class="panel" id="account" style="margin-top:10px"></div>' +
|
||||
(isAdmin() ? '<div class="panel"><header><h2>Access control (ACL)</h2><button class="btn small primary" id="acl-save">Save ACL</button></header><div class="form-grid" id="acl"></div></div>' : '');
|
||||
|
||||
function links() {
|
||||
@@ -1269,6 +1433,7 @@
|
||||
return '<div style="margin-top:10px"><div class="label">' + esc(l.name) + '</div>' +
|
||||
'<div class="copy-row"><span class="pill acc">M3U</span><code>' + esc(l.m3u) + '</code><button class="btn small" data-c>Copy</button></div>' +
|
||||
'<div class="copy-row"><span class="pill blue">HLS</span><code>' + esc(l.m3u_hls) + '</code><button class="btn small" data-c>Copy</button></div>' +
|
||||
(FAV.list().length ? '<div class="copy-row"><span class="pill acc">' + ico('starOn') + 'M3U</span><code>' + esc(l.m3u + (l.m3u.indexOf('?') >= 0 ? '&' : '?') + 'channels=' + FAV.list().join(',')) + '</code><button class="btn small" data-c>Copy</button></div>' : '') +
|
||||
'<div class="copy-row"><span class="pill ok">EPG</span><code>' + esc(l.epg) + '</code><button class="btn small" data-c>Copy</button></div>' +
|
||||
'<div class="copy-row"><span class="pill warn">TVH</span><code>' + esc(l.tvh_playlist) + '</code><button class="btn small" data-c>Copy</button></div>' +
|
||||
'<div class="copy-row"><span class="pill warn">TVH</span><code>' + esc(l.tvh_xmltv) + '</code><button class="btn small" data-c>Copy</button></div></div>';
|
||||
@@ -1316,7 +1481,7 @@
|
||||
var hosts = Object.keys(m || {});
|
||||
if (!hosts.length) return '';
|
||||
return '<div class="full small muted">' + esc(T('DDNS host names now resolve to:')) + ' ' + hosts.map(function (h) {
|
||||
return '<span class="mono">' + esc(h) + ' → ' + esc((m[h] || []).join(', ') || T('not resolved')) + '</span>';
|
||||
return '<span class="mono">' + esc(h) + ': ' + esc((m[h] || []).join(', ') || T('not resolved')) + '</span>';
|
||||
}).join(' · ') + '</div>';
|
||||
}
|
||||
function acl() {
|
||||
@@ -1334,7 +1499,7 @@
|
||||
};
|
||||
}).catch(fail);
|
||||
}
|
||||
links(); tokens(); users(); acl();
|
||||
links(); tokens(); users(); acl(); renderAccount();
|
||||
$('#pw-change').addEventListener('click', function () {
|
||||
var body = modal('Change password', '<div class="form-grid"><label class="full">Current password<input type="password" name="cur" autocomplete="current-password"></label><label class="full">New password<input type="password" name="new" autocomplete="new-password"></label></div><div class="modal-foot"><button class="btn primary" id="pw-save">Change</button></div>');
|
||||
$('#pw-save', body).addEventListener('click', function () {
|
||||
@@ -1360,7 +1525,7 @@
|
||||
// ------------------------------------------------------------ LOGS
|
||||
function pageLogs(view) {
|
||||
view.innerHTML = head('Diagnostics', 'Logs', 'What the server is doing: tuners, streams, access, EPG and recordings. The last 4000 entries are kept in memory.',
|
||||
'<a class="btn" href="/api/logs/download" download>⤓ Download</a><button class="btn" id="log-clear">Clear view</button>') +
|
||||
'<a class="btn" href="/api/logs/download" download>' + ico('download') + 'Download</a><button class="btn" id="log-clear">Clear view</button>') +
|
||||
'<div class="panel"><div class="tabs" id="log-cats"></div>' +
|
||||
'<div class="filters" style="border:0;padding:8px 0 4px"><select id="log-level"><option value="">' + esc(T('All levels')) + '</option><option value="info">info+</option><option value="warn">' + esc(T('warnings and errors')) + '</option><option value="error">' + esc(T('errors only')) + '</option></select>' +
|
||||
'<input id="log-q" placeholder="' + esc(T('Search…')) + '"><label class="check"><input type="checkbox" id="log-follow" checked> ' + esc(T('Follow')) + '</label><span class="spacer"></span><span class="muted small mono" id="log-count"></span></div>' +
|
||||
@@ -1422,7 +1587,7 @@
|
||||
var profile = 'auto';
|
||||
try { profile = localStorage.getItem('sdvb-profile') || 'auto'; } catch (e) {}
|
||||
box.innerHTML = '<header><h2>Appearance</h2><button class="btn small" id="prefs-reset">Reset to defaults</button></header>' +
|
||||
'<p class="hint" style="margin-top:-4px">Interface preferences are stored in this browser.</p>' +
|
||||
'<p class="hint" style="margin-top:-4px">Interface preferences are saved in your user profile and follow you to every device.</p>' +
|
||||
row('Language', langSelect('pref-lang', false)) +
|
||||
row('Theme', seg('theme', [['dark', 'Dark'], ['midnight', 'Midnight (OLED)'], ['light', 'Light'], ['system', 'System default']])) +
|
||||
row('Accent colour', '<div class="swatches">' + P.accents.map(function (a) {
|
||||
@@ -1432,7 +1597,7 @@
|
||||
row('Interface scale', seg('scale', [[90, '90%'], [100, '100%'], [110, '110%'], [125, '125%']])) +
|
||||
row('Sidebar', seg('sidebar', [['hover', 'Expand on hover'], ['pinned', 'Always expanded']])) +
|
||||
row('Start page', seg('start', [['overview', 'Overview'], ['tv', 'TV'], ['epg', 'TV guide'], ['channels', 'Channels']])) +
|
||||
row('Default player profile', '<div class="seg" id="pref-profile">' + [['auto', 'Automatic'], ['pass', 'Original'], ['aac', 'Audio → AAC'], ['h264', 'H.264 720p']].map(function (o) {
|
||||
row('Default player profile', '<div class="seg" id="pref-profile">' + [['auto', 'Automatic'], ['pass', 'Original'], ['aac', 'AAC audio'], ['h264', 'H.264 720p']].map(function (o) {
|
||||
return '<button data-p="' + o[0] + '"' + (profile === o[0] ? ' class="on"' : '') + '>' + esc(o[1]) + '</button>';
|
||||
}).join('') + '</div>') +
|
||||
row('EPG grid zoom', seg('epgZoom', [[3, 'Narrow'], [4, 'Normal'], [6, 'Wide']])) +
|
||||
@@ -1460,10 +1625,225 @@
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ SETTINGS
|
||||
function pageSettings(view) {
|
||||
// ------------------------------------------------------------ ANTENNA METER
|
||||
function pageSignal(view) {
|
||||
view.innerHTML = head('Antenna', 'Antenna meter', 'Live signal of a tuner, refreshed every second – handy while aligning the antenna (open it on the phone).',
|
||||
'<label class="check"><input type="checkbox" id="sg-sound"> ' + esc(T('Sound')) + '</label>') +
|
||||
'<div class="panel"><div class="row sg-pick" id="sg-pick"></div></div><div id="sg-body"></div>';
|
||||
var adapters = [], muxes = [], sel = SDVB_STORE.get('sdvb-sigad') || '', hist = { t: [], snr: [], str: [] };
|
||||
var holdMux = null, holdTimer = null, audio = null, beepTimer = null, lastSnr = null;
|
||||
function quality(snr, locked) {
|
||||
if (!locked) return ['No lock', 'bad'];
|
||||
if (snr == null) return ['Locked', 'ok'];
|
||||
// DVB-T2 256-QAM needs ~20 dB, DVB-T 64-QAM ~18 dB
|
||||
if (snr >= 26) return ['Excellent', 'ok'];
|
||||
if (snr >= 21) return ['Good', 'ok'];
|
||||
if (snr >= 17) return ['Fair', 'warn'];
|
||||
return ['Weak', 'bad'];
|
||||
}
|
||||
function pick() {
|
||||
var adOpts = adapters.map(function (a) { return '<option value="' + esc(a.id) + '"' + (a.id === sel ? ' selected' : '') + '>' + esc(a.id + ' · ' + a.name) + '</option>'; }).join('');
|
||||
var muxOpts = muxes.map(function (m) { return '<option value="' + m.id + '">' + esc(m.description + (m.network_name ? ' · ' + m.network_name : '')) + '</option>'; }).join('');
|
||||
$('#sg-pick').innerHTML = '<label>' + esc(T('Tuner')) + '<select id="sg-ad">' + adOpts + '</select></label>' +
|
||||
(isAdmin() && muxes.length ? '<label>' + esc(T('Tune multiplex')) + '<select id="sg-mux"><option value="">–</option>' + muxOpts + '</select></label>' +
|
||||
'<button class="btn" id="sg-tune">' + esc(T('Tune')) + '</button>' : '');
|
||||
$('#sg-ad').addEventListener('change', function () { sel = $('#sg-ad').value; SDVB_STORE.set('sdvb-sigad', sel); hist = { t: [], snr: [], str: [] }; });
|
||||
var tb = $('#sg-tune');
|
||||
if (tb) tb.addEventListener('click', function () {
|
||||
var id = +$('#sg-mux').value;
|
||||
if (!id) return;
|
||||
release();
|
||||
api('POST', '/api/signal/hold', { mux_id: id, seconds: 90 }).then(function () {
|
||||
holdMux = id; hist = { t: [], snr: [], str: [] };
|
||||
toast(T('Tuning…'));
|
||||
holdTimer = setInterval(function () { api('POST', '/api/signal/hold', { mux_id: id, seconds: 90 }).catch(function () {}); }, 60000);
|
||||
}).catch(fail);
|
||||
});
|
||||
}
|
||||
function release() {
|
||||
if (holdTimer) { clearInterval(holdTimer); holdTimer = null; }
|
||||
if (holdMux) { api('POST', '/api/signal/hold', { mux_id: holdMux, seconds: 0 }).catch(function () {}); holdMux = null; }
|
||||
}
|
||||
function beep() {
|
||||
// satellite-finder style: the better the SNR, the faster and higher the beeps
|
||||
if (!$('#sg-sound') || !$('#sg-sound').checked || lastSnr == null) { beepTimer = setTimeout(beep, 500); return; }
|
||||
try {
|
||||
audio = audio || new (window.AudioContext || window.webkitAudioContext)();
|
||||
var o = audio.createOscillator(), g = audio.createGain();
|
||||
o.frequency.value = 300 + Math.max(0, Math.min(35, lastSnr)) * 30;
|
||||
g.gain.value = 0.08;
|
||||
o.connect(g); g.connect(audio.destination);
|
||||
o.start(); o.stop(audio.currentTime + 0.06);
|
||||
} catch (e) {}
|
||||
beepTimer = setTimeout(beep, Math.max(90, 1100 - Math.max(0, lastSnr) * 30));
|
||||
}
|
||||
function render(a) {
|
||||
var act = a && a.active, sig = act && act.signal;
|
||||
if (!a) { $('#sg-body').innerHTML = '<div class="panel"><div class="empty">' + esc(T('No DVB adapters detected.')) + '</div></div>'; return; }
|
||||
if (!sig) {
|
||||
lastSnr = null;
|
||||
$('#sg-body').innerHTML = '<div class="panel"><div class="empty">' + esc(T('The tuner is idle. Start watching a channel or pick a multiplex above and press “Tune”.')) + '</div></div>';
|
||||
return;
|
||||
}
|
||||
var q = quality(sig.snr_db, sig.locked);
|
||||
lastSnr = sig.locked ? sig.snr_db : null;
|
||||
hist.t.push(now()); hist.snr.push(sig.snr_db); hist.str.push(sig.strength_pct);
|
||||
if (hist.t.length > 120) { hist.t.shift(); hist.snr.shift(); hist.str.shift(); }
|
||||
var snrPct = sig.snr_db != null ? Math.min(100, Math.max(0, sig.snr_db * 100 / 32)) : (sig.snr_pct || 0);
|
||||
$('#sg-body').innerHTML =
|
||||
'<div class="panel sg-main"><div class="sg-verdict ' + q[1] + '">' + esc(T(q[0])) + '</div>' +
|
||||
'<div class="sg-mux mono muted">' + esc(act.tuning) + '</div>' +
|
||||
'<div class="sg-grid">' +
|
||||
'<div><div class="label">' + esc(T('Strength')) + '</div><div class="sg-big">' + (sig.strength_pct != null ? sig.strength_pct.toFixed(0) + '<small>%</small>' : '–') + '</div>' +
|
||||
'<div class="meter ' + (sig.strength_pct > 50 ? 'good' : sig.strength_pct > 25 ? '' : 'bad') + '"><i style="width:' + (sig.strength_pct || 0) + '%"></i></div>' +
|
||||
'<div class="mono small muted">' + (sig.strength_dbm != null ? sig.strength_dbm.toFixed(1) + ' dBm' : ' ') + '</div></div>' +
|
||||
'<div><div class="label">SNR</div><div class="sg-big">' + (sig.snr_db != null ? sig.snr_db.toFixed(1) + '<small>dB</small>' : sig.snr_pct != null ? sig.snr_pct.toFixed(0) + '<small>%</small>' : '–') + '</div>' +
|
||||
'<div class="meter blue"><i style="width:' + snrPct + '%"></i></div><div class="mono small muted">' + (sig.ber != null ? 'BER ' + esc(fmtNum(sig.ber, 'ber')) : ' ') + '</div></div>' +
|
||||
'</div>' + lockBits(sig) +
|
||||
'<div class="kv" style="margin-top:8px"><span>' + esc(T('Uncorrected blocks')) + '</span><span class="mono">' + (sig.uncorrected != null ? sig.uncorrected : '–') + '</span>' +
|
||||
'<span>' + esc(T('Stream errors')) + '</span><span class="mono">CC ' + act.ts.cc_errors + ' · TEI ' + act.ts.tei_errors + '</span>' +
|
||||
'<span>' + esc(T('Multiplex bitrate')) + '</span><span class="mono">' + bps(act.bitrate_bps) + '</span></div></div>' +
|
||||
'<div class="grid g2" style="margin-top:10px">' +
|
||||
chartCard('sg-snr', 'SNR', [{ name: 'SNR', values: hist.snr }], hist.t, { unit: 'dB', min: 0, floor: 10, noArea: true }) +
|
||||
chartCard('sg-str', 'Signal strength', [{ name: '%', values: hist.str }], hist.t, { unit: '%', min: 0, max: 100 }) + '</div>';
|
||||
}
|
||||
function poll() {
|
||||
api('GET', '/api/adapters').then(function (list) {
|
||||
var changed = list.length !== adapters.length;
|
||||
adapters = list;
|
||||
if (!sel || !list.some(function (a) { return a.id === sel; })) {
|
||||
var busy = list.filter(function (a) { return a.active; })[0];
|
||||
sel = (busy || list[0] || {}).id || '';
|
||||
changed = true;
|
||||
}
|
||||
if (changed) pick();
|
||||
render(list.filter(function (a) { return a.id === sel; })[0]);
|
||||
}).catch(function () {});
|
||||
}
|
||||
api('GET', '/api/muxes').then(function (m) { muxes = m.filter(function (x) { return x.enabled; }); pick(); }).catch(function () {});
|
||||
every(1000, poll);
|
||||
beep();
|
||||
app.cleanup.push(function () { release(); clearTimeout(beepTimer); if (audio) try { audio.close(); } catch (e) {} });
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ STATISTICS
|
||||
function pageStats(view) {
|
||||
var days = +(SDVB_STORE.get('sdvb-statdays') || 7);
|
||||
view.innerHTML = head('Viewing', 'Statistics', 'What is watched, by whom, on which devices and when. Sessions shorter than 10 s (zapping) are not counted.',
|
||||
'<div class="seg" id="st-days">' + [[1, '24 h'], [7, '7 days'], [30, '30 days'], [365, 'year']].map(function (d) {
|
||||
return '<button data-d="' + d[0] + '"' + (d[0] === days ? ' class="on"' : '') + '>' + esc(T(d[1])) + '</button>';
|
||||
}).join('') + '</div>' + (isAdmin() ? '<button class="btn small danger" id="st-clear">' + esc(T('Clear history')) + '</button>' : '')) +
|
||||
'<div id="st-body"></div>';
|
||||
function hours(sec) {
|
||||
if (sec < 3600) return Math.round(sec / 60) + ' min';
|
||||
return (sec / 3600).toFixed(sec < 36000 ? 1 : 0) + ' h';
|
||||
}
|
||||
function barList(title, rows, total) {
|
||||
return '<div class="panel"><header><h2>' + esc(T(title)) + '</h2></header>' + (rows.length ? '<div class="bar-list">' + rows.map(function (r) {
|
||||
var pct = total ? r.seconds * 100 / total : 0;
|
||||
return '<div class="bl-row"><div class="bl-name" title="' + esc(r.name) + '">' + esc(r.name || '?') + '</div><div class="bl-bar"><i style="width:' + pct.toFixed(1) + '%"></i></div>' +
|
||||
'<div class="bl-val mono">' + hours(r.seconds) + '</div><div class="bl-sub mono muted">' + r.sessions + ' ' + esc(T('sessions')) + ' · ' + bytes(r.bytes) + '</div></div>';
|
||||
}).join('') + '</div>' : '<div class="empty">' + esc(T('No viewing yet in this period.')) + '</div>') + '</div>';
|
||||
}
|
||||
function columns(title, values, labels) {
|
||||
var max = Math.max.apply(null, values.concat([1]));
|
||||
return '<div class="panel"><header><h2>' + esc(T(title)) + '</h2></header><div class="cols">' + values.map(function (v, i) {
|
||||
return '<div class="col" title="' + esc(labels[i] + ': ' + hours(v)) + '"><i style="height:' + (v * 100 / max).toFixed(1) + '%"></i><span>' + esc(labels[i]) + '</span></div>';
|
||||
}).join('') + '</div></div>';
|
||||
}
|
||||
function load() {
|
||||
api('GET', '/api/stats/viewing?days=' + days).then(function (r) {
|
||||
var t = r.total, top = r.channels[0];
|
||||
var hourLabels = r.hours.map(function (_, i) { return String(i); });
|
||||
var perDay = r.per_day.slice(-31);
|
||||
$('#st-body').innerHTML =
|
||||
'<div class="grid g4">' +
|
||||
'<div class="panel stat"><div class="label">' + esc(T('Watch time')) + '</div><div class="value">' + hours(t.seconds) + '</div><div class="sub">' + t.sessions + ' ' + esc(T('sessions')) + '</div></div>' +
|
||||
'<div class="panel stat"><div class="label">' + esc(T('Data sent')) + '</div><div class="value">' + bytes(t.bytes) + '</div><div class="sub">' + esc(r.protocols.map(function (p) { return p.name.toUpperCase() + ' ' + hours(p.seconds); }).join(' · ') || '–') + '</div></div>' +
|
||||
'<div class="panel stat"><div class="label">' + esc(T('Most watched')) + '</div><div class="value small-value">' + esc(top ? top.name : '–') + '</div><div class="sub">' + (top ? hours(top.seconds) : '') + '</div></div>' +
|
||||
'<div class="panel stat"><div class="label">' + esc(T('Viewers')) + '</div><div class="value">' + r.users.length + '</div><div class="sub">' + r.devices.length + ' ' + esc(T('devices')) + '</div></div>' +
|
||||
'</div><div class="grid g2" style="margin-top:10px">' +
|
||||
barList('Most watched channels', r.channels, t.seconds) +
|
||||
'<div>' + barList('Viewers', r.users, t.seconds) + barList('Devices', r.devices, t.seconds) + '</div>' +
|
||||
columns('Time of day', r.hours, hourLabels) +
|
||||
(perDay.length > 1 ? columns('Per day', perDay.map(function (d) { return d.seconds; }), perDay.map(function (d) { return d.day.slice(5); })) : '') +
|
||||
'</div>';
|
||||
}).catch(function (e) {
|
||||
$('#st-body').innerHTML = '<div class="panel"><div class="empty">' + esc(isAdmin() ? e.message : T('Administrators only.')) + '</div></div>';
|
||||
});
|
||||
}
|
||||
$$('[data-d]', view).forEach(function (b) {
|
||||
b.addEventListener('click', function () {
|
||||
days = +b.getAttribute('data-d'); SDVB_STORE.set('sdvb-statdays', String(days));
|
||||
$$('[data-d]', view).forEach(function (x) { x.classList.toggle('on', x === b); });
|
||||
load();
|
||||
});
|
||||
});
|
||||
var cl = $('#st-clear');
|
||||
if (cl) cl.addEventListener('click', function () {
|
||||
if (confirmBox('Delete the whole viewing history?')) api('DELETE', '/api/stats/viewing').then(function () { toast('History cleared'); load(); }).catch(fail);
|
||||
});
|
||||
load();
|
||||
every(30000, load);
|
||||
}
|
||||
|
||||
/** Your account: password and the browsers/devices signed in (admins: everybody's). */
|
||||
function renderAccount() {
|
||||
var box = $('#account');
|
||||
if (!box || !app.me) return;
|
||||
var all = box.getAttribute('data-all') === '1', expanded = box.getAttribute('data-more') === '1';
|
||||
api('GET', '/api/me/sessions' + (all ? '?all=1' : '')).then(function (full) {
|
||||
var list = expanded ? full : full.slice(0, 6);
|
||||
box.innerHTML = '<header><h2>' + esc(T('Signed-in devices')) + '</h2><div class="actions">' +
|
||||
(full.filter(function (x) { return !x.current && (!all || x.user === app.me.username); }).length ? '<button class="btn small" id="acc-others">' + esc(T('Sign out other devices')) + '</button>' : '') + '</div></header>' +
|
||||
'<div class="section-head"><span class="small muted">' + esc(T('Browsers and apps signed in to the panel. Signing a device out ends its session immediately.')) + '</span>' +
|
||||
(isAdmin() ? '<label class="check small"><input type="checkbox" id="acc-all"' + (all ? ' checked' : '') + '> ' + esc(T('all users')) + '</label>' : '') + '</div>' +
|
||||
'<div class="table-wrap"><table><thead><tr>' + (all ? '<th>' + esc(T('User')) + '</th>' : '') + '<th>' + esc(T('Device')) + '</th><th>' + esc(T('Address')) + '</th><th>' + esc(T('Last active')) + '</th><th>' + esc(T('Signed in')) + '</th><th></th></tr></thead><tbody>' +
|
||||
list.map(function (x) {
|
||||
return '<tr>' + (all ? '<td>' + esc(x.user) + '</td>' : '') + '<td title="' + esc(x.user_agent) + '">' + esc(x.device || '?') + (x.current ? ' <span class="pill ok">' + esc(T('this device')) + '</span>' : '') + '</td>' +
|
||||
'<td class="mono small">' + esc(x.ip) + '</td><td class="mono small">' + dt(x.last_seen) + '</td><td class="mono small">' + dt(x.created) + '</td>' +
|
||||
'<td class="actions-cell">' + (x.current ? '' : '<button class="btn small" data-sess="' + esc(x.id) + '">' + esc(T('Sign out')) + '</button>') + '</td></tr>';
|
||||
}).join('') + '</tbody></table></div>' +
|
||||
(full.length > list.length ? '<button class="btn small ghost" id="acc-more">' + esc(T('Show all')) + ' (' + full.length + ')</button>' : '');
|
||||
var more = $('#acc-more', box);
|
||||
if (more) more.addEventListener('click', function () { box.setAttribute('data-more', '1'); renderAccount(); });
|
||||
var ot = $('#acc-others', box);
|
||||
if (ot) ot.addEventListener('click', function () {
|
||||
api('POST', '/api/me/sessions/others').then(function (r) { toast(T('Signed out devices:') + ' ' + r.ended); renderAccount(); }).catch(fail);
|
||||
});
|
||||
var al = $('#acc-all', box);
|
||||
if (al) al.addEventListener('change', function () { box.setAttribute('data-all', al.checked ? '1' : '0'); renderAccount(); });
|
||||
$$('[data-sess]', box).forEach(function (b) {
|
||||
b.addEventListener('click', function () {
|
||||
api('DELETE', '/api/me/sessions/' + b.getAttribute('data-sess')).then(function () { toast('Signed out'); renderAccount(); }).catch(fail);
|
||||
});
|
||||
});
|
||||
}).catch(fail);
|
||||
}
|
||||
|
||||
function pageSettings(view, args) {
|
||||
var SECTIONS = [['appearance', 'Appearance'], ['general', 'General'], ['streaming', 'Streaming'], ['epg', 'EPG & icons'], ['recording', 'Recording'], ['tuners', 'Scanning']].concat(isAdmin() ? [['maintenance', 'Backup & monitoring']] : []);
|
||||
var sec = SECTIONS.some(function (x) { return x[0] === args[0]; }) ? args[0] : 'appearance';
|
||||
view.innerHTML = head('Configuration', 'Settings', 'Changes apply immediately (to new stream sessions).', isAdmin() ? '<button class="btn primary" id="set-save">Save settings</button>' : '') +
|
||||
'<div class="panel" id="prefs"></div><div id="set-body"></div>';
|
||||
'<div class="tabs set-tabs" id="set-tabs">' + SECTIONS.map(function (x) { return '<button data-sec="' + x[0] + '"' + (x[0] === sec ? ' class="active"' : '') + '>' + esc(T(x[1])) + '</button>'; }).join('') + '</div>' +
|
||||
'<div class="panel" id="prefs" data-sec="appearance"></div><div id="set-body"></div>';
|
||||
function showSection() {
|
||||
$$('[data-sec]', view).forEach(function (el) {
|
||||
if (el.parentNode && el.parentNode.id === 'set-tabs') el.classList.toggle('active', el.getAttribute('data-sec') === sec);
|
||||
else el.classList.toggle('hidden', el.getAttribute('data-sec') !== sec);
|
||||
});
|
||||
var sv = $('#set-save');
|
||||
if (sv) sv.classList.toggle('hidden', sec === 'appearance' || sec === 'maintenance');
|
||||
}
|
||||
$$('#set-tabs button', view).forEach(function (b) {
|
||||
b.addEventListener('click', function () {
|
||||
sec = b.getAttribute('data-sec');
|
||||
history.replaceState(null, '', '#/settings/' + sec);
|
||||
showSection();
|
||||
});
|
||||
});
|
||||
renderPrefs();
|
||||
showSection();
|
||||
var cur = null;
|
||||
function field(name, label, type, hint, extra) {
|
||||
var v = cur[name];
|
||||
@@ -1474,39 +1854,43 @@
|
||||
}
|
||||
function render() {
|
||||
$('#set-body').innerHTML =
|
||||
'<div class="panel"><header><h2>General</h2></header><div class="form-grid">' +
|
||||
'<div class="panel" data-sec="general"><header><h2>General</h2></header><div class="form-grid">' +
|
||||
field('server_name', 'Server name') + field('public_url', 'Public URL (for links)', 'text', 'e.g. https://tv.example.com – empty = from the Host header') +
|
||||
field('session_hours', 'Panel session lifetime (h)', 'number') + '</div></div>' +
|
||||
'<div class="panel"><header><h2>Streaming (HLS / TS)</h2></header><div class="form-grid">' +
|
||||
'<div class="panel" data-sec="streaming"><header><h2>Streaming (HLS / TS)</h2></header><div class="form-grid">' +
|
||||
field('hls_segment_seconds', 'HLS segment length (s)', 'number', 'Cut on keyframes – actual length depends on the broadcaster’s GOP') +
|
||||
field('hls_window', 'Segments in playlist', 'number') + field('hls_idle_seconds', 'Close idle HLS session after (s)', 'number') +
|
||||
field('tuner_linger_seconds', 'Keep tuner after last client (s)', 'number', 'Faster zapping between channels of the same mux') +
|
||||
field('tuner_pid_filter', 'Read only the PIDs clients need (less CPU)', 'bool', 'The kernel passes only the selected programmes and the EPG/SI tables instead of the whole multiplex. Turn off if a tuner driver misbehaves.') +
|
||||
field('m3u_format', 'Default M3U format', 'select', 'TS – lightest for TVs, HLS – for apps that require HLS', [['ts', 'MPEG-TS (continuous stream)'], ['hls', 'HLS (m3u8)']]) + '</div></div>' +
|
||||
'<div class="panel"><header><h2>Transcoding (ffmpeg)</h2></header><div class="form-grid">' + field('ffmpeg_path', 'ffmpeg path') +
|
||||
'<div class="panel" data-sec="streaming"><header><h2>Transcoding (ffmpeg)</h2></header><div class="form-grid">' + field('ffmpeg_path', 'ffmpeg path') +
|
||||
field('ffmpeg_h264_args', 'H.264 profile arguments', 'wide', 'Used by the “h264” profile (e.g. HEVC in browsers without a hardware decoder). Hardware acceleration can be added: -c:v h264_vaapi etc.') + '</div></div>' +
|
||||
'<div class="panel"><header><h2>EPG</h2>' + (isAdmin() ? '<div class="actions"><button class="btn small" id="xmltv-now">Import XMLTV now</button></div>' : '') + '</header><div class="form-grid">' +
|
||||
'<div class="panel" data-sec="epg"><header><h2>EPG</h2>' + (isAdmin() ? '<div class="actions"><button class="btn small" id="xmltv-now">Import XMLTV now</button></div>' : '') + '</header><div class="form-grid">' +
|
||||
field('epg_ota_enabled', 'Collect EPG from the broadcast (EIT)', 'bool', 'While watching and periodically from every mux') +
|
||||
field('epg_grab_interval_hours', 'Grab all muxes every (h)', 'number', '0 = only while watching') + field('epg_grab_seconds', 'Grab time per mux (s)', 'number') +
|
||||
field('epg_keep_past_hours', 'Keep past programmes (h)', 'number') + field('xmltv_interval_hours', 'Import XMLTV every (h)', 'number') +
|
||||
'<label class="full">XMLTV sources (one URL per line, .xml or .xml.gz)<textarea name="xmltv_sources" placeholder="https://epg.ovh/pl.xml">' + esc(cur.xmltv_sources.map(function (s) { return (s.enabled ? '' : '# ') + s.url; }).join('\n')) + '</textarea>' +
|
||||
'<span class="hint">Channels are matched by the channel’s “EPG ID” or by name. A line starting with # is disabled. XMLTV data takes precedence over EIT.</span></label>' +
|
||||
'<div class="full small muted" id="xmltv-status"></div></div></div>' +
|
||||
'<div class="panel"><header><h2>Channel icons</h2></header><div class="form-grid"><label class="full">Icon URL templates<textarea name="icon_sources">' + esc(cur.icon_sources.join('\n')) + '</textarea>' +
|
||||
'<div class="panel" data-sec="epg"><header><h2>Channel icons</h2></header><div class="form-grid"><label class="full">Icon URL templates<textarea name="icon_sources">' + esc(cur.icon_sources.join('\n')) + '</textarea>' +
|
||||
'<span class="hint">{slug} is replaced with the channel name, e.g. “tvp-1”, “polsat-news”. First hit wins; icons are stored locally.</span></label></div></div>' +
|
||||
'<div class="panel"><header><h2>Recording</h2></header><div class="form-grid">' + field('recordings_dir', 'Recordings directory', 'text', 'Empty = ' + cur.data_dir + '/recordings') +
|
||||
'<div class="panel" data-sec="recording"><header><h2>Recording</h2></header><div class="form-grid">' + field('recordings_dir', 'Recordings directory', 'text', 'Empty = ' + cur.data_dir + '/recordings') +
|
||||
field('recording_pre_padding_min', 'Padding before (min)', 'number') + field('recording_post_padding_min', 'Padding after (min)', 'number') +
|
||||
field('recordings_keep_days', 'Delete recordings older than (days)', 'number', '0 = never') +
|
||||
field('recordings_min_free_gb', 'Minimum free space (GiB)', 'number', 'Below this threshold the oldest recordings are deleted; 0 = disabled') + '</div></div>' +
|
||||
'<div class="panel"><header><h2>Scanning</h2></header><div class="form-grid">' + field('scan_create_channels', 'Create channels automatically', 'bool') +
|
||||
'<div class="panel" data-sec="tuners"><header><h2>Scanning</h2></header><div class="form-grid">' + field('scan_create_channels', 'Create channels automatically', 'bool') +
|
||||
field('scan_include_radio', 'Add radio stations', 'bool') + field('scan_include_scrambled', 'Add scrambled channels', 'bool') +
|
||||
field('scan_lock_timeout_ms', 'Lock timeout (ms)', 'number', 'Si2168 usually locks DVB-T2 within ~1–2 s') +
|
||||
field('idle_scan_hours', 'Background scan every (h)', 'number', 'Rescans saved muxes (and the NIT) on an idle adapter; stops as soon as someone starts watching or recording. 0 = off') +
|
||||
field('idle_scan_quiet_minutes', 'Start after all tuners are idle for (min)', 'number') +
|
||||
field('idle_scan_follow_nit', 'Background scan: follow the NIT to new muxes', 'bool') +
|
||||
field('idle_scan_create_channels', 'Background scan: create channels for new services', 'bool', 'Off = new services only appear in “Add from services”') + '</div></div>' +
|
||||
(isAdmin() ? '<div class="panel"><header><h2>Backup</h2></header><p class="hint">Muxes, services, channels (order, groups, links), recording rules, tokens and settings. Without user accounts, EPG, icons and recording files.</p>' +
|
||||
'<div class="row"><a class="btn" href="/api/backup" download>⤓ Download backup (JSON)</a><label class="btn">⤒ Restore from file<input type="file" id="restore-file" accept="application/json,.json" class="hidden"></label>' +
|
||||
'<a class="btn ghost" href="/metrics" target="_blank">Prometheus metrics</a></div></div>' : '');
|
||||
(isAdmin() ? '<div class="panel" data-sec="maintenance"><header><h2>Backup</h2></header><p class="hint">Muxes, services, channels (order, groups, links), recording rules, tokens and settings. Without user accounts, EPG, icons and recording files.</p><p class="hint">Full database copy: everything incl. users, EPG and statistics – restore it with <code>simply-dvb db restore <file></code>.</p>' +
|
||||
'<div class="row"><a class="btn" href="/api/backup" download>' + ico('download') + 'Download backup (JSON)</a><a class="btn" href="/api/backup/database" download>' + ico('download') + 'Full database copy</a><label class="btn">' + ico('upload') + 'Restore from file<input type="file" id="restore-file" accept="application/json,.json" class="hidden"></label></div></div>' +
|
||||
'<div class="panel" data-sec="maintenance"><header><h2>Monitoring (Prometheus)</h2></header>' +
|
||||
'<p class="hint">Metrics for Prometheus/Grafana: tuners (signal, SNR, errors, bitrate), clients, traffic, recordings and the process. Add this address as a scrape target.</p>' +
|
||||
'<div class="copy-row"><code>' + esc(location.origin + '/metrics') + '</code><a class="btn small" href="/metrics" target="_blank">' + esc(T('Open')) + '</a></div></div>' : '');
|
||||
showSection();
|
||||
api('GET', '/api/epg/status').then(function (s) {
|
||||
var e = $('#xmltv-status');
|
||||
if (e) e.textContent = (s.status.last_xmltv ? T('Last XMLTV import:') + ' ' + dt(s.status.last_xmltv) + '\n' + T(s.status.xmltv_result || '') : '') + ' · ' + T('programmes in database:') + ' ' + s.events;
|
||||
|
||||
Reference in new issue
Block a user