mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
generalise pre-configurations
This commit is contained in:
@@ -1,14 +1,34 @@
|
|||||||
const { DebridOptions } = require('../moch/options');
|
const { DebridOptions } = require('../moch/options');
|
||||||
const { QualityFilter, Providers } = require('./filter');
|
const { QualityFilter, Providers } = require('./filter');
|
||||||
|
|
||||||
const LITE_CONFIG = liteConfig();
|
const PRE_CONFIGURATIONS = {
|
||||||
const LITE_CONFIG_VALUE = liteConfigValue();
|
lite: {
|
||||||
|
config: liteConfig(),
|
||||||
|
serialized: configValue(liteConfig()),
|
||||||
|
manifest: {
|
||||||
|
id: 'com.stremio.torrentio.lite.addon',
|
||||||
|
name: 'Torrentio Lite',
|
||||||
|
description: 'Preconfigured Lite version of Torrentio addon.'
|
||||||
|
+ ' To configure advanced options visit https://torrentio.strem.fun/lite'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
brazuca: {
|
||||||
|
config: brazucaConfig(),
|
||||||
|
serialized: configValue(brazucaConfig()),
|
||||||
|
manifest: {
|
||||||
|
id: 'com.stremio.torrentio.brazuca.addon',
|
||||||
|
name: 'Torrentio Brazuca',
|
||||||
|
description: 'Preconfigured version of Torrentio addon for Brazilian content.'
|
||||||
|
+ ' To configure advanced options visit https://torrentio.strem.fun/brazuca'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const keysToSplit = [Providers.key, QualityFilter.key, DebridOptions.key];
|
const keysToSplit = [Providers.key, QualityFilter.key, DebridOptions.key];
|
||||||
|
|
||||||
function parseConfiguration(configuration) {
|
function parseConfiguration(configuration) {
|
||||||
if (configuration === 'lite') {
|
if (PRE_CONFIGURATIONS[configuration]) {
|
||||||
return LITE_CONFIG;
|
return PRE_CONFIGURATIONS[configuration].config;
|
||||||
}
|
}
|
||||||
const configValues = configuration.split('|')
|
const configValues = configuration.split('|')
|
||||||
.reduce((map, next) => {
|
.reduce((map, next) => {
|
||||||
@@ -29,16 +49,26 @@ function liteConfig() {
|
|||||||
config[Providers.key] = Providers.options.filter(provider => !provider.foreign).map(provider => provider.key);
|
config[Providers.key] = Providers.options.filter(provider => !provider.foreign).map(provider => provider.key);
|
||||||
config[QualityFilter.key] = ['scr', 'cam']
|
config[QualityFilter.key] = ['scr', 'cam']
|
||||||
config['limit'] = 1;
|
config['limit'] = 1;
|
||||||
config['lite'] = true;
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
function liteConfigValue() {
|
function brazucaConfig() {
|
||||||
return Object.entries(LITE_CONFIG)
|
const config = {};
|
||||||
.filter(([key]) => key !== 'lite')
|
config[Providers.key] = ['nyaasi', 'comando', 'comoeubaixo', 'lapumia', 'ondebaixa'];
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
function configValue(config) {
|
||||||
|
return Object.entries(config)
|
||||||
.map(([key, value]) => `${key}=${Array.isArray(value) ? value.join(',') : value}`)
|
.map(([key, value]) => `${key}=${Array.isArray(value) ? value.join(',') : value}`)
|
||||||
.join('|');
|
.join('|');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = parseConfiguration;
|
function getManifestOverride(config) {
|
||||||
module.exports.LiteConfigValue = LITE_CONFIG_VALUE;
|
const preConfig = Object.values(PRE_CONFIGURATIONS).find(pre => pre.config === config);
|
||||||
|
return preConfig ? preConfig.manifest : {};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.PreConfigurations = PRE_CONFIGURATIONS;
|
||||||
|
module.exports.parseConfiguration = parseConfiguration;
|
||||||
|
module.exports.getManifestOverride = getManifestOverride;
|
||||||
@@ -185,7 +185,7 @@ const { SortOptions } = require('./sort');
|
|||||||
const { QualityFilter } = require('./filter');
|
const { QualityFilter } = require('./filter');
|
||||||
const { DebridOptions } = require('../moch/options');
|
const { DebridOptions } = require('../moch/options');
|
||||||
const { MochOptions } = require('../moch/moch');
|
const { MochOptions } = require('../moch/moch');
|
||||||
const { LiteConfigValue } = require('../lib/configuration');
|
const { PreConfigurations } = require('../lib/configuration');
|
||||||
|
|
||||||
function landingTemplate(manifest, config = {}) {
|
function landingTemplate(manifest, config = {}) {
|
||||||
const providers = config.providers || [];
|
const providers = config.providers || [];
|
||||||
@@ -227,6 +227,9 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
.join('\n');
|
.join('\n');
|
||||||
const stylizedTypes = manifest.types
|
const stylizedTypes = manifest.types
|
||||||
.map(t => t[0].toUpperCase() + t.slice(1) + (t !== 'series' ? 's' : ''));
|
.map(t => t[0].toUpperCase() + t.slice(1) + (t !== 'series' ? 's' : ''));
|
||||||
|
const preConfigurationObject = Object.entries(PreConfigurations)
|
||||||
|
.map(([key, config]) => `${key}: '${config.serialized}'`)
|
||||||
|
.join(',');
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -403,7 +406,10 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
const allDebrid = allDebridValue.length && allDebridValue.trim();
|
const allDebrid = allDebridValue.length && allDebridValue.trim();
|
||||||
const debridLink = debridLinkValue.length && debridLinkValue.trim();
|
const debridLink = debridLinkValue.length && debridLinkValue.trim();
|
||||||
const putio = putioClientIdValue.length && putioTokenValue.length && putioClientIdValue.trim() + '@' + putioTokenValue.trim();
|
const putio = putioClientIdValue.length && putioTokenValue.length && putioClientIdValue.trim() + '@' + putioTokenValue.trim();
|
||||||
|
|
||||||
|
const preConfigurations = {
|
||||||
|
${preConfigurationObject}
|
||||||
|
};
|
||||||
let configurationValue = [
|
let configurationValue = [
|
||||||
['${Providers.key}', providers],
|
['${Providers.key}', providers],
|
||||||
['${SortOptions.key}', sort],
|
['${SortOptions.key}', sort],
|
||||||
@@ -416,7 +422,9 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
['${MochOptions.debridlink.key}', debridLink],
|
['${MochOptions.debridlink.key}', debridLink],
|
||||||
['${MochOptions.putio.key}', putio]
|
['${MochOptions.putio.key}', putio]
|
||||||
].filter(([_, value]) => value.length).map(([key, value]) => key + '=' + value).join('|');
|
].filter(([_, value]) => value.length).map(([key, value]) => key + '=' + value).join('|');
|
||||||
configurationValue = '${LiteConfigValue}' === configurationValue ? 'lite' : configurationValue;
|
configurationValue = Object.entries(preConfigurations)
|
||||||
|
.filter(([key, value]) => value === configurationValue)
|
||||||
|
.map(([key, value]) => key)[0] || configurationValue;
|
||||||
const configuration = configurationValue && configurationValue.length ? '/' + configurationValue : '';
|
const configuration = configurationValue && configurationValue.length ? '/' + configurationValue : '';
|
||||||
installLink.href = 'stremio://' + window.location.host + configuration + '/manifest.json';
|
installLink.href = 'stremio://' + window.location.host + configuration + '/manifest.json';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
const { MochOptions } = require('../moch/moch');
|
const { MochOptions } = require('../moch/moch');
|
||||||
const { Providers } = require('./filter');
|
const { Providers } = require('./filter');
|
||||||
const { showDebridCatalog } = require('../moch/options');
|
const { showDebridCatalog } = require('../moch/options');
|
||||||
|
const { getManifestOverride } = require('./configuration');
|
||||||
const { Type } = require('./types');
|
const { Type } = require('./types');
|
||||||
|
|
||||||
const DefaultProviders = Providers.options.map(provider => provider.key);
|
const DefaultProviders = Providers.options.map(provider => provider.key);
|
||||||
const CatalogMochs = Object.values(MochOptions).filter(moch => moch.catalog);
|
const CatalogMochs = Object.values(MochOptions).filter(moch => moch.catalog);
|
||||||
|
|
||||||
function manifest(config = {}) {
|
function manifest(config = {}) {
|
||||||
return {
|
const defaultManifest = {
|
||||||
id: `com.stremio.torrentio${config.lite ? '.lite' : ''}.addon`,
|
id: 'com.stremio.torrentio.addon',
|
||||||
version: '0.0.11',
|
version: '0.0.11',
|
||||||
name: `Torrentio${config.lite ? ' Lite' : ''}`,
|
name: 'Torrentio',
|
||||||
description: getDescription(config),
|
description: getDescription(config),
|
||||||
catalogs: getCatalogs(config),
|
catalogs: getCatalogs(config),
|
||||||
resources: getResources(config),
|
resources: getResources(config),
|
||||||
@@ -22,6 +23,8 @@ function manifest(config = {}) {
|
|||||||
configurationRequired: false
|
configurationRequired: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const overrideManifest = getManifestOverride(config);
|
||||||
|
return Object.assign(defaultManifest, overrideManifest);
|
||||||
}
|
}
|
||||||
|
|
||||||
function dummyManifest() {
|
function dummyManifest() {
|
||||||
@@ -32,10 +35,6 @@ function dummyManifest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDescription(config) {
|
function getDescription(config) {
|
||||||
if (config.lite) {
|
|
||||||
return 'Preconfigured Lite version of Torrentio addon.'
|
|
||||||
+ ' To configure advanced options visit https://torrentio.strem.fun/lite';
|
|
||||||
}
|
|
||||||
const providersList = config.providers || DefaultProviders;
|
const providersList = config.providers || DefaultProviders;
|
||||||
const enabledProvidersDesc = Providers.options
|
const enabledProvidersDesc = Providers.options
|
||||||
.map(provider => `${provider.label}${providersList.includes(provider.key) ? '(+)' : '(-)'}`)
|
.map(provider => `${provider.label}${providersList.includes(provider.key) ? '(+)' : '(-)'}`)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const requestIp = require('request-ip');
|
|||||||
const addonInterface = require('./addon');
|
const addonInterface = require('./addon');
|
||||||
const qs = require('querystring')
|
const qs = require('querystring')
|
||||||
const { manifest } = require('./lib/manifest');
|
const { manifest } = require('./lib/manifest');
|
||||||
const parseConfiguration = require('./lib/configuration');
|
const { parseConfiguration, PreConfigurations } = require('./lib/configuration');
|
||||||
const landingTemplate = require('./lib/landingTemplate');
|
const landingTemplate = require('./lib/landingTemplate');
|
||||||
const moch = require('./moch/moch');
|
const moch = require('./moch/moch');
|
||||||
|
|
||||||
@@ -22,8 +22,8 @@ router.get('/', (_, res) => {
|
|||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/lite', (_, res) => {
|
router.get(`/:preconfiguration(${Object.keys(PreConfigurations).join('|')})`, (req, res) => {
|
||||||
res.redirect('/lite/configure')
|
res.redirect(`/${req.params.preconfiguration}/configure`)
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user