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) {
|
||||
if (PRE_CONFIGURATIONS[configuration]) {
|
||||
|
||||
@@ -195,7 +195,7 @@ const { PreConfigurations } = require('../lib/configuration');
|
||||
function landingTemplate(manifest, config = {}) {
|
||||
const providers = config.providers || Providers.options.map(provider => provider.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 limit = config.limit || '';
|
||||
|
||||
@@ -218,7 +218,7 @@ function landingTemplate(manifest, config = {}) {
|
||||
const sortOptionsHTML = Object.values(SortOptions.options)
|
||||
.map((option, i) => `<option value="${option.key}" ${i === 0 ? 'selected' : ''}>${option.description}</option>`)
|
||||
.join('\n');
|
||||
const languageOptionsHTML = LanguageOptions.options
|
||||
const languagesOptionsHTML = LanguageOptions.options
|
||||
.map((option, i) => `<option value="${option.key}">${option.label}</option>`)
|
||||
.join('\n');
|
||||
const qualityFiltersHTML = Object.values(QualityFilter.options)
|
||||
@@ -282,10 +282,9 @@ function landingTemplate(manifest, config = {}) {
|
||||
${sortOptionsHTML}
|
||||
</select>
|
||||
|
||||
<label class="label" for="iLanguage">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">
|
||||
<option value="none" selected>None</option>
|
||||
${languageOptionsHTML}
|
||||
<label class="label" for="iLanguages">Priority foreign language:</label>
|
||||
<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">
|
||||
${languagesOptionsHTML}
|
||||
</select>
|
||||
|
||||
<label class="label" for="iQualityFilter">Exclude qualities/resolutions:</label>
|
||||
@@ -363,6 +362,12 @@ function landingTemplate(manifest, config = {}) {
|
||||
onChange: () => generateInstallLink()
|
||||
});
|
||||
$('#iProviders').multiselect('select', [${providers.map(provider => '"' + provider + '"')}]);
|
||||
$('#iLanguages').multiselect({
|
||||
nonSelectedText: 'None',
|
||||
buttonTextAlignment: 'left',
|
||||
onChange: () => generateInstallLink()
|
||||
});
|
||||
$('#iLanguages').multiselect('select', [${languages.map(language => '"' + language + '"')}]);
|
||||
$('#iQualityFilter').multiselect({
|
||||
nonSelectedText: 'None',
|
||||
buttonTextAlignment: 'left',
|
||||
@@ -377,6 +382,7 @@ function landingTemplate(manifest, config = {}) {
|
||||
$('#iDebridOptions').multiselect('select', [${debridOptions.map(option => '"' + option + '"')}]);
|
||||
} else {
|
||||
$('#iProviders').val([${providers.map(provider => '"' + provider + '"')}]);
|
||||
$('#iLanguages').val([${languages.map(language => '"' + language + '"')}]);
|
||||
$('#iQualityFilter').val([${qualityFilters.map(filter => '"' + filter + '"')}]);
|
||||
$('#iDebridOptions').val([${debridOptions.map(option => '"' + option + '"')}]);
|
||||
}
|
||||
@@ -389,7 +395,6 @@ function landingTemplate(manifest, config = {}) {
|
||||
$('#iPutioClientId').val("${putioClientId}");
|
||||
$('#iPutioToken').val("${putioToken}");
|
||||
$('#iSort').val("${sort}");
|
||||
$('#iLanguage').val("${language || 'none'}");
|
||||
$('#iLimit').val("${limit}");
|
||||
generateInstallLink();
|
||||
debridProvidersChange();
|
||||
@@ -420,7 +425,7 @@ function landingTemplate(manifest, config = {}) {
|
||||
const providersValue = providersList.join(',');
|
||||
const qualityFilterValue = $('#iQualityFilter').val().join(',') || '';
|
||||
const sortValue = $('#iSort').val() || '';
|
||||
const languageValue = $('#iLanguage').val() || '';
|
||||
const languagesValue = $('#iLanguages').val().join(',') || [];
|
||||
const limitValue = $('#iLimit').val() || '';
|
||||
|
||||
const debridOptionsValue = $('#iDebridOptions').val().join(',') || '';
|
||||
@@ -436,7 +441,7 @@ function landingTemplate(manifest, config = {}) {
|
||||
const providers = providersList.length && providersList.length < ${Providers.options.length} && providersValue;
|
||||
const qualityFilters = qualityFilterValue.length && qualityFilterValue;
|
||||
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 debridOptions = debridOptionsValue.length && debridOptionsValue.trim();
|
||||
@@ -453,7 +458,7 @@ function landingTemplate(manifest, config = {}) {
|
||||
let configurationValue = [
|
||||
['${Providers.key}', providers],
|
||||
['${SortOptions.key}', sort],
|
||||
['${LanguageOptions.key}', language],
|
||||
['${LanguageOptions.key}', languages],
|
||||
['${QualityFilter.key}', qualityFilters],
|
||||
['limit', limit],
|
||||
['${DebridOptions.key}', debridOptions],
|
||||
|
||||
@@ -51,8 +51,8 @@ function mapLanguages(languages) {
|
||||
return [...new Set([].concat(mapped).concat(unmapped))];
|
||||
}
|
||||
|
||||
function containsLanguage(stream, language) {
|
||||
return stream.title.includes(languageMapping[language]);
|
||||
function containsLanguage(stream, languages) {
|
||||
return languages.map(lang => languageMapping[lang]).some(lang => stream.title.includes(lang));
|
||||
}
|
||||
|
||||
module.exports = { mapLanguages, containsLanguage, languages }
|
||||
@@ -40,10 +40,10 @@ const LanguageOptions = {
|
||||
}
|
||||
|
||||
function sortStreams(streams, config, type) {
|
||||
const language = config[LanguageOptions.key];
|
||||
if (language && language !== languages[0]) {
|
||||
const configLanguages = config[LanguageOptions.key];
|
||||
if (configLanguages && configLanguages.length && configLanguages[0] !== languages[0]) {
|
||||
// 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));
|
||||
return _sortStreams(streamsWithLanguage, config, type).concat(_sortStreams(streamsNoLanguage, config, type));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user