mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
allow selecting multiple foreign languages, closes #97
This commit is contained in:
@@ -26,7 +26,7 @@ const PRE_CONFIGURATIONS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const keysToSplit = [Providers.key, QualityFilter.key, DebridOptions.key];
|
const keysToSplit = [Providers.key, LanguageOptions.key, QualityFilter.key, DebridOptions.key];
|
||||||
|
|
||||||
function parseConfiguration(configuration) {
|
function parseConfiguration(configuration) {
|
||||||
if (PRE_CONFIGURATIONS[configuration]) {
|
if (PRE_CONFIGURATIONS[configuration]) {
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ const { PreConfigurations } = require('../lib/configuration');
|
|||||||
function landingTemplate(manifest, config = {}) {
|
function landingTemplate(manifest, config = {}) {
|
||||||
const providers = config.providers || Providers.options.map(provider => provider.key);
|
const providers = config.providers || Providers.options.map(provider => provider.key);
|
||||||
const sort = config[SortOptions.key] || SortOptions.options.qualitySeeders.key;
|
const sort = config[SortOptions.key] || SortOptions.options.qualitySeeders.key;
|
||||||
const language = config[LanguageOptions.key];
|
const languages = config[LanguageOptions.key] || [];
|
||||||
const qualityFilters = config[QualityFilter.key] || [];
|
const qualityFilters = config[QualityFilter.key] || [];
|
||||||
const limit = config.limit || '';
|
const limit = config.limit || '';
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
const sortOptionsHTML = Object.values(SortOptions.options)
|
const sortOptionsHTML = Object.values(SortOptions.options)
|
||||||
.map((option, i) => `<option value="${option.key}" ${i === 0 ? 'selected' : ''}>${option.description}</option>`)
|
.map((option, i) => `<option value="${option.key}" ${i === 0 ? 'selected' : ''}>${option.description}</option>`)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
const languageOptionsHTML = LanguageOptions.options
|
const languagesOptionsHTML = LanguageOptions.options
|
||||||
.map((option, i) => `<option value="${option.key}">${option.label}</option>`)
|
.map((option, i) => `<option value="${option.key}">${option.label}</option>`)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
const qualityFiltersHTML = Object.values(QualityFilter.options)
|
const qualityFiltersHTML = Object.values(QualityFilter.options)
|
||||||
@@ -282,10 +282,9 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
${sortOptionsHTML}
|
${sortOptionsHTML}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label class="label" for="iLanguage">Priority foreign language:</label>
|
<label class="label" for="iLanguages">Priority foreign language:</label>
|
||||||
<select id="iLanguage" class="input" onchange="generateInstallLink()" title="Streams with the selected dubs/subs language will be shown on the top">
|
<select id="iLanguages" class="input" onchange="generateInstallLink()" name="languages[]" multiple="multiple" title="Streams with the selected dubs/subs language will be shown on the top">
|
||||||
<option value="none" selected>None</option>
|
${languagesOptionsHTML}
|
||||||
${languageOptionsHTML}
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label class="label" for="iQualityFilter">Exclude qualities/resolutions:</label>
|
<label class="label" for="iQualityFilter">Exclude qualities/resolutions:</label>
|
||||||
@@ -363,6 +362,12 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
onChange: () => generateInstallLink()
|
onChange: () => generateInstallLink()
|
||||||
});
|
});
|
||||||
$('#iProviders').multiselect('select', [${providers.map(provider => '"' + provider + '"')}]);
|
$('#iProviders').multiselect('select', [${providers.map(provider => '"' + provider + '"')}]);
|
||||||
|
$('#iLanguages').multiselect({
|
||||||
|
nonSelectedText: 'None',
|
||||||
|
buttonTextAlignment: 'left',
|
||||||
|
onChange: () => generateInstallLink()
|
||||||
|
});
|
||||||
|
$('#iLanguages').multiselect('select', [${languages.map(language => '"' + language + '"')}]);
|
||||||
$('#iQualityFilter').multiselect({
|
$('#iQualityFilter').multiselect({
|
||||||
nonSelectedText: 'None',
|
nonSelectedText: 'None',
|
||||||
buttonTextAlignment: 'left',
|
buttonTextAlignment: 'left',
|
||||||
@@ -377,6 +382,7 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
$('#iDebridOptions').multiselect('select', [${debridOptions.map(option => '"' + option + '"')}]);
|
$('#iDebridOptions').multiselect('select', [${debridOptions.map(option => '"' + option + '"')}]);
|
||||||
} else {
|
} else {
|
||||||
$('#iProviders').val([${providers.map(provider => '"' + provider + '"')}]);
|
$('#iProviders').val([${providers.map(provider => '"' + provider + '"')}]);
|
||||||
|
$('#iLanguages').val([${languages.map(language => '"' + language + '"')}]);
|
||||||
$('#iQualityFilter').val([${qualityFilters.map(filter => '"' + filter + '"')}]);
|
$('#iQualityFilter').val([${qualityFilters.map(filter => '"' + filter + '"')}]);
|
||||||
$('#iDebridOptions').val([${debridOptions.map(option => '"' + option + '"')}]);
|
$('#iDebridOptions').val([${debridOptions.map(option => '"' + option + '"')}]);
|
||||||
}
|
}
|
||||||
@@ -389,7 +395,6 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
$('#iPutioClientId').val("${putioClientId}");
|
$('#iPutioClientId').val("${putioClientId}");
|
||||||
$('#iPutioToken').val("${putioToken}");
|
$('#iPutioToken').val("${putioToken}");
|
||||||
$('#iSort').val("${sort}");
|
$('#iSort').val("${sort}");
|
||||||
$('#iLanguage').val("${language || 'none'}");
|
|
||||||
$('#iLimit').val("${limit}");
|
$('#iLimit').val("${limit}");
|
||||||
generateInstallLink();
|
generateInstallLink();
|
||||||
debridProvidersChange();
|
debridProvidersChange();
|
||||||
@@ -420,7 +425,7 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
const providersValue = providersList.join(',');
|
const providersValue = providersList.join(',');
|
||||||
const qualityFilterValue = $('#iQualityFilter').val().join(',') || '';
|
const qualityFilterValue = $('#iQualityFilter').val().join(',') || '';
|
||||||
const sortValue = $('#iSort').val() || '';
|
const sortValue = $('#iSort').val() || '';
|
||||||
const languageValue = $('#iLanguage').val() || '';
|
const languagesValue = $('#iLanguages').val().join(',') || [];
|
||||||
const limitValue = $('#iLimit').val() || '';
|
const limitValue = $('#iLimit').val() || '';
|
||||||
|
|
||||||
const debridOptionsValue = $('#iDebridOptions').val().join(',') || '';
|
const debridOptionsValue = $('#iDebridOptions').val().join(',') || '';
|
||||||
@@ -436,7 +441,7 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
const providers = providersList.length && providersList.length < ${Providers.options.length} && providersValue;
|
const providers = providersList.length && providersList.length < ${Providers.options.length} && providersValue;
|
||||||
const qualityFilters = qualityFilterValue.length && qualityFilterValue;
|
const qualityFilters = qualityFilterValue.length && qualityFilterValue;
|
||||||
const sort = sortValue !== '${SortOptions.options.qualitySeeders.key}' && sortValue;
|
const sort = sortValue !== '${SortOptions.options.qualitySeeders.key}' && sortValue;
|
||||||
const language = languageValue.length && languageValue !== 'none' && languageValue;
|
const languages = languagesValue.length && languagesValue;
|
||||||
const limit = /^[1-9][0-9]{0,2}$/.test(limitValue) && limitValue;
|
const limit = /^[1-9][0-9]{0,2}$/.test(limitValue) && limitValue;
|
||||||
|
|
||||||
const debridOptions = debridOptionsValue.length && debridOptionsValue.trim();
|
const debridOptions = debridOptionsValue.length && debridOptionsValue.trim();
|
||||||
@@ -453,7 +458,7 @@ function landingTemplate(manifest, config = {}) {
|
|||||||
let configurationValue = [
|
let configurationValue = [
|
||||||
['${Providers.key}', providers],
|
['${Providers.key}', providers],
|
||||||
['${SortOptions.key}', sort],
|
['${SortOptions.key}', sort],
|
||||||
['${LanguageOptions.key}', language],
|
['${LanguageOptions.key}', languages],
|
||||||
['${QualityFilter.key}', qualityFilters],
|
['${QualityFilter.key}', qualityFilters],
|
||||||
['limit', limit],
|
['limit', limit],
|
||||||
['${DebridOptions.key}', debridOptions],
|
['${DebridOptions.key}', debridOptions],
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ function mapLanguages(languages) {
|
|||||||
return [...new Set([].concat(mapped).concat(unmapped))];
|
return [...new Set([].concat(mapped).concat(unmapped))];
|
||||||
}
|
}
|
||||||
|
|
||||||
function containsLanguage(stream, language) {
|
function containsLanguage(stream, languages) {
|
||||||
return stream.title.includes(languageMapping[language]);
|
return languages.map(lang => languageMapping[lang]).some(lang => stream.title.includes(lang));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { mapLanguages, containsLanguage, languages }
|
module.exports = { mapLanguages, containsLanguage, languages }
|
||||||
@@ -40,10 +40,10 @@ const LanguageOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sortStreams(streams, config, type) {
|
function sortStreams(streams, config, type) {
|
||||||
const language = config[LanguageOptions.key];
|
const configLanguages = config[LanguageOptions.key];
|
||||||
if (language && language !== languages[0]) {
|
if (configLanguages && configLanguages.length && configLanguages[0] !== languages[0]) {
|
||||||
// No need to filter english since it's hard to predict which entries are english
|
// No need to filter english since it's hard to predict which entries are english
|
||||||
const streamsWithLanguage = streams.filter(stream => containsLanguage(stream, language));
|
const streamsWithLanguage = streams.filter(stream => containsLanguage(stream, configLanguages));
|
||||||
const streamsNoLanguage = streams.filter(stream => !streamsWithLanguage.includes(stream));
|
const streamsNoLanguage = streams.filter(stream => !streamsWithLanguage.includes(stream));
|
||||||
return _sortStreams(streamsWithLanguage, config, type).concat(_sortStreams(streamsNoLanguage, config, type));
|
return _sortStreams(streamsWithLanguage, config, type).concat(_sortStreams(streamsNoLanguage, config, type));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user