This commit is contained in:
4DBug
2026-08-26 20:39:37 -05:00
parent 735f9a4375
commit bbb5659e00
7 changed files with 134 additions and 22 deletions
+3 -1
View File
@@ -1,7 +1,9 @@
{ {
"tmdbKey": "ac014b130a8e6344c91dff4e68b18d47", "tmdbKey": "ac014b130a8e6344c91dff4e68b18d47",
"enabledProviders": [ "enabledProviders": [
"cineby" "cineby",
"videasy",
"vidfast"
], ],
"timeoutMs": 30000, "timeoutMs": 30000,
"filters": { "filters": {
+5
View File
@@ -676,6 +676,11 @@ select.field {
color: rgba(255, 255, 255, 0.55); color: rgba(255, 255, 255, 0.55);
} }
.player-sources__group--error {
color: var(--color-danger);
cursor: help;
}
.source-item { .source-item {
display: flex; display: flex;
align-items: center; align-items: center;
+34 -4
View File
@@ -82,16 +82,45 @@
} }
} }
const PREFERRED_PROVIDERS = ['cineby', 'videasy', 'vidfast'];
// Merge the server's provider lists with the user's toggles. // Merge the server's provider lists with the user's toggles.
// Returns the enabled provider names, in the server's `all` order. // Returns the enabled provider names, in the server's `all` order.
function enabledProviders(allNames, serverEnabled) { function enabledProviders(allNames, serverEnabled) {
const all = Array.isArray(allNames) ? allNames : []; const all = Array.isArray(allNames) ? allNames : [];
const overrides = getProviders(); const overrides = getProviders();
if (!overrides) { if (overrides) {
const base = Array.isArray(serverEnabled) && serverEnabled.length ? serverEnabled : all; return Object.keys(overrides).filter((n) => overrides[n] !== false);
return all.filter((n) => base.includes(n));
} }
return all.filter((n) => overrides[n] !== false); const server = Array.isArray(serverEnabled) ? serverEnabled : [];
const wanted = new Set([...PREFERRED_PROVIDERS, ...server]);
return (all.length ? all : PREFERRED_PROVIDERS.slice()).filter((n) =>
wanted.has(n)
);
}
// Watch-page resolver. Re-reads localStorage on every call so provider
// changes made in Settings apply to the next lookup without a reload.
function resolveProviders(catalog) {
const all = Array.isArray(catalog && catalog.all) ? catalog.all : [];
const serverEnabled = Array.isArray(catalog && catalog.enabled) ? catalog.enabled : [];
const overrides = getProviders();
if (overrides) {
return {
names: Object.keys(overrides).filter((n) => overrides[n] !== false),
customized: true,
useServerDefaults: false,
};
}
const wanted = new Set([...PREFERRED_PROVIDERS, ...serverEnabled]);
const names = all.length
? all.filter((n) => wanted.has(n))
: PREFERRED_PROVIDERS.slice();
return {
names,
customized: false,
useServerDefaults: !names.length,
};
} }
window.SR = window.SR || {}; window.SR = window.SR || {};
@@ -106,5 +135,6 @@
setProviders, setProviders,
clearProviders, clearProviders,
enabledProviders, enabledProviders,
resolveProviders,
}; };
})(); })();
+5 -4
View File
@@ -54,8 +54,9 @@
providerList.replaceChildren(); providerList.replaceChildren();
boxes.clear(); boxes.clear();
const overrides = SR.config.getProviders(); const overrides = SR.config.getProviders();
const enabled = SR.config.enabledProviders(allProviders, serverEnabled);
for (const name of allProviders) { for (const name of allProviders) {
const checked = overrides ? overrides[name] !== false : serverEnabled.includes(name); const checked = enabled.includes(name);
const label = document.createElement('label'); const label = document.createElement('label');
label.className = 'provider'; label.className = 'provider';
const input = document.createElement('input'); const input = document.createElement('input');
@@ -71,7 +72,7 @@
providerList.appendChild(label); providerList.appendChild(label);
} }
const on = boxes.size ? Array.from(boxes.values()).filter((b) => b.checked).length : 0; const on = boxes.size ? Array.from(boxes.values()).filter((b) => b.checked).length : 0;
const source = overrides ? 'your selection' : 'server defaults'; const source = overrides ? 'your selection' : 'default sources';
let host; let host;
try { host = new URL(SR.config.getBase()).host; } catch (e) { host = SR.config.getBase(); } try { host = new URL(SR.config.getBase()).host; } catch (e) { host = SR.config.getBase(); }
setStatus(providersStatus, `${on} of ${allProviders.length} enabled — ${source} · ${host}`); setStatus(providersStatus, `${on} of ${allProviders.length} enabled — ${source} · ${host}`);
@@ -96,7 +97,7 @@
}); });
document.getElementById('providersReset').addEventListener('click', () => document.getElementById('providersReset').addEventListener('click', () =>
resetProviders('Using server defaults')); resetProviders('Using default sources'));
async function initSources() { async function initSources() {
try { try {
@@ -147,7 +148,7 @@
document.getElementById('resetProviders').addEventListener('click', () => { document.getElementById('resetProviders').addEventListener('click', () => {
resetProviders(''); resetProviders('');
setStatus(dataStatus, 'Source toggles reset to server defaults.'); setStatus(dataStatus, 'Source toggles reset to default sources.');
}); });
initSources(); initSources();
+16 -1
View File
@@ -50,6 +50,21 @@
return url.replace(/\/t\/p\/[A-Za-z0-9._-]+/, `/t/p/${size}`); return url.replace(/\/t\/p\/[A-Za-z0-9._-]+/, `/t/p/${size}`);
} }
// True when the in-browser player can load the stream through the proxy.
function webPlayable(stream) {
const s = stream || {};
const url = String(s.url || '');
if (!/^https?:\/\//i.test(url)) return false;
const type = String(s.type || '').toLowerCase();
if (['magnet', 'torrent', 'dash', 'mkv', 'avi'].includes(type)) return false;
const isHls = type === 'm3u8' || /\.m3u8($|\?)/i.test(url);
const isDirect =
type === 'mp4' ||
type === 'webm' ||
/\.(mp4|m4v|webm)(\?|#|$)/i.test(url);
return isHls || isDirect;
}
window.SR = window.SR || {}; window.SR = window.SR || {};
SR.util = { escapeHtml, getParam, formatSeconds, runtimeLabel, debounce, tmdbResize }; SR.util = { escapeHtml, getParam, formatSeconds, runtimeLabel, debounce, tmdbResize, webPlayable };
})(); })();
+70 -11
View File
@@ -50,6 +50,9 @@
seasons: [], seasons: [],
episodes: [], episodes: [],
streams: [], streams: [],
unsupported: [],
providerErrors: {},
loadErrors: {},
sourceIndex: -1, sourceIndex: -1,
season: null, season: null,
episode: null, episode: null,
@@ -380,21 +383,39 @@
return SR.storage.keyFor({ type, tmdbId: Number(id), season: state.season, episode: state.episode }); return SR.storage.keyFor({ type, tmdbId: Number(id), season: state.season, episode: state.episode });
} }
let providerNames = null; // cached per page load; null → ask server again let providerCatalog = null; // cached per page load; enabled names are re-read from localStorage every lookup
async function getProviderNames() { async function getProviderCatalog() {
if (providerNames) return providerNames; if (providerCatalog) return providerCatalog;
try { try {
const data = await SR.api.providers(); const data = await SR.api.providers();
providerNames = SR.config.enabledProviders(data.all || [], data.enabled || []); providerCatalog = { all: data.all || [], enabled: data.enabled || [] };
} catch (e) { } catch (e) {
providerNames = null; // unreachable → let /streams use server defaults return { all: [], enabled: [] };
} }
return providerNames; return providerCatalog;
}
async function getProviderInfo() {
if (SR.config.getProviders()) return SR.config.resolveProviders(null);
return SR.config.resolveProviders(await getProviderCatalog());
} }
async function loadStreams() { async function loadStreams() {
const query = { tmdb: id, type, providers: await getProviderNames() }; const providerInfo = await getProviderInfo();
if (!providerInfo.useServerDefaults && providerInfo.names.length === 0) {
closeSources();
pcQuality.textContent = '';
sourceLabel.textContent = '';
resumeNote.textContent = '';
showStatus('No sources are enabled. Open Settings → Sources and enable at least one provider.', true);
return;
}
const query = {
tmdb: id,
type,
providers: providerInfo.useServerDefaults ? null : providerInfo.names,
};
if (type === 'tv') { if (type === 'tv') {
if (state.season == null || state.episode == null) return; if (state.season == null || state.episode == null) return;
query.season = state.season; query.season = state.season;
@@ -407,11 +428,26 @@
resumeNote.textContent = ''; resumeNote.textContent = '';
try { try {
const data = await SR.api.streams(query); const data = await SR.api.streams(query);
state.streams = data.streams || []; const allStreams = data.streams || [];
state.streams = allStreams.filter(SR.util.webPlayable);
state.unsupported = allStreams.filter((s) => !SR.util.webPlayable(s));
state.providerErrors = data.providerErrors || {};
state.loadErrors = data.loadErrors || {};
renderSources(); renderSources();
pcGear.hidden = state.streams.length === 0; pcGear.hidden = state.streams.length === 0;
if (state.streams.length) playSource(0); if (state.streams.length) playSource(0);
else showStatus('No streams found for this title.', true); else {
const failed = Object.keys({ ...state.loadErrors, ...state.providerErrors });
const hidden = state.unsupported.length;
if (failed.length || hidden) {
const parts = ['No web-playable streams found.'];
if (failed.length) parts.push(`Provider failures: ${failed.join(', ')}.`);
if (hidden) parts.push(`Hidden ${hidden} unsupported source(s).`);
showStatus(parts.join(' '), true);
} else {
showStatus('No streams found for this title.', true);
}
}
} catch (e) { } catch (e) {
SR.app.showError(e, 'stream lookup failed'); SR.app.showError(e, 'stream lookup failed');
showStatus('Stream lookup failed.', true); showStatus('Stream lookup failed.', true);
@@ -454,8 +490,31 @@
b.addEventListener('click', () => playSource(i)); b.addEventListener('click', () => playSource(i));
list.appendChild(b); list.appendChild(b);
} }
document.getElementById('sourcesCount').textContent = const failures = { ...state.loadErrors, ...state.providerErrors };
`${state.streams.length} source${state.streams.length === 1 ? '' : 's'}`; const failed = Object.keys(failures);
if (failed.length) {
const note = document.createElement('div');
note.className = 'player-sources__group player-sources__group--error';
note.textContent = `Failed: ${failed.join(', ')}`;
note.title = failed.map((name) => `${name}: ${failures[name] || 'no streams'}`).join('\n');
list.appendChild(note);
}
if (state.unsupported.length) {
const types = [
...new Set(state.unsupported.map((s) => String(s.type || 'unknown').toLowerCase())),
];
const note = document.createElement('div');
note.className = 'player-sources__group player-sources__group--error';
note.textContent = `Hidden unsupported: ${state.unsupported.length} (${types.join(', ')})`;
note.title = state.unsupported
.map((s) => `${s.provider || 'Other'}: ${s.name || 'stream'} (${s.type || 'unknown'})`)
.join('\n');
list.appendChild(note);
}
const count = `${state.streams.length} source${state.streams.length === 1 ? '' : 's'}`;
document.getElementById('sourcesCount').textContent = state.unsupported.length
? `${count} · ${state.unsupported.length} hidden`
: count;
} }
function playSource(i) { function playSource(i) {
+1 -1
View File
@@ -39,7 +39,7 @@
<div class="settings__content"> <div class="settings__content">
<section class="settings__card" id="sources"> <section class="settings__card" id="sources">
<h2>Sources</h2> <h2>Sources</h2>
<p class="settings__hint">Choose which providers to search for streams. Saved in this browser; applies to new lookups.</p> <p class="settings__hint">Choose which providers to search for streams. Saved in this browser; applies from the next stream lookup.</p>
<div class="settings__actions"> <div class="settings__actions">
<button class="btn btn--ghost" id="allOn" type="button">Enable all</button> <button class="btn btn--ghost" id="allOn" type="button">Enable all</button>
<button class="btn btn--ghost" id="allOff" type="button">Disable all</button> <button class="btn btn--ghost" id="allOff" type="button">Disable all</button>