mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
114 lines
2.5 KiB
JavaScript
114 lines
2.5 KiB
JavaScript
const Providers = [
|
|
'YTS',
|
|
'EZTV',
|
|
'RARBG',
|
|
'1337x',
|
|
'ThePirateBay',
|
|
'KickassTorrents',
|
|
'TorrentGalaxy',
|
|
'Rutor',
|
|
'HorribleSubs',
|
|
'NyaaSi',
|
|
'NyaaPantsu'
|
|
];
|
|
const QualityFilter = {
|
|
key: 'qualityfilter',
|
|
options: [
|
|
{
|
|
key: "4k",
|
|
label: "4k",
|
|
items: ["4k"],
|
|
test(quality) {
|
|
return this.items.includes(quality);
|
|
}
|
|
},
|
|
{
|
|
key: "1080p",
|
|
label: "1080p",
|
|
items: ["1080p"],
|
|
test(quality) {
|
|
return this.items.includes(quality)
|
|
}
|
|
},
|
|
{
|
|
key: "720p",
|
|
label: "720p",
|
|
items: ["720p"],
|
|
test(quality) {
|
|
return this.items.includes(quality)
|
|
}
|
|
},
|
|
{
|
|
key: "480p",
|
|
label: "480p",
|
|
items: ["480p"],
|
|
test(quality) {
|
|
return this.items.includes(quality)
|
|
}
|
|
},
|
|
{
|
|
key: "sd",
|
|
label: "SD",
|
|
items: ["DVDRip", "HDRip", "BDRip", "BRRip", "BluRay", "WED-DL", "WEBRip", "HDTV", "DivX", "XviD"],
|
|
test(quality) {
|
|
return this.items.includes(quality)
|
|
}
|
|
},
|
|
{
|
|
key: "scr",
|
|
label: "Screener",
|
|
items: ["SCR"],
|
|
test(quality) {
|
|
return this.items.includes(quality)
|
|
}
|
|
},
|
|
{
|
|
key: "cam",
|
|
label: "Cam",
|
|
items: ["CAM", "TeleSync", "TeleCine"],
|
|
test(quality) {
|
|
return this.items.includes(quality)
|
|
}
|
|
},
|
|
{
|
|
key: "unknown",
|
|
label: "Unknown",
|
|
test(quality) {
|
|
return !quality
|
|
}
|
|
}
|
|
]
|
|
};
|
|
const defaultProviderKeys = Providers.map(provider => provider.toLowerCase());
|
|
|
|
function applyFilters(streams, config) {
|
|
return filterByQuality(filterByProvider(streams, config), config);
|
|
}
|
|
|
|
function filterByProvider(streams, config) {
|
|
const providers = config.providers || defaultProviderKeys;
|
|
if (!providers || !providers.length) {
|
|
return streams;
|
|
}
|
|
return streams.filter(stream => {
|
|
const match = stream.title.match(/⚙.* ([^ \n]+)/);
|
|
const provider = match && match[1].toLowerCase();
|
|
return providers.includes(provider);
|
|
})
|
|
}
|
|
|
|
function filterByQuality(streams, config) {
|
|
const filters = config[QualityFilter.key];
|
|
if (!filters) {
|
|
return streams;
|
|
}
|
|
const filterOptions = QualityFilter.options.filter(option => filters.includes(option.key));
|
|
return streams.filter(stream => {
|
|
const streamQuality = stream.name.split('\n')[1];
|
|
return !filterOptions.some(option => option.test(streamQuality));
|
|
});
|
|
}
|
|
|
|
module.exports = applyFilters;
|
|
module.exports.Providers = Providers;
|
|
module.exports.QualityFilter = QualityFilter; |