diff --git a/src/controller/StreamController.ts b/src/controller/StreamController.ts index 72bc6e8..4604685 100644 --- a/src/controller/StreamController.ts +++ b/src/controller/StreamController.ts @@ -28,6 +28,7 @@ export class StreamController { const id: string = req.params['id'] || ''; const ctx: Context = { + hostUrl: new URL(`${req.protocol}://${req.host}`), id: res.getHeader('X-Request-ID') as string, ...(req.ip && { ip: req.ip }), config, diff --git a/src/index.ts b/src/index.ts index 0f446f3..1be7527 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { CineHDPlus, Cuevana, Eurostreaming, Frembed, FrenchCloud, Source, KinoG import { createExtractors, ExtractorRegistry } from './extractor'; import { ConfigureController, ManifestController, StreamController } from './controller'; import { envGet, envIsProd, Fetcher, StreamResolver, tmdbFetch, TmdbId } from './utils'; +import { Context } from './types'; const logger = winston.createLogger({ transports: [ @@ -72,7 +73,11 @@ addon.listen(port, () => { }); const cacheWarmup = async () => { - const ctx = { id: 'warmup', config: { de: 'on', en: 'on', es: 'on', fr: 'on', it: 'on', mx: 'on' } }; + const ctx: Context = { + hostUrl: new URL('http://localhost'), + id: 'warmup', + config: { de: 'on', en: 'on', es: 'on', fr: 'on', it: 'on', mx: 'on' }, + }; logger.info(`starting cache warmup`, ctx); interface ResponsePartial { results: { id: number }[] } diff --git a/src/test/index.ts b/src/test/index.ts index 29cdece..ed25f50 100644 --- a/src/test/index.ts +++ b/src/test/index.ts @@ -3,6 +3,7 @@ import { getDefaultConfig } from '../utils'; export const createTestContext = (config?: Config): Context => { return { + hostUrl: new URL('http://localhost'), id: 'test', config: config ?? getDefaultConfig(), }; diff --git a/src/types.ts b/src/types.ts index ff91158..2245f89 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,7 @@ import { Manifest, ManifestConfig } from 'stremio-addon-sdk'; export interface Context { + hostUrl: URL; id: string; ip?: string; config: Config; diff --git a/src/utils/StreamResolver.ts b/src/utils/StreamResolver.ts index 6b981cd..94b17d9 100644 --- a/src/utils/StreamResolver.ts +++ b/src/utils/StreamResolver.ts @@ -39,7 +39,7 @@ export class StreamResolver { { name: 'WebStreamr', title: '⚠️ No sources found. Please re-configure the plugin.', - ytId: 'E4WlUXrJgy4', + externalUrl: ctx.hostUrl.href, }, ], }; @@ -73,7 +73,7 @@ export class StreamResolver { streams.push({ name: envGetAppName(), title: [`🔗 ${handler.label}`, this.logErrorAndReturnNiceString(ctx, handler.id, error)].join('\n'), - ytId: 'E4WlUXrJgy4', + externalUrl: ctx.hostUrl.href, }); } }); @@ -136,7 +136,7 @@ export class StreamResolver { return Math.min(...urlResults.map(urlResult => urlResult.ttl as number)); }; - private buildUrl(ctx: Context, urlResult: UrlResult): { externalUrl: string } | { url: string } | { ytId: string } { + private buildUrl(ctx: Context, urlResult: UrlResult): { externalUrl: string } | { url: string } { if (!urlResult.isExternal) { return { url: urlResult.url.href }; } @@ -145,7 +145,7 @@ export class StreamResolver { return { externalUrl: urlResult.url.href }; } - return { ytId: 'E4WlUXrJgy4' }; + return { externalUrl: ctx.hostUrl.href }; }; private buildName(ctx: Context, urlResult: UrlResult): string { diff --git a/src/utils/__snapshots__/StreamResolver.test.ts.snap b/src/utils/__snapshots__/StreamResolver.test.ts.snap index 3707ff7..a7495c7 100644 --- a/src/utils/__snapshots__/StreamResolver.test.ts.snap +++ b/src/utils/__snapshots__/StreamResolver.test.ts.snap @@ -5,59 +5,59 @@ exports[`resolve adds error info 1`] = ` "streams": [ { "behaviorHints": {}, + "externalUrl": "http://localhost/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com ⚠️ Request was blocked.", - "ytId": "E4WlUXrJgy4", }, { "behaviorHints": {}, + "externalUrl": "http://localhost/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com ⚠️ Request was blocked.", - "ytId": "E4WlUXrJgy4", }, { "behaviorHints": {}, + "externalUrl": "http://localhost/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com 🚦 Request was rate-limited. Please try again later or consider self-hosting.", - "ytId": "E4WlUXrJgy4", }, { "behaviorHints": {}, + "externalUrl": "http://localhost/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com 🚦 Too many recent timeouts. Please try again later.", - "ytId": "E4WlUXrJgy4", }, { "behaviorHints": {}, + "externalUrl": "http://localhost/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com ❌ Request failed. Request-id: test.", - "ytId": "E4WlUXrJgy4", }, { "behaviorHints": {}, + "externalUrl": "http://localhost/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com 🐢 Request timed out.", - "ytId": "E4WlUXrJgy4", }, { "behaviorHints": {}, + "externalUrl": "http://localhost/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com ⏳ Request queue is full. Please try again later or consider self-hosting.", - "ytId": "E4WlUXrJgy4", }, { "behaviorHints": {}, + "externalUrl": "http://localhost/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com ❌ Request failed with status 500 (Internal Server Error). Request-id: test.", - "ytId": "E4WlUXrJgy4", }, ], } @@ -151,9 +151,9 @@ exports[`resolve returns info as stream if no sources were configured 1`] = ` { "streams": [ { + "externalUrl": "http://localhost/", "name": "WebStreamr", "title": "⚠️ No sources found. Please re-configure the plugin.", - "ytId": "E4WlUXrJgy4", }, ], } @@ -331,10 +331,10 @@ exports[`resolve returns source errors as stream 1`] = ` { "streams": [ { + "externalUrl": "http://localhost/", "name": "WebStreamr", "title": "🔗 MeineCloud ❌ Request failed. Request-id: test.", - "ytId": "E4WlUXrJgy4", }, ], }