From b829a236393e07391f3ae58502f57aaf16d4c2be Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Thu, 11 Jan 2024 11:43:16 +0200 Subject: [PATCH] feat: use local-addon instead of running server Signed-off-by: Lachezar Lechev --- package.json | 3 ++- scripts/gen.js | 47 +++++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index c1941b3..864d6cd 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ }, "homepage": "https://github.com/Stremio/stremio-official-addons#readme", "devDependencies": { - "stremio-addon-client": "^1.5.2" + "stremio-addon-client": "^1.5.2", + "stremio-local-addon": "https://git@github.com/Stremio/stremio-local-addon#79cd88c32aa26270af8b662fa7bd92b657f6e14f" }, "workspaces": [ ".", diff --git a/scripts/gen.js b/scripts/gen.js index e01049d..b0a18c0 100755 --- a/scripts/gen.js +++ b/scripts/gen.js @@ -1,7 +1,14 @@ #!/usr/bin/env node -const client = require('stremio-addon-client') + +const client = require('stremio-addon-client'); +const localAddonManifest = require('stremio-local-addon/lib/manifestNoCatalogs'); + +const PROTECTED_URLS = [ + 'https://v3-cinemeta.strem.io/manifest.json', + 'http://127.0.0.1:11470/local-addon/manifest.json', +]; const ENDPOINTS = [ "https://v3-cinemeta.strem.io/manifest.json", "https://v3-channels.strem.io/manifest.json", @@ -14,23 +21,23 @@ const ENDPOINTS = [ const col = new client.AddonCollection() -Promise.all(ENDPOINTS.map(url => client.detectFromURL(url))) -.then(function(responses) { - responses.forEach(function(x, i) { - if (!x.addon) return - if (JSON.stringify(x.addon.manifest).length > 8192) throw 'manifest bigger than 8kb - aborting!' - x.addon.flags = isProtected(x, i) ? { official: true, protected: true } : { official: true } - col.add(x.addon) - }) -}) -.then(function() { - console.log(JSON.stringify(col.save(), null, 4)) -}) - -function isProtected(x, i) { - // cinemeta - if (i === 0) return true +Promise.all(ENDPOINTS.map((transportUrl) => { + if (transportUrl === 'http://127.0.0.1:11470/local-addon/manifest.json') { + // return { response: Promise.resolve(localAddonManifest), transportUrl }; + return Promise.resolve({ addon: new client.AddonClient(localAddonManifest, transportUrl, { official: true, protected: true }), transportUrl }); + } - // local - if (x.addon.manifest.id.match('local')) return true -} + return client.detectFromURL(transportUrl); +})) + .then(function (responses) { + responses.forEach(function (response) { + if (!response.addon) return + if (JSON.stringify(response.addon.manifest).length > 8192) throw 'manifest bigger than 8kb - aborting!' + let isProtected = PROTECTED_URLS.includes(response.transportUrl); + response.addon.flags = isProtected ? { official: true, protected: true } : { official: true } + col.add(response.addon) + }) + }) + .then(function () { + console.log(JSON.stringify(col.save(), null, 4)) + })