feat: make multi sources explicitly configurable

This commit is contained in:
WebStreamr 2025-07-01 18:02:21 +00:00
parent 81434fff0e
commit a0ed13f18e
No known key found for this signature in database
7 changed files with 22 additions and 9 deletions

View file

@ -1,7 +1,7 @@
import { Request, Response, Router } from 'express';
import winston from 'winston';
import { Source } from '../source';
import { Config, Context, CountryCode } from '../types';
import { Config, Context } from '../types';
import { envIsProd, getDefaultConfig, ImdbId, StreamResolver } from '../utils';
import { ContentType } from 'stremio-addon-sdk';
@ -36,7 +36,7 @@ export class StreamController {
this.logger.info(`Search stream for type "${type}" and id "${id}" for ip ${ctx.ip}`, ctx);
const sources = this.sources.filter(handler => handler.countryCodes.filter(countryCode => countryCode in ctx.config || countryCode === CountryCode.multi).length);
const sources = this.sources.filter(handler => handler.countryCodes.filter(countryCode => countryCode in ctx.config).length);
const { streams, ttl } = await this.streamResolver.resolve(ctx, sources, type, ImdbId.fromString(id));

View file

@ -3,6 +3,7 @@ import { Extractor } from './Extractor';
import {
buildMediaFlowProxyExtractorStreamUrl,
Fetcher,
hasMultiEnabled,
iso639FromCountryCode,
supportsMediaFlowProxy,
} from '../utils';
@ -39,7 +40,7 @@ export class VixSrc extends Extractor {
const playlistUrl = await buildMediaFlowProxyExtractorStreamUrl(ctx, this.fetcher, 'VixCloud', url);
const countryCodes = await this.determineCountryCodesFromPlaylist(ctx, playlistUrl);
if (!countryCodes.some(countryCode => countryCode in ctx.config)) {
if (!hasMultiEnabled(ctx.config) && !countryCodes.some(countryCode => countryCode in ctx.config)) {
return [];
}

View file

@ -27,6 +27,6 @@ export class VixSrc implements Source {
? new URL(`/tv/${tmdbId.id}/${tmdbId.season}/${tmdbId.episode}`, this.baseUrl)
: new URL(`/movie/${tmdbId.id}`, this.baseUrl);
return [{ countryCode: CountryCode.it, url }];
return [{ countryCode: CountryCode.multi, url }];
};
}

View file

@ -3,7 +3,7 @@
exports[`VixSrc handle imdb black mirror s4e2 1`] = `
[
{
"countryCode": "it",
"countryCode": "multi",
"url": "https://vixsrc.to/tv/42009/4/2",
},
]
@ -12,7 +12,7 @@ exports[`VixSrc handle imdb black mirror s4e2 1`] = `
exports[`VixSrc handle imdb full metal jacket 1`] = `
[
{
"countryCode": "it",
"countryCode": "multi",
"url": "https://vixsrc.to/movie/600",
},
]

View file

@ -64,6 +64,11 @@ exports[`buildManifest has checked source with appropriate config 1`] = `
exports[`buildManifest has unchecked source without a config 1`] = `
[
{
"key": "multi",
"title": "Multi 🌐 (VixSrc)",
"type": "checkbox",
},
{
"key": "de",
"title": "German 🇩🇪 (StreamKiste, MeineCloud)",

View file

@ -1,7 +1,9 @@
import { Config } from '../types';
export const getDefaultConfig = (): Config => {
return { en: 'on' };
return { multi: 'on', en: 'on' };
};
export const showExternalUrls = (config: Config): boolean => 'includeExternalUrls' in config;
export const hasMultiEnabled = (config: Config): boolean => 'multi' in config;

View file

@ -36,11 +36,16 @@ export const buildManifest = (sources: Source[], config: Config): ManifestWithCo
const countryCodeSources: Partial<Record<CountryCode, Source[]>> = {};
sources.forEach(source =>
source.countryCodes
.filter(countryCode => countryCode !== CountryCode.multi)
.forEach(countryCode => countryCodeSources[countryCode] = [...(countryCodeSources[countryCode] ?? []), source]));
const sortedLanguageSources = typedEntries(countryCodeSources)
.sort(([countryCodeA], [countryCodeB]) => countryCodeA.localeCompare(countryCodeB));
.sort(([countryCodeA], [countryCodeB]) => {
if (countryCodeB === CountryCode.multi) {
return 1;
}
return countryCodeA.localeCompare(countryCodeB);
});
for (const [countryCode, sources] of sortedLanguageSources) {
manifest.config.push({