From 4daa6441eede8aa630108c21f8760fa7c19a3745 Mon Sep 17 00:00:00 2001 From: Viren070 Date: Thu, 5 Jun 2025 18:59:12 +0100 Subject: [PATCH] fix: add verbose logging for resources and fix addon catalog support --- packages/core/src/main.ts | 39 ++++++++++++++++++- packages/server/src/app.ts | 2 + packages/server/src/middlewares/errors.ts | 2 +- .../server/src/routes/stremio/manifest.ts | 3 ++ packages/server/src/utils/responses.ts | 22 +++++++---- 5 files changed, 57 insertions(+), 11 deletions(-) diff --git a/packages/core/src/main.ts b/packages/core/src/main.ts index 9086a704..b53dab8c 100644 --- a/packages/core/src/main.ts +++ b/packages/core/src/main.ts @@ -265,7 +265,7 @@ export class AIOStreams { // step 2 // get the actual catalog id from the id - const actualCatalogId = id.split('.', 2)[1]; + const actualCatalogId = id.split('.').slice(1).join('.'); // step 3 // get the catalog from the addon let catalog = await new Wrapper(addon).getCatalog( @@ -441,7 +441,7 @@ export class AIOStreams { // step 2 // get the actual addon catalog id from the id - const actualAddonCatalogId = id.split('.', 2)[1]; + const actualAddonCatalogId = id.split('.').slice(1).join('.'); // step 3 // get the addon catalog from the addon @@ -513,6 +513,12 @@ export class AIOStreams { const addon = this.addons[Number(index)]; + logger.verbose( + `Determined that ${addon.identifyingName} (Index: ${index}) has support for the following resources: ${JSON.stringify( + addonResources + )}` + ); + // Filter and merge resources for (const resource of addonResources) { if ( @@ -572,6 +578,35 @@ export class AIOStreams { this.supportedResources[Number(index)] = addonResources; } + logger.verbose( + `Parsed all catalogs and determined the following catalogs: ${JSON.stringify( + this.finalCatalogs.map((c) => ({ + id: c.id, + name: c.name, + type: c.type, + })) + )}` + ); + + logger.verbose( + `Parsed all addon catalogs and determined the following catalogs: ${JSON.stringify( + this.finalAddonCatalogs?.map((c) => ({ + id: c.id, + name: c.name, + type: c.type, + })) + )}` + ); + + logger.verbose( + `Parsed all resources and determined the following resources: ${JSON.stringify( + this.finalResources.map((r) => ({ + name: r.name, + types: r.types, + })) + )}` + ); + if (this.userData.catalogModifications) { this.finalCatalogs = this.finalCatalogs // Sort catalogs based on catalogModifications order, with non-modified catalogs at the end diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts index 3e1a0627..05bd7aeb 100644 --- a/packages/server/src/app.ts +++ b/packages/server/src/app.ts @@ -14,6 +14,7 @@ import { catalog, meta, subtitle, + addonCatalog, } from './routes/stremio'; import { @@ -73,6 +74,7 @@ stremioAuthRouter.use('/configure.txt', (req, res) => { stremioAuthRouter.use('/meta', meta); stremioAuthRouter.use('/catalog', catalog); stremioAuthRouter.use('/subtitles', subtitle); +stremioAuthRouter.use('/addon_catalog', addonCatalog); app.use('/stremio', stremioRouter); // For public routes app.use('/stremio/:uuid/:encryptedPassword', stremioAuthRouter); // For authenticated routes diff --git a/packages/server/src/middlewares/errors.ts b/packages/server/src/middlewares/errors.ts index 2c52b399..c8fb4908 100644 --- a/packages/server/src/middlewares/errors.ts +++ b/packages/server/src/middlewares/errors.ts @@ -27,7 +27,7 @@ export const errorMiddleware = ( let stremioResponse = false; const match = req.originalUrl.match( - /\/stremio(?:\/[^\/]+){0,2}\/(stream|catalog|subtitles|meta)/ + /\/stremio(?:\/[^\/]+){0,2}\/(stream|catalog|subtitles|meta|addon_catalog)/ ); if (match) { stremioResponse = true; diff --git a/packages/server/src/routes/stremio/manifest.ts b/packages/server/src/routes/stremio/manifest.ts index b0de2bca..27081cf7 100644 --- a/packages/server/src/routes/stremio/manifest.ts +++ b/packages/server/src/routes/stremio/manifest.ts @@ -22,6 +22,7 @@ const manifest = async (config?: UserData): Promise => { } let catalogs: Manifest['catalogs'] = []; let resources: Manifest['resources'] = []; + let addonCatalogs: Manifest['addonCatalogs'] = []; if (config) { const aiostreams = new AIOStreams(config); @@ -29,6 +30,7 @@ const manifest = async (config?: UserData): Promise => { catalogs = aiostreams.getCatalogs(); resources = aiostreams.getResources(); + addonCatalogs = aiostreams.getAddonCatalogs(); } return { name: config?.addonName || Env.ADDON_NAME, @@ -48,6 +50,7 @@ const manifest = async (config?: UserData): Promise => { configurable: true, configurationRequired: config ? false : true, }, + addonCatalogs, stremioAddonsConfig: Env.STREMIO_ADDONS_CONFIG_ISSUER && Env.STREMIO_ADDONS_CONFIG_SIGNATURE ? { diff --git a/packages/server/src/utils/responses.ts b/packages/server/src/utils/responses.ts index af0cf55c..81a1e10b 100644 --- a/packages/server/src/utils/responses.ts +++ b/packages/server/src/utils/responses.ts @@ -28,17 +28,17 @@ export function createResponse( const { success, data, error } = options; let type: string = 'api'; // adapt responses for path specific response types + let stremioResponse = false; if (adaptResponses && path) { - if (path.match(/\/stremio(?:\/[^\/]+){0,2}\/stream/)) { - type = 'stream'; - } else if (path.match(/\/stremio(?:\/[^\/]+){0,2}\/catalog/)) { - type = 'catalog'; - } else if (path.match(/\/stremio(?:\/[^\/]+){0,2}\/subtitles/)) { - type = 'subtitles'; - } else if (path.match(/\/stremio(?:\/[^\/]+){0,2}\/meta/)) { - type = 'meta'; + const match = path?.match( + /\/stremio(?:\/[^\/]+){0,2}\/(stream|catalog|subtitles|meta|addon_catalog)/ + ); + if (match) { + stremioResponse = true; + type = match[1]; } } + logger.debug('Creating response object', { success, error, @@ -80,6 +80,12 @@ export function createResponse( meta: data, }; } + case 'addon_catalog': + if (success) { + return { + addons: data, + }; + } default: return { success,