push
This commit is contained in:
+70
-11
@@ -50,6 +50,9 @@
|
||||
seasons: [],
|
||||
episodes: [],
|
||||
streams: [],
|
||||
unsupported: [],
|
||||
providerErrors: {},
|
||||
loadErrors: {},
|
||||
sourceIndex: -1,
|
||||
season: null,
|
||||
episode: null,
|
||||
@@ -380,21 +383,39 @@
|
||||
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() {
|
||||
if (providerNames) return providerNames;
|
||||
async function getProviderCatalog() {
|
||||
if (providerCatalog) return providerCatalog;
|
||||
try {
|
||||
const data = await SR.api.providers();
|
||||
providerNames = SR.config.enabledProviders(data.all || [], data.enabled || []);
|
||||
providerCatalog = { all: data.all || [], enabled: data.enabled || [] };
|
||||
} 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() {
|
||||
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 (state.season == null || state.episode == null) return;
|
||||
query.season = state.season;
|
||||
@@ -407,11 +428,26 @@
|
||||
resumeNote.textContent = '';
|
||||
try {
|
||||
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();
|
||||
pcGear.hidden = state.streams.length === 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) {
|
||||
SR.app.showError(e, 'stream lookup failed');
|
||||
showStatus('Stream lookup failed.', true);
|
||||
@@ -454,8 +490,31 @@
|
||||
b.addEventListener('click', () => playSource(i));
|
||||
list.appendChild(b);
|
||||
}
|
||||
document.getElementById('sourcesCount').textContent =
|
||||
`${state.streams.length} source${state.streams.length === 1 ? '' : 's'}`;
|
||||
const failures = { ...state.loadErrors, ...state.providerErrors };
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user