add priority language setting

This commit is contained in:
TheBeastLT
2021-09-14 21:15:13 +02:00
committed by TheBeastLT
parent 6b1bb8ebba
commit f1a2a69170
4 changed files with 49 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
const { QualityFilter } = require('./filter');
const { languages, containsLanguage } = require('./languages');
const OTHER_QUALITIES = QualityFilter.options.find(option => option.key === 'other');
const CAM_QUALITIES = QualityFilter.options.find(option => option.key === 'cam');
@@ -28,8 +29,25 @@ const SortOptions = {
},
}
}
const LanguageOptions = {
key: 'language',
options: languages.map(lang => ({
key: lang,
label: lang.charAt(0).toUpperCase() + lang.substr(1)
}))
}
function sortStreams(streams, config) {
const language = config[LanguageOptions.key];
if (language) {
const streamsWithLanguage = streams.filter(stream => containsLanguage(stream, language));
const streamsNoLanguage = streams.filter(stream => !streamsWithLanguage.includes(stream));
return _sortStreams(streamsWithLanguage, config).concat(_sortStreams(streamsNoLanguage, config));
}
return _sortStreams(streams, config);
}
function _sortStreams(streams, config) {
const sort = config.sort && config.sort.toLowerCase() || undefined;
const limit = /^[1-9][0-9]*$/.test(config.limit) && parseInt(config.limit) || undefined;
if (sort === SortOptions.options.seeders.key) {
@@ -137,4 +155,5 @@ function parseSize(sizeText) {
}
module.exports = sortStreams;
module.exports.SortOptions = SortOptions;
module.exports.SortOptions = SortOptions;
module.exports.LanguageOptions = LanguageOptions;