From c7e7fefc813d0bb1a7667da3b281a0a5b95128e8 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Thu, 11 Jan 2024 12:31:46 +0200 Subject: [PATCH] feat: use local-addon instead of running server Signed-off-by: Lachezar Lechev --- index.json | 29 +++++++++++++++-------------- package.json | 3 ++- scripts/gen.js | 47 ++++++++++++++++++++++++++++------------------- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/index.json b/index.json index a403a8a..d40589c 100644 --- a/index.json +++ b/index.json @@ -744,7 +744,6 @@ "newEpisodeNotifications": true } }, - "transportName": "http", "transportUrl": "https://v3-cinemeta.strem.io/manifest.json", "flags": { "official": true, @@ -813,10 +812,10 @@ } ] }, - "transportName": "http", "transportUrl": "https://v3-channels.strem.io/manifest.json", "flags": { - "official": true + "official": true, + "protected": false } }, { @@ -838,10 +837,10 @@ "tt" ] }, - "transportName": "http", "transportUrl": "https://watchhub.strem.io/manifest.json", "flags": { - "official": true + "official": true, + "protected": false } }, { @@ -876,10 +875,10 @@ "tt" ] }, - "transportName": "http", "transportUrl": "https://caching.stremio.net/publicdomainmovies.now.sh/manifest.json", "flags": { - "official": true + "official": true, + "protected": false } }, { @@ -901,10 +900,10 @@ ], "logo": "http://www.strem.io/images/addons/opensubtitles-logo.png" }, - "transportName": "http", "transportUrl": "https://opensubtitles-v3.strem.io/manifest.json", "flags": { - "official": true + "official": true, + "protected": false } }, { @@ -922,12 +921,15 @@ "movie", "other" ], - "catalogs": [] + "catalogs": [], + "behaviorHints": { + "adult": false + } }, - "transportName": "legacy", "transportUrl": "https://opensubtitles.strem.io/stremio/v1", "flags": { - "official": true + "official": true, + "protected": false } }, { @@ -965,11 +967,10 @@ ], "catalogs": [] }, - "transportName": "http", "transportUrl": "http://127.0.0.1:11470/local-addon/manifest.json", "flags": { "official": true, "protected": true } } -] \ No newline at end of file +] 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..ed092db 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 AddonClient = require('stremio-addon-client/lib/AddonClient'); +const transports = require('stremio-addon-client/lib/transports'); +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,25 @@ 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)) -}) +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 AddonClient(localAddonManifest, new transports.http(transportUrl), { official: true, protected: true }), transportUrl }); + } + + return client.detectFromURL(transportUrl); +})) + .then(function (responses) { + responses.forEach(function (response) { + if (!response.addon) return + let descriptor = response.addon.toDescriptor(); -function isProtected(x, i) { - // cinemeta - if (i === 0) return true + if (JSON.stringify(descriptor.manifest).length > 8192) throw 'manifest bigger than 8kb - aborting!' + let isProtected = PROTECTED_URLS.includes(descriptor.transportUrl); - // local - if (x.addon.manifest.id.match('local')) return true -} + col.add(new AddonClient(descriptor.manifest, new transports.http(descriptor.transportUrl), { official: true, protected: isProtected })) + }) + }) + .then(function () { + console.log(JSON.stringify(col.save(), null, 4)) + })