mirror of
https://gitlab.com/vyla-entertainment/TV.git
synced 2026-11-20 23:15:38 -05:00
ported sdk and this works
This commit is contained in:
@@ -65,6 +65,21 @@
|
||||
filter: drop-shadow(0 4px 18px rgba(0, 0, 0, .6))
|
||||
}
|
||||
|
||||
#dback {
|
||||
position: fixed;
|
||||
top: 3.5vh;
|
||||
left: 3.5vw;
|
||||
z-index: 12;
|
||||
background: rgba(255, 255, 255, .12);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
#dback.on {
|
||||
background: #fff;
|
||||
color: #000;
|
||||
transform: scale(1.08);
|
||||
}
|
||||
|
||||
.dh h1 {
|
||||
font-size: clamp(30px, 4.4vw, 76px);
|
||||
font-weight: 700;
|
||||
|
||||
@@ -702,14 +702,4 @@ video::cue {
|
||||
#pl.cover #pbg {
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
#pv {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
background: #000;
|
||||
z-index: 0;
|
||||
}
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
|
||||
<title>Vyla</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
@@ -15,7 +16,7 @@
|
||||
<link rel="stylesheet" href="css/player.css">
|
||||
<link rel="stylesheet" href="css/skeleton.css">
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
|
||||
<script src="js/hls.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -74,6 +75,9 @@
|
||||
<div id="pspin"></div>
|
||||
<div id="pm"></div>
|
||||
</div>
|
||||
|
||||
<script src="js/vyla-local.js"></script>
|
||||
<script src="js/native.js"></script>
|
||||
<script src="js/core.js"></script>
|
||||
<script src="js/skeleton.js"></script>
|
||||
<script src="js/focus.js"></script>
|
||||
|
||||
@@ -2,7 +2,7 @@ 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 = SK.detail(it); ov.scrollTop = 0;
|
||||
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 }
|
||||
@@ -11,8 +11,8 @@ async function openDetail(it) {
|
||||
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="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>`;
|
||||
const secs = $('#dsecs');
|
||||
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') {
|
||||
|
||||
4
www/js/hls.min.js
vendored
Normal file
4
www/js/hls.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,3 +1,10 @@
|
||||
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',
|
||||
@@ -96,4 +103,10 @@ document.addEventListener('mousemove', e => {
|
||||
document.addEventListener('click', e => {
|
||||
const f = e.target.closest('.f'); if (f) act(f)
|
||||
});
|
||||
ov.addEventListener('wheel', () => { }, { passive: true });
|
||||
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;
|
||||
};
|
||||
112
www/js/native.js
Normal file
112
www/js/native.js
Normal file
@@ -0,0 +1,112 @@
|
||||
(() => {
|
||||
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 [] }
|
||||
}
|
||||
};
|
||||
})();
|
||||
@@ -129,13 +129,7 @@ function buildProxyUrl(rawUrl, headersObj = {}) {
|
||||
}
|
||||
|
||||
async function fetchSources() {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/sources`);
|
||||
const data = await res.json();
|
||||
currentSources = data.sources || [];
|
||||
} catch (_) {
|
||||
currentSources = [];
|
||||
}
|
||||
currentSources = Vyla.sources();
|
||||
}
|
||||
|
||||
async function startConcurrentDiscovery(it, s = null, e = null) {
|
||||
@@ -153,10 +147,8 @@ async function startConcurrentDiscovery(it, s = null, e = null) {
|
||||
if (session !== discoverySession) return;
|
||||
|
||||
const sourcePromises = currentSources.map(async (src) => {
|
||||
let epQuery = s && e ? `&season=${s}&episode=${e}` : '';
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/stream?provider=${src.key}&tmdbId=${it.id}${epQuery}`);
|
||||
const data = await res.json();
|
||||
const data = await Vyla.stream(src.key, it.id, s, e);
|
||||
if (session !== discoverySession) return;
|
||||
|
||||
if (data.success && data.stream) {
|
||||
@@ -287,10 +279,7 @@ async function loadSubtitles(id, s, e) {
|
||||
activeSubtitles = [];
|
||||
|
||||
try {
|
||||
let epQuery = s && e ? `&season=${s}&episode=${e}` : '';
|
||||
const res = await fetch(`${API_BASE}/api/subtitles?tmdbId=${id}${epQuery}`);
|
||||
const data = await res.json();
|
||||
activeSubtitles = data.subtitles || [];
|
||||
activeSubtitles = await Vyla.subtitles(id, s, e);
|
||||
|
||||
activeSubtitles.forEach((sub, idx) => {
|
||||
const track = document.createElement('track');
|
||||
|
||||
18
www/js/vyla-local.js
Normal file
18
www/js/vyla-local.js
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user