mirror of
https://gitlab.com/vyla-entertainment/TV.git
synced 2026-11-20 06:57:22 -05:00
rewrote the entire app using jetpack compose, and exoplayer/media3 for playback
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
function hero(it) { clearTimeout(ht); ht = setTimeout(() => applyHero(it), 130) }
|
||||
async function applyHero(it) {
|
||||
if (heroIt === it) return; heroIt = it; $('.hc').classList.remove('sl');
|
||||
const bp = it.backdrop_path || it.poster_path;
|
||||
xf(bgb, I + 'w780' + bp); xf(hb, I + 'w1280' + bp);
|
||||
const t = it.title || it.name;
|
||||
$('#hlogo').innerHTML = `<h1>${t}</h1>`;
|
||||
$('#hmeta').innerHTML = `<span>★ ${(it.vote_average || 0).toFixed(1)}</span><span>${yr(it)}</span><span class="b">${it._t === 'movie' ? 'Movie' : 'Series'}</span><span>${gn(it)}</span>`;
|
||||
$('#hov').textContent = it.overview || '';
|
||||
const l = await logo(it);
|
||||
if (heroIt === it && l) $('#hlogo').innerHTML = `<img src="${l}" alt="${t.replace(/"/g, '')}">`
|
||||
}
|
||||
|
||||
function card(it, h = true) {
|
||||
const c = document.createElement('div'); c.className = 'card f'; c.tabIndex = -1;
|
||||
c.innerHTML = `<img loading="lazy" src="${I}w342${it.poster_path}" alt="">`;
|
||||
if (h) c._it = it; c._a = () => openDetail(it); return c
|
||||
}
|
||||
|
||||
function mkRow(i) {
|
||||
const mv = mode === "movie" || (mode === "discover" && i % 2 === 0), k = mode === "discover" ? i >> 1 : i, list = mv ? MG : TG, g = list[k % list.length], pg = 1 + Math.floor(k / list.length) % 20;
|
||||
const sec = document.createElement('section'); sec.className = 'sec';
|
||||
sec.innerHTML = `<h2>${g.name} ${mv ? 'Movies' : 'TV Shows'}</h2><div class="row">${SK.cards(14)}</div>`;
|
||||
rowsEl.appendChild(sec);
|
||||
return api(`/discover/${mv ? 'movie' : 'tv'}`, `&with_genres=${g.id}&sort_by=popularity.desc&vote_count.gte=100&include_adult=false&page=${pg}`).then(d => {
|
||||
const rs = (d.results || []).filter(x => x.poster_path);
|
||||
if (!rs.length) { sec.remove(); return }
|
||||
sec.lastChild.innerHTML = ''; rs.forEach(x => { x._t = mv ? 'movie' : 'tv'; sec.lastChild.appendChild(card(x)) })
|
||||
})
|
||||
}
|
||||
|
||||
async function more(n) {
|
||||
if (busy) return; busy = true; const g = gen;
|
||||
const ps = []; for (let j = 0; j < n; j++)ps.push(mkRow(idx++));
|
||||
await Promise.all(ps); if (g === gen) busy = false
|
||||
}
|
||||
|
||||
async function go(k) {
|
||||
if (k === 'search') { closeLib(true); openSearch(); return }
|
||||
closeSearch(true);
|
||||
if (k === 'wl' || k === 'fav') { openLib(k); return }
|
||||
closeLib(true);
|
||||
if (k === mode && rowsEl.children.length) { setAct(k); setFocus(document.querySelector('#rows .card')); return }
|
||||
mode = k; setAct(k); gen++; busy = false; idx = 0; heroIt = null; lastMain = null; rowsEl.innerHTML = ''; main.scrollTop = 0; $('.hc').classList.add('sl');
|
||||
await more(6);
|
||||
const first = document.querySelector('#rows .card');
|
||||
if (first) { applyHero(first._it); setFocus(first) }
|
||||
}
|
||||
|
||||
main.addEventListener('scroll', () => {
|
||||
const h = innerHeight;
|
||||
$('#dim2').style.opacity = Math.min(main.scrollTop / (h * .6), 1) * .55;
|
||||
if (main.scrollTop + h * 2.5 > main.scrollHeight) more(4)
|
||||
});
|
||||
|
||||
$('#hplay')._a = () => openPlayer(heroIt);
|
||||
$('#hinfo')._a = () => heroIt && openDetail(heroIt);
|
||||
@@ -1,37 +0,0 @@
|
||||
const API_BASE = window.API_BASE || localStorage.getItem('vyla.api') || '';
|
||||
|
||||
const K = '3f6703f3e2a0b2b40fe4fbb3e1546244', A = 'https://api.themoviedb.org/3', I = 'https://image.tmdb.org/t/p/';
|
||||
const $ = s => document.querySelector(s);
|
||||
const main = $('#main'), rowsEl = $('#rows'), side = $('#side'), ov = $('#ov'), bgb = $('#bg'), hb = $('#hb'), sr = $('#sr'), sres = $('#sres'), chips = $('#chips'), tabs = $('#tabs'), kb = $('#kb'), pl = $('#pl'), vd = $('#pv');
|
||||
const api = async (p, q = '') => { try { const r = await fetch(`${A}${p}?api_key=${K}&language=en-US${q}`); return r.ok ? await r.json() : {} } catch (e) { return {} } };
|
||||
const ic = p => `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${p}</svg>`;
|
||||
const P_WL = '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>', P_FV = '<path d="M20.8 5.6a5.5 5.5 0 0 0-7.8 0L12 6.7l-1-1.1a5.5 5.5 0 0 0-7.8 7.8l1 1.1L12 22l7.8-7.5 1-1.1a5.5 5.5 0 0 0 0-7.8z"/>';
|
||||
const LN = { wl: 'Watch Later', fav: 'Favorites' };
|
||||
const NAVEL = {}; let navAct = null, mode = '', gen = 0, sgen = 0, st;
|
||||
let fast = false, G = {}, MG = [], TG = [], cur = null, lastMain = null, heroIt = null, idx = 0, busy = false, ht;
|
||||
const LC = {};
|
||||
|
||||
function xf(box, url, cls = 'xf') {
|
||||
if (box._u === url) return; box._u = url;
|
||||
const im = new Image();
|
||||
im.onload = () => { if (box._u !== url) return; const d = document.createElement('div'); d.className = cls; d.style.backgroundImage = `url(${url})`; box.appendChild(d); requestAnimationFrame(() => requestAnimationFrame(() => d.classList.add('in'))); setTimeout(() => { while (box.children.length > 2) box.firstChild.remove() }, 800) };
|
||||
im.onerror = () => { if (box._u === url) box._u = null };
|
||||
im.src = url
|
||||
}
|
||||
|
||||
async function logo(it) {
|
||||
const k = it._t + it.id; if (k in LC) return LC[k];
|
||||
const d = await api(`/${it._t}/${it.id}/images`, '&include_image_language=en,null');
|
||||
const l = (d.logos || []).find(x => x.iso_639_1 === 'en') || (d.logos || [])[0];
|
||||
return LC[k] = l ? I + 'w500' + l.file_path : null
|
||||
}
|
||||
|
||||
const yr = it => ((it.release_date || it.first_air_date || '') + '').slice(0, 4);
|
||||
const gn = it => (it.genre_ids || []).map(i => G[i]).filter(Boolean).slice(0, 2).join(', ');
|
||||
|
||||
const esc = t => String(t).replace(/</g, '<');
|
||||
const mkf = (cls, html, fn) => { const e = document.createElement('div'); e.className = cls + ' f'; e.tabIndex = -1; e.innerHTML = html; e._a = fn; return e };
|
||||
const LOGO = 'assets/favicon.ico', PH = 'data:image/svg+xml,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><rect width="40" height="40" rx="11" fill="#2a2a34"/><circle cx="14" cy="14" r="3" fill="#5b5b6b"/><path d="M7 31l9-10 6 6 4-4 7 8z" fill="#5b5b6b"/></svg>');
|
||||
function toast(m) { const t = document.createElement('div'); t.className = 'toast'; t.textContent = m; (document.fullscreenElement || document.body).appendChild(t); setTimeout(() => t.remove(), 2300) }
|
||||
const imgDone = e => { const t = e.target; if (t.tagName === 'IMG') { t.classList.add('ld'); t.parentElement && t.parentElement.classList.add('lded') } };
|
||||
document.addEventListener('load', imgDone, true); document.addEventListener('error', imgDone, true);
|
||||
@@ -1,66 +0,0 @@
|
||||
let dgen = 0;
|
||||
async function openDetail(it) {
|
||||
const t = it._t;
|
||||
if (!ov.classList.contains('show')) ov._prev = cur;
|
||||
ov.classList.add('show'); side.classList.remove('open'); const my = ++dgen; ov.innerHTML = `<div class="pic f" id="dback">${ic('<path d="M19 12H5M12 19l-7-7 7-7"/>')}</div>` + SK.detail(it); $('#dback')._a = closeDetail; ov.scrollTop = 0;
|
||||
const d = await api(`/${t}/${it.id}`, `&append_to_response=videos,credits,recommendations,images,${t === 'movie' ? 'release_dates' : 'content_ratings'}&include_image_language=en,null`);
|
||||
if (my !== dgen || !ov.classList.contains('show')) return;
|
||||
if (!d.id) { closeDetail(); return }
|
||||
const title = d.title || d.name, year = ((d.release_date || d.first_air_date) || '').slice(0, 4);
|
||||
const cert = t === 'movie' ? (((d.release_dates || {}).results || []).find(r => r.iso_3166_1 === 'US') || { release_dates: [] }).release_dates.map(x => x.certification).find(Boolean) : (((d.content_ratings || {}).results || []).find(r => r.iso_3166_1 === 'US') || {}).rating;
|
||||
const rt = t === 'movie' ? (d.runtime ? `${Math.floor(d.runtime / 60)}h ${d.runtime % 60}m` : '') : (d.number_of_seasons ? `${d.number_of_seasons} Season${d.number_of_seasons > 1 ? 's' : ''}` : '');
|
||||
const lg = ((d.images || {}).logos || []).find(x => x.iso_639_1 === 'en') || ((d.images || {}).logos || [])[0];
|
||||
const bp = d.backdrop_path || d.poster_path;
|
||||
ov.innerHTML = `<div class="pic f" id="dback">${ic('<path d="M19 12H5M12 19l-7-7 7-7"/>')}</div><div class="dbl" style="background-image:url(${I}w780${bp})"></div><div class="dw"><div class="dimg" style="background-image:url(${I}w1280${bp})"></div><div class="dc"><div class="dh"><div id="dlogo">${lg ? `<img src="${I}w500${lg.file_path}" alt="">` : `<h1>${title}</h1>`}</div><div class="meta"><span>${(d.vote_average || 0).toFixed(1)}</span><span>${year}</span>${cert ? `<span class="b">${cert}</span>` : ''}<span>${rt}</span><span>${(d.genres || []).slice(0, 3).map(g => g.name).join(', ')}</span></div><div class="hb"><button class="pb f" id="dplay">Play</button><div class="circ f" id="dmenu">⋮</div><div class="mx" id="dmx"><div class="circ f" id="dwl"></div><div class="circ f" id="dfv"></div></div></div><p class="otx" id="otx">${d.overview || ''}</p><span class="more f" id="dmore">MORE</span></div><div id="dsecs"></div></div></div>`;
|
||||
$('#dback')._a = closeDetail; const secs = $('#dsecs');
|
||||
const rowOf = (name, kids) => { if (!kids.length) return; const s = document.createElement('section'); s.className = 'ds'; s.innerHTML = `<h3>${name}</h3><div class="row"></div>`; s.lastChild.append(...kids); secs.appendChild(s) };
|
||||
const el = (c, h) => { const e = document.createElement('div'); e.className = c + ' f'; e.tabIndex = -1; e.innerHTML = h; e._a = () => { }; return e };
|
||||
if (t === 'tv') {
|
||||
const ss = (d.seasons || []).filter(x => x.season_number > 0 && x.episode_count);
|
||||
if (ss.length) {
|
||||
const sec = document.createElement('section'); sec.className = 'ds eps';
|
||||
sec.innerHTML = '<div class="eh"><h3>Episodes</h3><div class="dd"><div class="ddb f" id="ddb"></div><div class="ddl" id="ddl"></div></div></div><div class="el" id="el"></div>';
|
||||
secs.appendChild(sec);
|
||||
const ddb = $('#ddb'), ddl = $('#ddl'), list = $('#el'); let cs = null;
|
||||
const nm = x => x.name || 'Season ' + x.season_number;
|
||||
const loadEps = async x => {
|
||||
cs = x; ddb.innerHTML = `<span>${esc(nm(x))}</span>` + ic('<path d="m6 9 6 6 6-6"/>');
|
||||
[...ddl.children].forEach((c, i) => c.classList.toggle('cur', ss[i] === x));
|
||||
list.innerHTML = SK.eps(10);
|
||||
const r = await api(`/tv/${it.id}/season/${x.season_number}`);
|
||||
if (cs !== x || !list.isConnected) return;
|
||||
list.innerHTML = '';
|
||||
(r.episodes || []).forEach((p, ix) => {
|
||||
const n = p.episode_number, img = p.still_path ? I + 'w300' + p.still_path : (it.backdrop_path ? I + 'w300' + it.backdrop_path : PH);
|
||||
const e = el('ep', `<div class="et"><img loading="lazy" src="${img}" alt=""></div><b>${esc(p.name || 'Episode ' + n)}</b><small>${['Episode ' + n, p.runtime ? p.runtime + 'm' : ''].filter(Boolean).join(' \u2022 ')}</small>`);
|
||||
e.title = p.overview || '';
|
||||
e._a = () => openPlayer(it, `S${x.season_number} E${n} \u2022 ${p.name || ''}`, { it, seasons: ss, s: x.season_number, eps: r.episodes, i: ix, cache: { [x.season_number]: r.episodes } }); list.appendChild(e)
|
||||
});
|
||||
const f0 = list.firstChild; if (f0 && f0._a && $('#dplay')) $('#dplay')._a = () => f0._a();
|
||||
if (!list.children.length) list.innerHTML = '<p class="none">No episodes listed.</p>'
|
||||
};
|
||||
ss.forEach(x => ddl.appendChild(mkf('ddi', `<span>${esc(nm(x))}</span><small>${x.episode_count} eps</small>`, () => { closeDD(); loadEps(x) })));
|
||||
ddb._a = () => { if (!closeDD()) { ddl.classList.add('open'); setFocus(ddl.children[Math.max(0, ss.indexOf(cs))]) } };
|
||||
loadEps(ss[0])
|
||||
}
|
||||
}
|
||||
rowOf('Trailers', ((d.videos || {}).results || []).filter(v => v.site === 'YouTube' && /Trailer|Teaser|Clip/.test(v.type)).sort((a, b) => (b.type === 'Trailer') - (a.type === 'Trailer')).slice(0, 8).map(v => el('tr', `<div class="tb" style="background-image:url(https://img.youtube.com/vi/${v.key}/mqdefault.jpg)"></div><div class="th" style="background-image:url(https://img.youtube.com/vi/${v.key}/mqdefault.jpg)"></div><b>${v.name}</b><small>▶ ${v.type}</small>`)));
|
||||
rowOf('Related', ((d.recommendations || {}).results || []).filter(x => x.poster_path).map(x => { x._t = t; return card(x, false) }));
|
||||
rowOf('Cast', ((d.credits || {}).cast || []).slice(0, 20).map(p => el('cs', `<div class="pf" style="${p.profile_path ? `background-image:url(${I}w185${p.profile_path})` : ''}">${p.profile_path ? '' : p.name[0]}</div><b>${p.name}</b><small>${p.character || ''}</small>`)));
|
||||
$('#dplay')._a = () => openPlayer(it); const sync = () => [['dwl', 'wl', P_WL], ['dfv', 'fav', P_FV]].forEach(([id, k, p]) => { const e = $('#' + id), v = has(k, it); e.classList.toggle('sv', v); e.dataset.l = (v ? 'Remove from ' : 'Add to ') + LN[k]; e.innerHTML = ic(p) });
|
||||
sync();
|
||||
$('#dmenu')._a = () => { const o = $('#dmx').classList.toggle('open'); $('#dmenu').classList.toggle('sv', o) };
|
||||
$('#dwl')._a = () => { toggleLib('wl', it); sync() }; $('#dfv')._a = () => { toggleLib('fav', it); sync() };
|
||||
$('#dmore')._a = () => { const o = $('#otx'), m = $('#dmore'); o.classList.toggle('x'); m.textContent = o.classList.contains('x') ? 'LESS' : 'MORE' };
|
||||
ov.scrollTop = 0;
|
||||
setFocus($('#dplay'))
|
||||
}
|
||||
|
||||
function closeDetail() {
|
||||
ov.classList.remove('show');
|
||||
const p = ov._prev;
|
||||
setTimeout(() => { if (!ov.classList.contains('show')) ov.innerHTML = '' }, 400);
|
||||
if (p && document.body.contains(p)) setFocus(p); else if (lib.classList.contains('show')) setFocus($('#lgrid .card') || navAct)
|
||||
}
|
||||
|
||||
function closeDD() { const l = $('#ddl'); if (l && l.classList.contains('open')) { l.classList.remove('open'); setFocus($('#ddb')); return true } return false }
|
||||
@@ -1,60 +0,0 @@
|
||||
function setFocus(el) {
|
||||
if (!el) return;
|
||||
const od = $('#ddl.open'); if (od && !el.closest('.dd')) od.classList.remove('open');
|
||||
cur && cur.classList.remove('on'); cur = el; el.classList.add('on');
|
||||
const inSide = !!el.closest('#side'), inOv = !!el.closest('#ov');
|
||||
side.classList.toggle('open', inSide && !ov.classList.contains('show'));
|
||||
if (!inSide && !inOv && !el.closest('#pl')) lastMain = el;
|
||||
const row = el.closest('.row');
|
||||
if (row) row.scrollTo({ left: Math.max(0, el.offsetLeft - parseInt(getComputedStyle(row).paddingLeft)), behavior: fast ? 'auto' : 'smooth' });
|
||||
|
||||
const menu = el.closest('#pm');
|
||||
if (menu) {
|
||||
el.scrollIntoView({ block: 'nearest', behavior: fast ? 'auto' : 'smooth' });
|
||||
return;
|
||||
}
|
||||
|
||||
const scr = el.closest('#ov,#sr,#lib');
|
||||
if (scr && el.closest('#kb,#chips,#tabs')) scr.scrollTo({ top: 0, behavior: fast ? 'auto' : 'smooth' });
|
||||
else if (scr) {
|
||||
const r = el.getBoundingClientRect();
|
||||
if (r.bottom > innerHeight - 50) scr.scrollBy({ top: r.bottom - innerHeight + 110, behavior: fast ? 'auto' : 'smooth' });
|
||||
else if (r.top < 50) scr.scrollBy({ top: r.top - 110, behavior: fast ? 'auto' : 'smooth' });
|
||||
}
|
||||
else if (!inSide && !el.closest('#pl')) {
|
||||
const sec = el.closest('.sec');
|
||||
main.scrollTo({ top: sec ? Math.max(0, sec.offsetTop - innerHeight * .52) : 0, behavior: fast ? 'auto' : 'smooth' });
|
||||
}
|
||||
if (el._it) hero(el._it); if (el._bg) sbgf(el._bg);
|
||||
}
|
||||
|
||||
function nav(d) {
|
||||
const sc = pl.classList.contains('show') ? (pl.classList.contains('eps') ? '#pep .f' : '#pl .f') : ov.classList.contains('show') ? '#ov .f' : sr.classList.contains('show') ? '#sr .f,#side .f' : lib.classList.contains('show') ? '#lib .f,#side .f' : '#side .f,#main .f';
|
||||
const c = cur.getBoundingClientRect(), cx = c.left + c.width / 2, cy = c.top + c.height / 2;
|
||||
const inSide = !!cur.closest('#side');
|
||||
if (inSide && d === 'r' && lastMain && getComputedStyle(lastMain).visibility !== 'hidden') { setFocus(lastMain); return }
|
||||
if ((d === 'l' || d === 'r') && !inSide) {
|
||||
const g = cur.closest('.row,#kb,#tabs');
|
||||
if (g) {
|
||||
const L = [...g.children].filter(e => e.classList.contains('f') && e.getBoundingClientRect().width), i = L.indexOf(cur), n = L[i + (d === 'r' ? 1 : -1)];
|
||||
if (i >= 0) { if (n) setFocus(n); else if (d === 'l' && !cur.closest('#ov,#pl')) setFocus(navAct); return }
|
||||
}
|
||||
}
|
||||
let best = null, bs = 1e9;
|
||||
document.querySelectorAll(sc).forEach(e => {
|
||||
if (e === cur) return;
|
||||
const r = e.getBoundingClientRect(); if (!r.width) return;
|
||||
const x = r.left + r.width / 2, y = r.top + r.height / 2, dx = x - cx, dy = y - cy;
|
||||
let p, s;
|
||||
if (d === 'r') { if (dx < 8) return; p = dx; s = Math.abs(dy) * 2.5 }
|
||||
else if (d === 'l') { if (dx > -8) return; p = -dx; s = Math.abs(dy) * 2.5 }
|
||||
else if (d === 'd') { if (dy < 8) return; p = dy; s = Math.abs(dx) * 2 }
|
||||
else { if (dy > -8) return; p = -dy; s = Math.abs(dx) * 2 }
|
||||
if (p + s < bs) { bs = p + s; best = e }
|
||||
});
|
||||
if (!best) return;
|
||||
if (best.closest('#side') && !inSide) best = navAct;
|
||||
setFocus(best)
|
||||
}
|
||||
|
||||
function act(el) { el && el._a && el._a() }
|
||||
112
www/js/input.js
112
www/js/input.js
@@ -1,112 +0,0 @@
|
||||
if (window.tizen && window.tizen.tvinputdevice) {
|
||||
try {
|
||||
['MediaPlay', 'MediaPause', 'MediaPlayPause', 'MediaStop', 'MediaFastForward', 'MediaRewind', '10009']
|
||||
.forEach(k => tizen.tvinputdevice.registerKey(k));
|
||||
} catch (_) { }
|
||||
}
|
||||
|
||||
const KM = {
|
||||
37: 'l', 21: 'l',
|
||||
38: 'u', 19: 'u',
|
||||
39: 'r', 22: 'r',
|
||||
40: 'd', 20: 'd',
|
||||
13: 'e', 23: 'e', 66: 'e',
|
||||
27: 'b', 8: 'b', 4: 'b', 10009: 'b', 461: 'b'
|
||||
};
|
||||
|
||||
document.addEventListener('keydown', e => {
|
||||
fast = e.repeat;
|
||||
document.body.classList.add('kbm');
|
||||
|
||||
if (e.keyCode === 85 || e.keyCode === 179 || e.keyCode === 10252 || e.keyCode === 415) {
|
||||
e.preventDefault();
|
||||
tgl();
|
||||
return;
|
||||
}
|
||||
if (e.keyCode === 126 || e.keyCode === 250) {
|
||||
e.preventDefault();
|
||||
vd.play();
|
||||
return;
|
||||
}
|
||||
if (e.keyCode === 127 || e.keyCode === 413) {
|
||||
e.preventDefault();
|
||||
vd.pause();
|
||||
return;
|
||||
}
|
||||
if (e.keyCode === 89 || e.keyCode === 227 || e.keyCode === 412) {
|
||||
e.preventDefault();
|
||||
vd.currentTime = Math.max(0, vd.currentTime - 10);
|
||||
return;
|
||||
}
|
||||
if (e.keyCode === 90 || e.keyCode === 228 || e.keyCode === 417) {
|
||||
e.preventDefault();
|
||||
vd.currentTime = Math.min(vd.duration || Infinity, vd.currentTime + 10);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pl.classList.contains('show')) {
|
||||
showCtl();
|
||||
if (e.key === ' ' || e.keyCode === 32) { e.preventDefault(); tgl(); return }
|
||||
if (cur === $('#pseek') && (e.keyCode === 37 || e.keyCode === 39 || e.keyCode === 21 || e.keyCode === 22)) {
|
||||
e.preventDefault();
|
||||
vd.currentTime += (e.keyCode === 39 || e.keyCode === 22) ? 10 : -10;
|
||||
return;
|
||||
}
|
||||
if (cur && cur.id === 'vsl' && (e.keyCode === 37 || e.keyCode === 39 || e.keyCode === 21 || e.keyCode === 22)) {
|
||||
e.preventDefault();
|
||||
vd.muted = false;
|
||||
vd.volume = Math.min(1, Math.max(0, vd.volume + ((e.keyCode === 39 || e.keyCode === 22) ? .1 : -.1)));
|
||||
cur._v();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (sr.classList.contains('show') && !ov.classList.contains('show') && !pl.classList.contains('show')) {
|
||||
if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) { e.preventDefault(); setQ(sqv + e.key); return }
|
||||
if (e.keyCode === 8) { e.preventDefault(); setQ(sqv.slice(0, -1)); return }
|
||||
}
|
||||
|
||||
const k = KM[e.keyCode];
|
||||
if (!k) return;
|
||||
e.preventDefault();
|
||||
|
||||
if (!cur) {
|
||||
const fallback = document.querySelector('.f');
|
||||
if (fallback) setFocus(fallback);
|
||||
return;
|
||||
}
|
||||
|
||||
if (k === 'e') act(cur);
|
||||
else if (k === 'b') {
|
||||
if (pl.classList.contains('show')) {
|
||||
pmK ? closeMenu(1) : pl.classList.contains('eps') ? closeEps(1) : closePlayer();
|
||||
} else if (ov.classList.contains('show')) {
|
||||
closeDD() || closeDetail();
|
||||
} else if (lib.classList.contains('show')) {
|
||||
closeLib();
|
||||
} else if (sr.classList.contains('show')) {
|
||||
closeSearch();
|
||||
}
|
||||
} else {
|
||||
nav(k);
|
||||
}
|
||||
});
|
||||
|
||||
let mx = -1, my = -1;
|
||||
document.addEventListener('mousemove', e => {
|
||||
if (Math.abs(e.clientX - mx) + Math.abs(e.clientY - my) < 4) return;
|
||||
mx = e.clientX; my = e.clientY; document.body.classList.remove('kbm');
|
||||
if (pl.classList.contains('show')) { showCtl(); const g = e.target.closest('.f'); if (g && g !== cur && pl.contains(g)) setFocus(g); return }
|
||||
const f = e.target.closest('.f');
|
||||
if (f && f !== cur && (!ov.classList.contains('show') || ov.contains(f))) setFocus(f)
|
||||
});
|
||||
document.addEventListener('click', e => {
|
||||
const f = e.target.closest('.f'); if (f) act(f)
|
||||
});
|
||||
ov.addEventListener('wheel', () => { }, { passive: true });
|
||||
|
||||
window.vylaBack = () => {
|
||||
const open = [pl, ov, lib, sr].some(e => e.classList.contains('show'));
|
||||
if (open) document.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 4, key: 'GoBack', bubbles: true, cancelable: true }));
|
||||
return open;
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
let LIB = { wl: [], fav: [] }, libK = null; const lib = $('#lib');
|
||||
try { Object.assign(LIB, JSON.parse(localStorage.getItem('vyla.lib') || '{}')) } catch (e) { }
|
||||
const saveLib = () => { try { localStorage.setItem('vyla.lib', JSON.stringify(LIB)) } catch (e) { } };
|
||||
const slim = it => ({ id: it.id, _t: it._t || it.media_type, title: it.title, name: it.name, poster_path: it.poster_path, backdrop_path: it.backdrop_path, release_date: it.release_date, first_air_date: it.first_air_date, vote_average: it.vote_average, overview: it.overview });
|
||||
const has = (k, it) => LIB[k].some(x => x.id === it.id && x._t === it._t);
|
||||
function toggleLib(k, it) {
|
||||
const i = LIB[k].findIndex(x => x.id === it.id && x._t === it._t), had = i >= 0;
|
||||
if (had) LIB[k].splice(i, 1); else LIB[k].unshift(slim(it));
|
||||
saveLib(); syncNav(); toast((had ? 'Removed from ' : 'Added to ') + LN[k]);
|
||||
if (lib.classList.contains('show')) drawLib()
|
||||
}
|
||||
function drawLib() {
|
||||
const k = libK, a = LIB[k], g = $('#lgrid');
|
||||
$('#lt').innerHTML = `${LN[k]}<small>${a.length} title${a.length === 1 ? '' : 's'}</small>`;
|
||||
g.innerHTML = '';
|
||||
if (!a.length) { g.innerHTML = '<p class="none">Nothing here yet. Open a title, press the \u22EE button and add it.</p>'; return }
|
||||
a.forEach(x => { const c = card(x, false); c._bg = x; g.appendChild(c) })
|
||||
}
|
||||
function openLib(k) {
|
||||
libK = k; setAct(k); document.body.classList.add('lib'); lib.classList.add('show'); side.classList.remove('open'); lib.scrollTop = 0;
|
||||
drawLib(); syncNav(); setFocus($('#lgrid .card') || NAVEL[k])
|
||||
}
|
||||
function closeLib(silent) {
|
||||
if (!lib.classList.contains('show')) return;
|
||||
lib.classList.remove('show'); document.body.classList.remove('lib'); libK = null; heroIt = null; bgb._u = null; syncNav();
|
||||
if (!silent) { setAct(mode); setFocus($('#rows .card')) }
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
(async () => {
|
||||
rowsEl.innerHTML = SK.rows(4);
|
||||
const [m, t] = await Promise.all([api('/genre/movie/list'), api('/genre/tv/list')]);
|
||||
MG = m.genres || []; TG = t.genres || [];
|
||||
[...MG, ...TG].forEach(g => G[g.id] = g.name);
|
||||
if (!MG.length || !TG.length) { rowsEl.innerHTML = '<p style="padding:40vh var(--pad)">Could not reach TMDB.</p>'; return }
|
||||
await go('discover');
|
||||
})();
|
||||
112
www/js/native.js
112
www/js/native.js
@@ -1,112 +0,0 @@
|
||||
(() => {
|
||||
const cap = window.Capacitor || {};
|
||||
const N = (cap.Plugins && cap.Plugins.VylaNative) || cap.registerPlugin('VylaNative');
|
||||
window.API_BASE = 'http://127.0.0.1:38417';
|
||||
|
||||
const webFetch = window.fetch.bind(window);
|
||||
const dec = new TextDecoder('utf-8');
|
||||
const bytesOf = s => { const b = atob(s), u = new Uint8Array(b.length); for (let i = 0; i < b.length; i++) u[i] = b.charCodeAt(i); return u };
|
||||
const abortErr = () => new DOMException('The operation was aborted', 'AbortError');
|
||||
|
||||
const wrap = r => {
|
||||
const bytes = bytesOf(r.body || ''), h = r.headers || {};
|
||||
const text = async () => dec.decode(bytes);
|
||||
return {
|
||||
ok: r.status >= 200 && r.status < 300,
|
||||
status: r.status,
|
||||
statusText: '',
|
||||
url: r.url,
|
||||
headers: { get: k => { const v = h[String(k).toLowerCase()]; return v === undefined ? null : v }, has: k => String(k).toLowerCase() in h },
|
||||
body: { getReader: () => { let d = false; return { read: async () => d ? { done: true, value: undefined } : (d = true, { done: false, value: bytes }) } }, cancel: async () => { } },
|
||||
text,
|
||||
json: async () => JSON.parse(await text()),
|
||||
arrayBuffer: async () => bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)
|
||||
};
|
||||
};
|
||||
|
||||
window.fetch = (input, init = {}) => {
|
||||
const isReq = typeof input !== 'string';
|
||||
const url = (isReq ? (input && input.url) : input) || '';
|
||||
if (!/^https?:\/\//i.test(url) || url.startsWith(window.API_BASE) || /^https:\/\/(api|image)\.themoviedb\.org|^https:\/\/image\.tmdb\.org/i.test(url)) return webFetch(input, init);
|
||||
const hd = {};
|
||||
new Headers(init.headers || (isReq ? input.headers : undefined)).forEach((v, k) => { hd[k] = v });
|
||||
const sig = init.signal;
|
||||
if (sig && sig.aborted) return Promise.reject(abortErr());
|
||||
const call = N.fetch({
|
||||
url,
|
||||
method: String(init.method || (isReq ? input.method : 'GET')).toUpperCase(),
|
||||
headers: hd,
|
||||
body: init.body == null ? undefined : String(init.body),
|
||||
timeout: init.timeout || 120000,
|
||||
redirect: init.redirect || 'follow',
|
||||
maxBytes: init.maxBytes || 0
|
||||
}).then(wrap);
|
||||
if (!sig) return call;
|
||||
return Promise.race([call, new Promise((_, rej) => sig.addEventListener('abort', () => rej(abortErr()), { once: true }))]);
|
||||
};
|
||||
|
||||
let booted = false;
|
||||
const boot = () => { if (!booted) { VylaLocal.init(K); booted = true } };
|
||||
const opt = v => v === undefined || v === null || v === '' || v === 'null' || v === 'undefined' ? undefined : String(v);
|
||||
|
||||
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36';
|
||||
const OKS = [200, 206, 304];
|
||||
const SEG = { recap: 'Skip Recap', intro: 'Skip Intro', preview: 'Skip Preview', credits: 'Skip Credits' };
|
||||
|
||||
const probeGet = (u, h, max) => fetch(u, { headers: { 'User-Agent': UA, Accept: '*/*', 'Accept-Language': 'en-US,en;q=0.9', ...h, Range: 'bytes=0-1024' }, timeout: 6000, maxBytes: max });
|
||||
|
||||
const playable = async (url, h, depth = 0) => {
|
||||
try {
|
||||
const r = await probeGet(url, h, 1048576);
|
||||
if (!OKS.includes(r.status)) return false;
|
||||
const ct = (r.headers.get('content-type') || '').toLowerCase();
|
||||
if (!(url.includes('.m3u8') || ct.includes('mpegurl') || ct.includes('m3u8'))) return true;
|
||||
if (depth > 4) return false;
|
||||
const line = (await r.text()).split('\n').map(x => x.trim()).find(x => x && x[0] !== '#');
|
||||
if (!line) return false;
|
||||
const base = url.slice(0, url.lastIndexOf('/') + 1), origin = new URL(url).origin;
|
||||
const t = line.startsWith('http') ? line : line.startsWith('/') ? origin + line : base + line;
|
||||
if (t.includes('m3u8')) return playable(t, h, depth + 1);
|
||||
return OKS.includes((await probeGet(t, h, 1024)).status);
|
||||
} catch (_) { return false }
|
||||
};
|
||||
|
||||
window.Vyla = {
|
||||
sources() {
|
||||
boot();
|
||||
return VylaLocal.sources().map(c => ({ key: c.key, label: c.label }));
|
||||
},
|
||||
async stream(provider, tmdbId, season, episode) {
|
||||
boot();
|
||||
try {
|
||||
const d = await VylaLocal.stream(String(provider), String(tmdbId), opt(season), opt(episode));
|
||||
if (!d) return { success: false };
|
||||
const h = d.headers || {};
|
||||
if (Array.isArray(d.allUrls) && d.allUrls.length) {
|
||||
const ok = await Promise.all(d.allUrls.map(async u => (u && u.url && await playable(u.url, h)) ? u : null));
|
||||
d.allUrls = ok.filter(Boolean);
|
||||
if (d.allUrls.length) { if (!d.url || !d.allUrls.some(u => u.url === d.url)) d.url = d.allUrls[0].url }
|
||||
else d.url = null;
|
||||
} else if (d.url && !(await playable(d.url, h))) d.url = null;
|
||||
return d.url ? { success: true, provider, stream: d } : { success: false };
|
||||
} catch (_) { return { success: false } }
|
||||
},
|
||||
async subtitles(id, season, episode) {
|
||||
boot();
|
||||
try { return (await VylaLocal.subtitles(String(id), opt(season), opt(episode))) || [] } catch (_) { return [] }
|
||||
},
|
||||
async timestamps(id, season, episode, durationSec) {
|
||||
let u = `https://api.theintrodb.org/v3/media?tmdb_id=${id}`;
|
||||
if (season) u += `&season=${season}`;
|
||||
if (episode) u += `&episode=${episode}`;
|
||||
if (durationSec) u += `&duration_ms=${Math.round(durationSec * 1000)}`;
|
||||
try {
|
||||
const r = await fetch(u, { timeout: 8000 });
|
||||
if (!r.ok) return [];
|
||||
const d = await r.json(), out = [];
|
||||
Object.keys(SEG).forEach(t => (Array.isArray(d[t]) ? d[t] : []).forEach(x => out.push({ type: t, label: SEG[t], start: x.start_ms != null ? x.start_ms / 1000 : 0, end: x.end_ms != null ? x.end_ms / 1000 : null })));
|
||||
return out;
|
||||
} catch (_) { return [] }
|
||||
}
|
||||
};
|
||||
})();
|
||||
794
www/js/player.js
794
www/js/player.js
@@ -1,794 +0,0 @@
|
||||
let currentHls = null;
|
||||
let currentBgHls = null;
|
||||
let currentSources = [];
|
||||
let resolvedStreams = [];
|
||||
let selectedSourceKey = null;
|
||||
let selectedStreamUrl = null;
|
||||
let expandedSources = new Set();
|
||||
let currentQualityLevels = [];
|
||||
let selectedQualityIndex = -1;
|
||||
let activeSubtitles = [];
|
||||
let mediaSegments = [];
|
||||
let activeSegment = null;
|
||||
let plPrev = null;
|
||||
let plT = null;
|
||||
let plItem = null;
|
||||
let pmK = null;
|
||||
let plCtx = null;
|
||||
let viewS = null;
|
||||
let drag = 0;
|
||||
let discoverySession = 0;
|
||||
let userHasManuallySelectedSource = false;
|
||||
|
||||
let subSettings = {
|
||||
size: 24,
|
||||
color: '#ffffff',
|
||||
bg: 'rgba(0,0,0,0.75)',
|
||||
offset: 0
|
||||
};
|
||||
|
||||
const pi = (p, f) => `<svg viewBox="0 0 24 24" fill="${f ? 'currentColor' : 'none'}" stroke="${f ? 'none' : 'currentColor'}" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">${p}</svg>`;
|
||||
const SPK = '<path d="M4 9v6h4l5 4V5L8 9z"/>';
|
||||
const PI = {
|
||||
x: pi('<path d="M5 5l14 14M19 5 5 19"/>'),
|
||||
play: pi('<path d="M7 4.5v15L19.5 12z" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/>', 1),
|
||||
pause: pi('<rect x="6" y="4.5" width="4" height="15" rx="1.2"/><rect x="14" y="4.5" width="4" height="15" rx="1.2"/>', 1),
|
||||
cc: pi('<rect x="3" y="5" width="18" height="14" rx="3"/><path d="M10.5 10a2 2 0 1 0 0 4M17 10a2 2 0 1 0 0 4"/>'),
|
||||
vol: pi(SPK + '<path d="M16.5 8.5a5 5 0 0 1 0 7M19 6a9 9 0 0 1 0 12"/>'),
|
||||
mute: pi(SPK + '<path d="m17 9.5 4 5m0-5-4 5"/>'),
|
||||
qlt: pi('<path d="M4 6h16M4 12h16M4 18h7"/>'),
|
||||
set: pi('<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z"/>'),
|
||||
more: pi('<path d="M5 12h.01M12 12h.01M19 12h.01" stroke-width="3.4"/>'),
|
||||
fs: pi('<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>'),
|
||||
fx: pi('<path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/>'),
|
||||
eps: pi('<rect x="3" y="4" width="7" height="6" rx="1.5"/><rect x="14" y="4" width="7" height="6" rx="1.5"/><rect x="3" y="14" width="7" height="6" rx="1.5"/><rect x="14" y="14" width="7" height="6" rx="1.5"/>'),
|
||||
chk: pi('<path d="m5 12.5 4.5 4.5L19 7"/>')
|
||||
};
|
||||
|
||||
$('#ptop').innerHTML = `<div class="pic f" id="pback">${PI.x}</div><img class="av" id="pav" alt=""><div class="pt"><b id="pt"></b><small id="ps"></small></div><div class="pr"><div class="pic f" id="pqlt" title="Quality">${PI.qlt}</div><div class="pic f" id="pcc">${PI.cc}</div><div class="pic f" id="pvol">${PI.vol}</div><div class="pic f" id="pset">${PI.set}</div><div class="pic f" id="pmore">${PI.more}</div></div>`;
|
||||
$('#pbot').innerHTML = `<span class="bt" id="pcur">0:00</span><div class="sk f" id="pseek"><u id="pbuf"></u><i id="pfill"></i><b id="phd"></b></div><span class="bt" id="pdur">0:00</span><div class="pic f" id="peps">${PI.eps}</div><div class="pic f" id="pfs">${PI.fs}</div>`;
|
||||
$('#pmid').innerHTML = PI.play;
|
||||
|
||||
const pm = $('#pm');
|
||||
const sk = $('#pseek');
|
||||
const pbg = $('#pbg');
|
||||
|
||||
const fmt = t => {
|
||||
t = Math.max(0, Math.floor(t || 0));
|
||||
const h = Math.floor(t / 3600);
|
||||
const m = Math.floor((t % 3600) / 60);
|
||||
const c = t % 60;
|
||||
return (h ? h + ':' + String(m).padStart(2, '0') : m) + ':' + String(c).padStart(2, '0');
|
||||
};
|
||||
|
||||
const tgl = () => vd.paused ? vd.play() : vd.pause();
|
||||
const pico = () => {
|
||||
$('#pmid').innerHTML = vd.paused ? PI.play : PI.pause;
|
||||
};
|
||||
|
||||
function showCtl() {
|
||||
pl.classList.add('ui');
|
||||
clearTimeout(plT);
|
||||
plT = setTimeout(() => {
|
||||
if (!vd.paused && !pmK && !pl.classList.contains('eps')) {
|
||||
pl.classList.remove('ui');
|
||||
}
|
||||
}, 3800);
|
||||
}
|
||||
|
||||
function closeMenu(rf) {
|
||||
if (!pmK) return;
|
||||
const t = {
|
||||
qlt: '#pqlt',
|
||||
cc: '#pcc',
|
||||
vol: '#pvol',
|
||||
set: '#pset',
|
||||
more: '#pmore'
|
||||
}[pmK];
|
||||
pmK = null;
|
||||
pm.classList.remove('open');
|
||||
pm.innerHTML = '';
|
||||
if (rf) setFocus($(t));
|
||||
}
|
||||
|
||||
function updateSubStyles() {
|
||||
vd.classList.add('sub-active');
|
||||
vd.style.setProperty('--sub-size', `${subSettings.size}px`);
|
||||
vd.style.setProperty('--sub-color', subSettings.color);
|
||||
vd.style.setProperty('--sub-bg', subSettings.bg);
|
||||
Array.from(vd.textTracks).forEach(track => {
|
||||
if (track.cues) {
|
||||
for (let i = 0; i < track.cues.length; i++) {
|
||||
const cue = track.cues[i];
|
||||
if (cue && !cue._initialOffsetApplied) {
|
||||
cue.startTime += subSettings.offset;
|
||||
cue.endTime += subSettings.offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function applySubOffset(delta) {
|
||||
subSettings.offset += delta;
|
||||
Array.from(vd.textTracks).forEach(track => {
|
||||
if (track.cues) {
|
||||
for (let i = 0; i < track.cues.length; i++) {
|
||||
const cue = track.cues[i];
|
||||
if (cue) {
|
||||
cue.startTime += delta;
|
||||
cue.endTime += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function buildProxyUrl(rawUrl, headersObj = {}) {
|
||||
return `${API_BASE}/api/proxy?url=${encodeURIComponent(rawUrl)}&headers=${encodeURIComponent(JSON.stringify(headersObj))}`;
|
||||
}
|
||||
|
||||
async function fetchSources() {
|
||||
currentSources = Vyla.sources();
|
||||
}
|
||||
|
||||
async function startConcurrentDiscovery(it, s = null, e = null) {
|
||||
const session = ++discoverySession;
|
||||
pl.classList.add('buf');
|
||||
|
||||
resolvedStreams = [];
|
||||
selectedStreamUrl = null;
|
||||
let foundFirstPlayable = false;
|
||||
|
||||
if (!currentSources.length) {
|
||||
await fetchSources();
|
||||
}
|
||||
|
||||
if (session !== discoverySession) return;
|
||||
|
||||
const sourcePromises = currentSources.map(async (src) => {
|
||||
try {
|
||||
const data = await Vyla.stream(src.key, it.id, s, e);
|
||||
if (session !== discoverySession) return;
|
||||
|
||||
if (data.success && data.stream) {
|
||||
const streamData = data.stream;
|
||||
const headers = streamData.headers || {};
|
||||
let playable = [];
|
||||
|
||||
if (Array.isArray(streamData.allUrls) && streamData.allUrls.length > 0) {
|
||||
playable = streamData.allUrls;
|
||||
} else if (streamData.url) {
|
||||
playable = [{ url: streamData.url, quality: streamData.quality || 'Auto', isM3U8: streamData.isM3U8 }];
|
||||
}
|
||||
|
||||
if (playable.length > 0) {
|
||||
const resolvedEntry = {
|
||||
provider: src.key,
|
||||
label: src.label || src.key,
|
||||
headers,
|
||||
primaryUrl: playable[0].url,
|
||||
allUrls: playable
|
||||
};
|
||||
|
||||
resolvedStreams.push(resolvedEntry);
|
||||
|
||||
if (pmK === 'set') {
|
||||
renderSourcesMenu();
|
||||
}
|
||||
|
||||
if (!foundFirstPlayable && !userHasManuallySelectedSource) {
|
||||
foundFirstPlayable = true;
|
||||
selectedSourceKey = src.key;
|
||||
playSpecificStream(resolvedEntry.primaryUrl, resolvedEntry.headers);
|
||||
} else if (userHasManuallySelectedSource && selectedSourceKey === src.key && !selectedStreamUrl) {
|
||||
playSpecificStream(resolvedEntry.primaryUrl, resolvedEntry.headers);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_) { }
|
||||
});
|
||||
|
||||
Promise.allSettled(sourcePromises).then(() => {
|
||||
if (session !== discoverySession) return;
|
||||
if (!resolvedStreams.length) {
|
||||
pl.classList.remove('buf');
|
||||
toast('No playable sources available.');
|
||||
}
|
||||
});
|
||||
|
||||
loadSubtitles(it.id, s, e);
|
||||
loadTimestamps(it.id, s, e);
|
||||
}
|
||||
|
||||
function playSpecificStream(streamUrl, headers = {}) {
|
||||
pl.classList.add('buf');
|
||||
selectedStreamUrl = streamUrl;
|
||||
|
||||
if (currentHls) {
|
||||
currentHls.destroy();
|
||||
currentHls = null;
|
||||
}
|
||||
if (currentBgHls) {
|
||||
currentBgHls.destroy();
|
||||
currentBgHls = null;
|
||||
}
|
||||
|
||||
const finalUrl = buildProxyUrl(streamUrl, headers);
|
||||
|
||||
if (streamUrl.includes('.m3u8')) {
|
||||
if (Hls.isSupported()) {
|
||||
currentHls = new Hls({
|
||||
xhrSetup: function (xhr) {
|
||||
xhr.withCredentials = false;
|
||||
}
|
||||
});
|
||||
currentHls.loadSource(finalUrl);
|
||||
currentHls.attachMedia(vd);
|
||||
currentHls.on(Hls.Events.MANIFEST_PARSED, (_, data) => {
|
||||
currentQualityLevels = data.levels || [];
|
||||
vd.play().catch(() => { });
|
||||
});
|
||||
currentHls.on(Hls.Events.LEVEL_SWITCHED, (_, data) => {
|
||||
selectedQualityIndex = data.level;
|
||||
});
|
||||
|
||||
if (pbg) {
|
||||
currentBgHls = new Hls({
|
||||
xhrSetup: function (xhr) {
|
||||
xhr.withCredentials = false;
|
||||
}
|
||||
});
|
||||
currentBgHls.loadSource(finalUrl);
|
||||
currentBgHls.attachMedia(pbg);
|
||||
currentBgHls.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||
pbg.muted = true;
|
||||
if (!vd.paused) pbg.play().catch(() => { });
|
||||
});
|
||||
}
|
||||
} else if (vd.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
vd.src = finalUrl;
|
||||
vd.play().catch(() => { });
|
||||
if (pbg) {
|
||||
pbg.src = finalUrl;
|
||||
pbg.muted = true;
|
||||
pbg.play().catch(() => { });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentQualityLevels = [];
|
||||
vd.src = finalUrl;
|
||||
vd.play().catch(() => { });
|
||||
if (pbg) {
|
||||
pbg.src = finalUrl;
|
||||
pbg.muted = true;
|
||||
pbg.play().catch(() => { });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setPlaybackQuality(levelIndex) {
|
||||
selectedQualityIndex = levelIndex;
|
||||
if (currentHls) {
|
||||
currentHls.currentLevel = levelIndex;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSubtitles(id, s, e) {
|
||||
Array.from(vd.querySelectorAll('track')).forEach(t => t.remove());
|
||||
activeSubtitles = [];
|
||||
|
||||
try {
|
||||
activeSubtitles = await Vyla.subtitles(id, s, e);
|
||||
|
||||
activeSubtitles.forEach((sub, idx) => {
|
||||
const track = document.createElement('track');
|
||||
track.kind = 'subtitles';
|
||||
track.label = `${sub.label} (${sub.source || 'mirror'})`;
|
||||
track.srclang = sub.label.slice(0, 2).toLowerCase();
|
||||
track.src = buildProxyUrl(sub.file);
|
||||
track.default = idx === 0;
|
||||
vd.appendChild(track);
|
||||
track.track.mode = 'disabled';
|
||||
});
|
||||
updateSubStyles();
|
||||
} catch (_) { }
|
||||
}
|
||||
|
||||
async function loadTimestamps(tmdbId, season = null, episode = null, durationSec = null) {
|
||||
mediaSegments = [];
|
||||
activeSegment = null;
|
||||
$('#pskip').classList.remove('v');
|
||||
try {
|
||||
let q = `${API_BASE}/api/timestamps?tmdb_id=${tmdbId}`;
|
||||
if (season) q += `&season=${season}`;
|
||||
if (episode) q += `&episode=${episode}`;
|
||||
if (durationSec) q += `&duration_ms=${Math.round(durationSec * 1000)}`;
|
||||
|
||||
const res = await fetch(q);
|
||||
const data = await res.json();
|
||||
mediaSegments = data.segments || [];
|
||||
} catch (_) {
|
||||
mediaSegments = [];
|
||||
}
|
||||
}
|
||||
|
||||
function renderSourcesMenu() {
|
||||
let container = $('#pm-src-list');
|
||||
if (!container) return;
|
||||
container.innerHTML = '';
|
||||
|
||||
if (!resolvedStreams.length) {
|
||||
container.innerHTML = '<div style="padding:10px 14px;color:rgba(255,255,255,0.4);font-size:13px;">Probing providers...</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
resolvedStreams.forEach(s => {
|
||||
const grp = document.createElement('div');
|
||||
grp.className = 'src-group';
|
||||
|
||||
const hdr = document.createElement('div');
|
||||
hdr.className = 'src-header f' + (s.provider === selectedSourceKey ? ' on' : '');
|
||||
|
||||
const hasMulti = s.allUrls && s.allUrls.length > 1;
|
||||
const countLabel = hasMulti ? ` (${s.allUrls.length})` : '';
|
||||
const expandIcon = hasMulti ? `<span class="src-expand-btn">${expandedSources.has(s.provider) ? '▲' : '▼'}</span>` : '';
|
||||
|
||||
hdr.innerHTML = `<span>${s.label}${countLabel}</span><div>${expandIcon}${s.provider === selectedSourceKey ? PI.chk : ''}</div>`;
|
||||
hdr._a = () => {
|
||||
userHasManuallySelectedSource = true;
|
||||
if (hasMulti && s.provider === selectedSourceKey) {
|
||||
if (expandedSources.has(s.provider)) expandedSources.delete(s.provider);
|
||||
else expandedSources.add(s.provider);
|
||||
renderSourcesMenu();
|
||||
} else {
|
||||
selectedSourceKey = s.provider;
|
||||
playSpecificStream(s.primaryUrl, s.headers);
|
||||
renderSourcesMenu();
|
||||
}
|
||||
};
|
||||
grp.appendChild(hdr);
|
||||
|
||||
if (hasMulti) {
|
||||
const sub = document.createElement('div');
|
||||
sub.className = 'src-sublist' + (expandedSources.has(s.provider) ? ' open' : '');
|
||||
|
||||
s.allUrls.forEach((u, i) => {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'src-subitem f' + (u.url === selectedStreamUrl ? ' on' : '');
|
||||
item.innerHTML = `<span>${u.quality || 'Stream ' + (i + 1)}</span>${u.url === selectedStreamUrl ? PI.chk : ''}`;
|
||||
item._a = () => {
|
||||
userHasManuallySelectedSource = true;
|
||||
selectedSourceKey = s.provider;
|
||||
playSpecificStream(u.url, s.headers);
|
||||
renderSourcesMenu();
|
||||
};
|
||||
sub.appendChild(item);
|
||||
});
|
||||
grp.appendChild(sub);
|
||||
}
|
||||
|
||||
container.appendChild(grp);
|
||||
});
|
||||
}
|
||||
|
||||
function openMenu(k) {
|
||||
if (pmK === k) {
|
||||
closeMenu(1);
|
||||
return;
|
||||
}
|
||||
closeEps();
|
||||
pm.innerHTML = '';
|
||||
pmK = k;
|
||||
pm.classList.add('open');
|
||||
let first = null;
|
||||
|
||||
const h = t => {
|
||||
const e = document.createElement('h4');
|
||||
e.textContent = t;
|
||||
pm.appendChild(e);
|
||||
};
|
||||
|
||||
const r = (l, on, fn) => {
|
||||
const e = mkf('pi', `<span>${l}</span>${on ? PI.chk : ''}`, () => {
|
||||
fn();
|
||||
closeMenu(1);
|
||||
});
|
||||
pm.appendChild(e);
|
||||
if (on && !first) first = e;
|
||||
return e;
|
||||
};
|
||||
|
||||
if (k === 'qlt') {
|
||||
h('Stream Quality');
|
||||
if (currentHls && currentQualityLevels.length > 0) {
|
||||
r('Auto', selectedQualityIndex === -1, () => setPlaybackQuality(-1));
|
||||
currentQualityLevels.forEach((lvl, idx) => {
|
||||
const label = lvl.height ? `${lvl.height}p` : `${Math.round(lvl.bitrate / 1000)} kbps`;
|
||||
r(label, selectedQualityIndex === idx, () => setPlaybackQuality(idx));
|
||||
});
|
||||
} else {
|
||||
const activeProv = resolvedStreams.find(s => s.provider === selectedSourceKey);
|
||||
if (activeProv && activeProv.allUrls.length > 1) {
|
||||
activeProv.allUrls.forEach((u, idx) => {
|
||||
const label = u.quality || `Stream ${idx + 1}`;
|
||||
r(label, u.url === selectedStreamUrl, () => {
|
||||
userHasManuallySelectedSource = true;
|
||||
playSpecificStream(u.url, activeProv.headers);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
r('Auto', true, () => { });
|
||||
}
|
||||
}
|
||||
} else if (k === 'cc') {
|
||||
h('Subtitles');
|
||||
const T = [...vd.textTracks];
|
||||
r('Off', !T.some(t => t.mode === 'showing'), () => {
|
||||
T.forEach(t => t.mode = 'disabled');
|
||||
});
|
||||
T.forEach(t => r(t.label, t.mode === 'showing', () => {
|
||||
T.forEach(u => u.mode = u === t ? 'showing' : 'disabled');
|
||||
updateSubStyles();
|
||||
}));
|
||||
|
||||
h('Subtitle Size');
|
||||
[18, 22, 26, 32].forEach(sz => {
|
||||
r(`${sz}px`, subSettings.size === sz, () => {
|
||||
subSettings.size = sz;
|
||||
updateSubStyles();
|
||||
});
|
||||
});
|
||||
|
||||
h('Subtitle Color');
|
||||
[['White', '#ffffff'], ['Yellow', '#ffd700'], ['Cyan', '#00ffff']].forEach(([col, code]) => {
|
||||
r(col, subSettings.color === code, () => {
|
||||
subSettings.color = code;
|
||||
updateSubStyles();
|
||||
});
|
||||
});
|
||||
|
||||
h('Subtitle Sync');
|
||||
const syncRow = document.createElement('div');
|
||||
syncRow.className = 'sub-ctrl-row';
|
||||
syncRow.innerHTML = `<span>Timing Offset</span><div class="sub-btn-group"><button id="sub-min">-0.5s</button><button id="sub-plus">+0.5s</button></div>`;
|
||||
pm.appendChild(syncRow);
|
||||
$('#sub-min').onclick = (ev) => {
|
||||
ev.stopPropagation();
|
||||
applySubOffset(-0.5);
|
||||
};
|
||||
$('#sub-plus').onclick = (ev) => {
|
||||
ev.stopPropagation();
|
||||
applySubOffset(0.5);
|
||||
};
|
||||
} else if (k === 'vol') {
|
||||
h('Volume');
|
||||
const w = document.createElement('div');
|
||||
w.className = 'vrow';
|
||||
w.innerHTML = '<div class="pic f" id="vm"></div><div class="vs f" id="vsl"><i></i></div><span id="vpc"></span>';
|
||||
pm.appendChild(w);
|
||||
const vm = $('#vm');
|
||||
const vs = $('#vsl');
|
||||
const vu = () => {
|
||||
const v = vd.muted ? 0 : vd.volume;
|
||||
vs.firstChild.style.width = v * 100 + '%';
|
||||
$('#vpc').textContent = Math.round(v * 100);
|
||||
vm.innerHTML = $('#pvol').innerHTML = v ? PI.vol : PI.mute;
|
||||
};
|
||||
vm._a = () => {
|
||||
vd.muted = !vd.muted;
|
||||
vu();
|
||||
};
|
||||
vs._a = () => { };
|
||||
vs._v = vu;
|
||||
vs.addEventListener('click', e => {
|
||||
const b = vs.getBoundingClientRect();
|
||||
vd.muted = false;
|
||||
vd.volume = Math.min(1, Math.max(0, (e.clientX - b.left) / b.width));
|
||||
vu();
|
||||
});
|
||||
vu();
|
||||
first = vs;
|
||||
} else if (k === 'set') {
|
||||
h('Available Sources');
|
||||
const srcContainer = document.createElement('div');
|
||||
srcContainer.id = 'pm-src-list';
|
||||
pm.appendChild(srcContainer);
|
||||
renderSourcesMenu();
|
||||
|
||||
h('Playback Speed');
|
||||
[.5, 1, 1.25, 1.5, 2].forEach(v => r(v === 1 ? 'Normal' : v + '\u00d7', vd.playbackRate === v, () => vd.playbackRate = v));
|
||||
|
||||
h('Aspect Ratio');
|
||||
r('Fit Screen', !pl.classList.contains('cover'), () => {
|
||||
pl.classList.remove('cover');
|
||||
if (pbg) {
|
||||
pbg.currentTime = vd.currentTime;
|
||||
if (!vd.paused) pbg.play().catch(() => { });
|
||||
}
|
||||
});
|
||||
r('Fill Screen', pl.classList.contains('cover'), () => {
|
||||
pl.classList.add('cover');
|
||||
if (pbg) pbg.pause();
|
||||
});
|
||||
} else {
|
||||
h('Library');
|
||||
r('Watch Later', has('wl', plItem), () => toggleLib('wl', plItem));
|
||||
r('Favorites', has('fav', plItem), () => toggleLib('fav', plItem));
|
||||
}
|
||||
|
||||
showCtl();
|
||||
setFocus(first || pm.querySelector('.f'));
|
||||
}
|
||||
|
||||
async function openPlayer(it, ep, ctx) {
|
||||
if (!it) return;
|
||||
plPrev = cur;
|
||||
plItem = it;
|
||||
plCtx = ctx || null;
|
||||
userHasManuallySelectedSource = false;
|
||||
$('#peps').style.display = plCtx ? '' : 'none';
|
||||
pl.classList.remove('eps');
|
||||
$('#pnext').classList.remove('v');
|
||||
$('#pt').textContent = it.title || it.name || '';
|
||||
$('#ps').textContent = ep || [yr(it), it._t === 'tv' ? 'Series' : 'Movie'].filter(Boolean).join(' \u2022 ');
|
||||
$('#pav').src = it.poster_path ? I + 'w185' + it.poster_path : PH;
|
||||
vd.poster = it.backdrop_path ? I + 'w1280' + it.backdrop_path : '';
|
||||
|
||||
pl.classList.add('show');
|
||||
showCtl();
|
||||
pico();
|
||||
setFocus($('#pmid'));
|
||||
|
||||
if (plCtx) {
|
||||
const epData = plCtx.eps[plCtx.i];
|
||||
startConcurrentDiscovery(it, plCtx.s, epData.episode_number);
|
||||
} else {
|
||||
startConcurrentDiscovery(it);
|
||||
}
|
||||
}
|
||||
|
||||
function closePlayer() {
|
||||
closeMenu();
|
||||
closeEps();
|
||||
if (currentHls) {
|
||||
currentHls.destroy();
|
||||
currentHls = null;
|
||||
}
|
||||
if (currentBgHls) {
|
||||
currentBgHls.destroy();
|
||||
currentBgHls = null;
|
||||
}
|
||||
plCtx = null;
|
||||
vd.pause();
|
||||
vd.removeAttribute('src');
|
||||
vd.load();
|
||||
if (pbg) {
|
||||
pbg.pause();
|
||||
pbg.removeAttribute('src');
|
||||
pbg.load();
|
||||
}
|
||||
if (document.fullscreenElement) document.exitFullscreen();
|
||||
pl.classList.remove('show', 'ui');
|
||||
if (plPrev && document.body.contains(plPrev)) setFocus(plPrev);
|
||||
}
|
||||
|
||||
$('#pback')._a = closePlayer;
|
||||
$('#pmid')._a = tgl;
|
||||
|
||||
$('#pskip')._a = () => {
|
||||
if (activeSegment) {
|
||||
const target = activeSegment.end != null ? activeSegment.end + 0.5 : (vd.duration || vd.currentTime + 30);
|
||||
vd.currentTime = target;
|
||||
$('#pskip').classList.remove('v');
|
||||
activeSegment = null;
|
||||
} else {
|
||||
vd.currentTime += 85;
|
||||
}
|
||||
};
|
||||
|
||||
$('#pqlt')._a = () => openMenu('qlt');
|
||||
$('#pcc')._a = () => openMenu('cc');
|
||||
$('#pvol')._a = () => openMenu('vol');
|
||||
$('#pset')._a = () => openMenu('set');
|
||||
$('#pmore')._a = () => openMenu('more');
|
||||
$('#pfs')._a = () => document.fullscreenElement ? document.exitFullscreen() : pl.requestFullscreen && pl.requestFullscreen();
|
||||
|
||||
document.addEventListener('fullscreenchange', () => {
|
||||
$('#pfs').innerHTML = document.fullscreenElement ? PI.fx : PI.fs;
|
||||
});
|
||||
|
||||
const sp = e => {
|
||||
const b = sk.getBoundingClientRect();
|
||||
vd.currentTime = Math.min(1, Math.max(0, (e.clientX - b.left) / b.width)) * (vd.duration || 0);
|
||||
};
|
||||
|
||||
sk.addEventListener('pointerdown', e => {
|
||||
drag = 1;
|
||||
sk._m = 1;
|
||||
sk.setPointerCapture(e.pointerId);
|
||||
sp(e);
|
||||
});
|
||||
|
||||
sk.addEventListener('pointermove', e => {
|
||||
if (drag) sp(e);
|
||||
});
|
||||
|
||||
sk.addEventListener('pointerup', () => drag = 0);
|
||||
|
||||
sk._a = () => {
|
||||
if (sk._m) {
|
||||
sk._m = 0;
|
||||
return;
|
||||
}
|
||||
tgl();
|
||||
};
|
||||
|
||||
pl.querySelectorAll('.f').forEach(e => {
|
||||
if (!e._a) e._a = () => { };
|
||||
});
|
||||
|
||||
vd.addEventListener('click', () => {
|
||||
if (pmK) closeMenu();
|
||||
else if (pl.classList.contains('eps')) closeEps();
|
||||
else tgl();
|
||||
showCtl();
|
||||
});
|
||||
|
||||
vd.addEventListener('play', () => {
|
||||
if (!pl.classList.contains('cover') && pbg) {
|
||||
pbg.muted = true;
|
||||
pbg.currentTime = vd.currentTime;
|
||||
pbg.play().catch(() => { });
|
||||
}
|
||||
});
|
||||
|
||||
vd.addEventListener('pause', () => {
|
||||
if (pbg) pbg.pause();
|
||||
});
|
||||
|
||||
vd.addEventListener('seeking', () => {
|
||||
if (pbg) pbg.currentTime = vd.currentTime;
|
||||
});
|
||||
|
||||
vd.addEventListener('seeked', () => {
|
||||
if (pbg) pbg.currentTime = vd.currentTime;
|
||||
});
|
||||
|
||||
vd.addEventListener('ratechange', () => {
|
||||
if (pbg) pbg.playbackRate = vd.playbackRate;
|
||||
});
|
||||
|
||||
vd.addEventListener('durationchange', () => {
|
||||
$('#pdur').textContent = fmt(vd.duration);
|
||||
if (vd.duration && plItem) {
|
||||
const c = plCtx;
|
||||
loadTimestamps(plItem.id, c ? c.s : null, c ? c.eps[c.i].episode_number : null, vd.duration);
|
||||
}
|
||||
});
|
||||
|
||||
vd.addEventListener('timeupdate', () => {
|
||||
const d = vd.duration || 0;
|
||||
const t = vd.currentTime;
|
||||
const p = d ? (t / d) * 100 : 0;
|
||||
|
||||
$('#pfill').style.width = p + '%';
|
||||
$('#phd').style.left = p + '%';
|
||||
$('#pcur').textContent = fmt(t);
|
||||
|
||||
if (d && vd.buffered.length) {
|
||||
$('#pbuf').style.width = (vd.buffered.end(vd.buffered.length - 1) / d * 100) + '%';
|
||||
}
|
||||
|
||||
if (!pl.classList.contains('cover') && pbg && Math.abs(pbg.currentTime - t) > 0.35) {
|
||||
pbg.currentTime = t;
|
||||
}
|
||||
|
||||
const currentSeg = mediaSegments.find(seg => {
|
||||
const afterStart = t >= seg.start;
|
||||
const beforeEnd = seg.end == null ? (d ? t < d - 5 : true) : t < seg.end;
|
||||
return afterStart && beforeEnd;
|
||||
});
|
||||
|
||||
if (currentSeg) {
|
||||
activeSegment = currentSeg;
|
||||
$('#pskip').textContent = currentSeg.label;
|
||||
$('#pskip').classList.add('v');
|
||||
} else {
|
||||
activeSegment = null;
|
||||
$('#pskip').classList.remove('v');
|
||||
}
|
||||
});
|
||||
|
||||
['play', 'pause', 'ended'].forEach(n => vd.addEventListener(n, pico));
|
||||
['loadstart', 'waiting', 'seeking'].forEach(n => vd.addEventListener(n, () => pl.classList.add('buf')));
|
||||
['playing', 'canplay', 'seeked', 'error'].forEach(n => vd.addEventListener(n, () => pl.classList.remove('buf')));
|
||||
|
||||
const hasNext = () => !!plCtx && (plCtx.i + 1 < plCtx.eps.length || plCtx.seasons.some(x => x.season_number > plCtx.s));
|
||||
const getSeason = async s => plCtx.cache[s] || (plCtx.cache[s] = (await api(`/tv/${plCtx.it.id}/season/${s}`)).episodes || []);
|
||||
|
||||
async function playEp(s, i) {
|
||||
const c = plCtx;
|
||||
if (!c) return;
|
||||
const eps = await getSeason(s);
|
||||
const p = eps[i];
|
||||
if (!p || plCtx !== c) return;
|
||||
c.s = s;
|
||||
c.i = i;
|
||||
c.eps = eps;
|
||||
$('#ps').textContent = `S${s} E${p.episode_number} \u2022 ${p.name || ''}`;
|
||||
$('#pnext').classList.remove('v');
|
||||
closeEps();
|
||||
showCtl();
|
||||
setFocus($('#pmid'));
|
||||
userHasManuallySelectedSource = false;
|
||||
startConcurrentDiscovery(c.it, s, p.episode_number);
|
||||
}
|
||||
|
||||
function nextEp() {
|
||||
const c = plCtx;
|
||||
if (!hasNext()) return;
|
||||
if (c.i + 1 < c.eps.length) {
|
||||
playEp(c.s, c.i + 1);
|
||||
} else {
|
||||
playEp(c.seasons.find(x => x.season_number > c.s).season_number, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function closeEps(rf) {
|
||||
if (!pl.classList.contains('eps')) return;
|
||||
pl.classList.remove('eps');
|
||||
if (rf) setFocus($('#peps'));
|
||||
}
|
||||
|
||||
function openEps() {
|
||||
const c = plCtx;
|
||||
if (!c) return;
|
||||
closeMenu();
|
||||
$('#peT').innerHTML = `Episodes<small>${esc(c.it.title || c.it.name || '')}</small>`;
|
||||
const sr = $('#pseas');
|
||||
sr.innerHTML = '';
|
||||
c.seasons.forEach(x => {
|
||||
sr.appendChild(mkf('chip', esc(x.name || 'Season ' + x.season_number), () => showSeason(x.season_number)));
|
||||
});
|
||||
pl.classList.add('eps');
|
||||
showCtl();
|
||||
showSeason(c.s, true);
|
||||
}
|
||||
|
||||
async function showSeason(sn, focus) {
|
||||
const c = plCtx;
|
||||
const car = $('#pcar');
|
||||
if (!c) return;
|
||||
viewS = sn;
|
||||
[...$('#pseas').children].forEach((e, i) => e.classList.toggle('act', c.seasons[i].season_number === sn));
|
||||
car.innerHTML = SK.pep(8);
|
||||
const eps = await getSeason(sn);
|
||||
if (viewS !== sn || plCtx !== c) return;
|
||||
car.innerHTML = '';
|
||||
eps.forEach((p, i) => {
|
||||
const n = p.episode_number;
|
||||
const cur = c.s === sn && c.i === i;
|
||||
const img = p.still_path ? I + 'w300' + p.still_path : (c.it.backdrop_path ? I + 'w300' + c.it.backdrop_path : PH);
|
||||
car.appendChild(mkf('pe' + (cur ? ' cur' : ''), `<div class="et"><img loading="lazy" src="${img}" alt=""><i>${n}</i>${cur ? '<span class="eq"><u></u><u></u><u></u></span><span class="pg"><u></u></span>' : ''}</div><span class="pn">${esc(p.name || 'Episode ' + n)}</span><small>${p.runtime ? p.runtime + 'm' : 'Episode ' + n}</small>`, () => playEp(sn, i)));
|
||||
});
|
||||
const t = car.querySelector('.cur') || car.firstChild;
|
||||
if (focus && t) setFocus(t);
|
||||
}
|
||||
|
||||
$('#pep').innerHTML = `<div class="peh"><h3 id="peT"></h3><div class="row" id="pseas"></div><div class="pic f" id="pepx">${PI.x}</div></div><div class="row pcar" id="pcar"></div>`;
|
||||
$('#pnext').innerHTML = 'Next Episode' + pi('<path d="M6 5.5v13l9-6.5z"/><path d="M18 5.5v13"/>');
|
||||
$('#pnext')._a = nextEp;
|
||||
$('#pepx')._a = () => closeEps(1);
|
||||
$('#peps')._a = () => pl.classList.contains('eps') ? closeEps(1) : openEps();
|
||||
|
||||
vd.addEventListener('timeupdate', () => {
|
||||
const d = vd.duration || 0;
|
||||
const r = d - vd.currentTime;
|
||||
$('#pnext').classList.toggle('v', !!d && hasNext() && r <= 300 && r > 0);
|
||||
$('#pep').style.setProperty('--p', d ? (vd.currentTime / d) * 100 + '%' : '0%');
|
||||
});
|
||||
|
||||
vd.addEventListener('ended', () => {
|
||||
if (hasNext()) nextEp();
|
||||
});
|
||||
@@ -1,70 +0,0 @@
|
||||
let sqv = '', bgT, stab = 0, SD = { q: '', all: [], mv: [], tv: [] };
|
||||
const SVS = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>';
|
||||
const sdraw = () => { const t = $('#stext'); t.textContent = sqv || 'Search'; t.classList.toggle('q', !!sqv) };
|
||||
function setQ(v) { sqv = v; sdraw(); clearTimeout(st); st = setTimeout(() => fillSearch(sqv.trim()), 300) }
|
||||
function sbgf(it) { clearTimeout(bgT); bgT = setTimeout(() => xf(bgb, I + 'w780' + (it.backdrop_path || it.poster_path)), 120) }
|
||||
async function fillSearch(q) {
|
||||
const my = ++sgen; skelSearch();
|
||||
let all, mv, tv;
|
||||
const ok = x => x.poster_path && (x.media_type === 'movie' || x.media_type === 'tv');
|
||||
if (q) {
|
||||
const d = await api('/search/multi', `&query=${encodeURIComponent(q)}&include_adult=false`);
|
||||
if (my !== sgen) return;
|
||||
all = (d.results || []).filter(ok); mv = all.filter(x => x.media_type === 'movie'); tv = all.filter(x => x.media_type === 'tv')
|
||||
}
|
||||
else {
|
||||
const [a, b] = await Promise.all([api('/trending/movie/week'), api('/trending/tv/week')]);
|
||||
if (my !== sgen) return;
|
||||
mv = (a.results || []).filter(x => x.poster_path).map(x => ({ ...x, media_type: 'movie' }));
|
||||
tv = (b.results || []).filter(x => x.poster_path).map(x => ({ ...x, media_type: 'tv' })); all = []
|
||||
}
|
||||
SD = { q, all, mv, tv }; drawSearch()
|
||||
}
|
||||
function tile(x) {
|
||||
x._t = x.media_type;
|
||||
const e = mkf('sc', `<div class="po"><img src="${I}w342${x.poster_path}" alt=""></div><b>${esc(x.title || x.name || '')}</b><small><span>★ ${(x.vote_average || 0).toFixed(1)}</span><span>${yr(x)}</span><span>${x.media_type === 'tv' ? 'Show' : 'Movie'}</span></small>`, () => openDetail(x));
|
||||
e._bg = x; return e
|
||||
}
|
||||
function drawSearch() {
|
||||
const { q, all, mv, tv } = SD;
|
||||
chips.innerHTML = '';
|
||||
const names = [...new Set((q ? all : [...mv, ...tv]).map(x => x.title || x.name))].slice(0, 9);
|
||||
if (q) chips.appendChild(mkf('chip', SVS + `"${esc(q)}"`, () => { }));
|
||||
names.forEach(n => chips.appendChild(mkf('chip', esc(n), () => setQ(n))));
|
||||
sres.innerHTML = '';
|
||||
const L = stab === 1 ? [['Movies', mv]] : stab === 2 ? [['TV Shows', tv]] : q ? [['Top Matches', all.slice(0, 10)], ['Movies', mv], ['TV Shows', tv]] : [['Trending Movies', mv], ['Trending TV Shows', tv]];
|
||||
let n = 0;
|
||||
L.forEach(([h, a]) => { if (!a.length) return; n++; const sec = document.createElement('section'); sec.className = 'ss'; sec.innerHTML = `<h3>${h}</h3><div class="row ch"></div>`; sec.lastChild.append(...a.map(tile)); sres.appendChild(sec) });
|
||||
if (!n) sres.innerHTML = `<p class="none">No results${q ? ` for \u201c${esc(q)}\u201d` : ''}</p>`;
|
||||
[...tabs.children].forEach((t, i) => t.classList.toggle('act', i === stab));
|
||||
if (cur && !document.body.contains(cur)) setFocus(chips.children[1] || chips.firstChild || kb.children[2])
|
||||
}
|
||||
['Top Results', 'Movies', 'TV Shows'].forEach((t, i) => tabs.appendChild(mkf('tab', t, () => { stab = i; drawSearch() })));
|
||||
const KL = 'abcdefghijklmnopqrstuvwxyz'.split(''), KN = "1234567890.-'&:".split('');
|
||||
let num = false;
|
||||
function buildKb() {
|
||||
kb.innerHTML = '';
|
||||
const mk = (label, cls, fn) => kb.appendChild(mkf('k ' + cls, label, () => { fn(); sr.scrollTo({ top: 0, behavior: 'smooth' }) }));
|
||||
mk(num ? 'ABC' : '123', 'w', () => { num = !num; buildKb(); setFocus(kb.firstChild) });
|
||||
mk('SPACE', 'w', () => { if (sqv && !sqv.endsWith(' ')) setQ(sqv + ' ') });
|
||||
(num ? KN : KL).forEach(c => mk(c, '', () => setQ(sqv + c)));
|
||||
mk('<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M9 5h11a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H9l-6-7z"/><path d="m12 9 5 5m0-5-5 5"/></svg>', 'd', () => setQ(sqv.slice(0, -1)))
|
||||
}
|
||||
buildKb();
|
||||
function openSearch() {
|
||||
setAct('search'); document.body.classList.add('srch'); sr.classList.add('show'); side.classList.remove('open'); sr.scrollTop = 0;
|
||||
if (!sres.children.length) fillSearch('');
|
||||
setFocus(kb.children[2])
|
||||
}
|
||||
function closeSearch(silent) {
|
||||
if (!sr.classList.contains('show')) return;
|
||||
sr.classList.remove('show'); document.body.classList.remove('srch');
|
||||
heroIt = null; bgb._u = null;
|
||||
if (!silent) { setAct(mode); setFocus(document.querySelector('#rows .card')) }
|
||||
}
|
||||
|
||||
|
||||
function skelSearch() {
|
||||
chips.innerHTML = SK.chips(7);
|
||||
sres.innerHTML = [0, 1].map(() => `<section class="ss"><i class="sb h3s"></i><div class="row ch">${SK.tiles(9)}</div></section>`).join('')
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
const NAV = [
|
||||
['search', 'Search', ic('<circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/>')],
|
||||
['discover', 'Discovery', ic('<circle cx="12" cy="12" r="9"/><path d="m15.5 8.5-2 5-5 2 2-5z"/>')],
|
||||
['movie', 'Movies', ic('<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M7 3v18M17 3v18M3 8h4M3 12h4M3 16h4M17 8h4M17 12h4M17 16h4"/>')],
|
||||
['tv', 'TV Shows', ic('<rect x="3" y="7" width="18" height="13" rx="2"/><path d="m8 3 4 4 4-4"/>')],
|
||||
['wl', 'Watch Later', ic(P_WL)],
|
||||
['fav', 'Favorites', ic(P_FV)]
|
||||
];
|
||||
|
||||
NAV.forEach(([k, n, s]) => { const e = document.createElement('div'); e.className = 'ni f'; e.tabIndex = -1; e.innerHTML = s + `<span>${n}</span>`; e._a = () => go(k); NAVEL[k] = e; $('#nav').appendChild(e) });
|
||||
syncNav();
|
||||
function setAct(k) { Object.entries(NAVEL).forEach(([n, e]) => e.classList.toggle('act', n === k)); navAct = NAVEL[k] }
|
||||
const mark = $('#mark'); mark.onerror = () => { mark.onerror = null; mark.src = PH }; mark.src = LOGO;
|
||||
|
||||
|
||||
function syncNav() { ['wl', 'fav'].forEach(k => { if (NAVEL[k]) NAVEL[k].style.display = (LIB[k].length || libK === k) ? '' : 'none' }) }
|
||||
@@ -1,13 +0,0 @@
|
||||
const SK = {
|
||||
cards: n => '<div class="card sl"></div>'.repeat(n),
|
||||
tiles: n => '<div class="sc sl"><div class="po"></div><i class="sb"></i><i class="sb s"></i></div>'.repeat(n),
|
||||
chips: n => Array.from({ length: n }, (_, i) => `<div class="chip sl" style="width:${90 + (i * 37) % 80}px"></div>`).join(''),
|
||||
pep: n => '<div class="pe sl"><div class="et"></div><i class="sb" style="width:70%;height:14px;margin-top:11px"></i><i class="sb" style="width:35%;height:11px;margin-top:6px"></i></div>'.repeat(n),
|
||||
eps: n => '<div class="ep sl"><div class="et"></div><i class="sb" style="width:70%;height:14px;margin-top:12px"></i><i class="sb" style="width:40%;height:11px;margin-top:6px"></i></div>'.repeat(n),
|
||||
rows: n => Array.from({ length: n }, () => '<section class="sec"><i class="sb h2"></i><div class="row">' + SK.cards(14) + '</div></section>').join(''),
|
||||
detail: it => {
|
||||
const bp = it.backdrop_path || it.poster_path || '';
|
||||
return `<div class="dbl" style="background-image:url(${I}w780${bp})"></div><div class="dw"><div class="dimg" style="background-image:url(${I}w1280${bp})"></div><div class="dc"><div class="dh dsk"><i class="sb t"></i><i class="sb m"></i><div class="hb"><i class="sb b"></i><i class="sb c"></i></div><i class="sb l"></i><i class="sb l"></i><i class="sb l x"></i></div>` +
|
||||
`<div class="ds"><i class="sb h3"></i><div class="row">${'<div class="trk"></div>'.repeat(4)}</div></div><div class="ds"><i class="sb h3"></i><div class="row">${SK.cards(9)}</div></div></div></div>`
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user