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