66 lines
3.2 KiB
JavaScript
66 lines
3.2 KiB
JavaScript
/* ── Series episode selector ──────────────────────────────────── */
|
|
/* TITLE, COVER, SEASONS injected by server as window vars before this script */
|
|
|
|
var tabs = document.getElementById('tabs');
|
|
var sdiv = document.getElementById('seasons');
|
|
|
|
Object.keys(SEASONS).sort(function(a,b){return +a-+b;}).forEach(function(s) {
|
|
var btn = document.createElement('button');
|
|
btn.className = 'btn b'; btn.textContent = 'S' + s.padStart(2,'0');
|
|
btn.style.marginRight = '6px';
|
|
btn.onclick = function() { showSeason(s); };
|
|
tabs.appendChild(btn);
|
|
|
|
var div = document.createElement('div'); div.id = 's-' + s; div.style.display = 'none';
|
|
var html = '<div style="margin:8px 0">'
|
|
+ '<button class="btn btn-s" onclick="selAll(\'' + s + '\',true)">All S' + s.padStart(2,'0') + '</button> '
|
|
+ '<button class="btn g" onclick="dlSeason(\'' + s + '\')" style="margin-left:6px">⬇ Season ' + s + '</button></div>';
|
|
html += '<table><tr><th><input type=checkbox onchange="selAll(\'' + s + '\',this.checked)"></th>'
|
|
+ '<th>Ep</th><th>Title</th><th>Duration</th></tr>';
|
|
SEASONS[s].forEach(function(e) {
|
|
var epn = e.episode_num || e.episodeNum || '?';
|
|
var dur = (e.info && e.info.duration) || '';
|
|
var ext = e.container_extension || 'mp4';
|
|
html += '<tr>'
|
|
+ '<td><input type=checkbox class="ep-cb s-cb-' + s + '" data-id="' + e.id + '" data-ep="' + epn + '" data-s="' + s + '" data-ext="' + ext + '"></td>'
|
|
+ '<td>E' + String(epn).padStart(2,'0') + '</td>'
|
|
+ '<td>' + (e.title||'') + '</td>'
|
|
+ '<td>' + dur + '</td></tr>';
|
|
});
|
|
html += '</table>';
|
|
div.innerHTML = html;
|
|
sdiv.appendChild(div);
|
|
});
|
|
|
|
var firstS = Object.keys(SEASONS).sort(function(a,b){return +a-+b;})[0];
|
|
if (firstS) showSeason(firstS);
|
|
|
|
function showSeason(s) {
|
|
document.querySelectorAll('[id^=s-]').forEach(function(d) { d.style.display = 'none'; });
|
|
var d = document.getElementById('s-' + s); if (d) d.style.display = '';
|
|
}
|
|
|
|
function selAll(s, v) {
|
|
var all = Array.from(document.querySelectorAll('.s-cb-' + s));
|
|
var checked = v === undefined ? !all.every(function(x){return x.checked;}) : v;
|
|
all.forEach(function(c) { c.checked = checked; });
|
|
}
|
|
|
|
function dlSeason(s) { selAll(s, true); dlSelected(); }
|
|
|
|
function dlSelected() {
|
|
var eps = Array.from(document.querySelectorAll('.ep-cb:checked')).map(function(c) {
|
|
return {id: c.dataset.id, ep: c.dataset.ep, s: c.dataset.s, ext: c.dataset.ext};
|
|
});
|
|
if (!eps.length) { alert('Select episodes first'); return; }
|
|
var bySeason = {};
|
|
eps.forEach(function(e) { (bySeason[e.s] = bySeason[e.s]||[]).push({id:e.id, episode_num:e.ep, ext:e.ext}); });
|
|
Promise.all(Object.keys(bySeason).map(function(s) {
|
|
return fetch(BASE + '/api/download', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({episodes: bySeason[s], series_title: TITLE, season: s, cover_url: COVER})
|
|
}).then(function(r) { return r.json(); });
|
|
})).then(function() { alert('Queued!'); location.href = BASE + '/downloads'; });
|
|
}
|