From 6c6fc992afe0c245cdae9f6b29db756d22d6484c Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 2 Aug 2021 21:18:59 +0300 Subject: [PATCH] Update filter.js --- scripts/filter.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/filter.js b/scripts/filter.js index c36bcfb11c..da0d30b7f8 100644 --- a/scripts/filter.js +++ b/scripts/filter.js @@ -1,6 +1,5 @@ const blacklist = require('./helpers/blacklist.json') const parser = require('./helpers/parser') -const utils = require('./helpers/utils') const log = require('./helpers/log') async function main() { @@ -10,7 +9,10 @@ async function main() { const playlists = parser.parseIndex() for (const playlist of playlists) { log.print(`\nProcessing '${playlist.url}'...`) - await parser.parsePlaylist(playlist.url).then(removeBlacklisted).then(utils.savePlaylist) + await parser + .parsePlaylist(playlist.url) + .then(removeBlacklisted) + .then(p => p.save()) } log.print('\n') @@ -19,19 +21,20 @@ async function main() { async function removeBlacklisted(playlist) { const channels = playlist.channels.filter(channel => { - return !blacklist.find(i => { - const channelName = channel.name.toLowerCase() - return ( - (i.name.toLowerCase() === channelName || - i.aliases.map(i => i.toLowerCase()).includes(channelName)) && - i.country === channel.filename - ) + return !blacklist.find(item => { + const hasSameName = + item.name.toLowerCase() === channel.name.toLowerCase() || + item.aliases.map(alias => alias.toLowerCase()).includes(channel.name.toLowerCase()) + const fromSameCountry = channel.countries.find(c => c.code === item.country) + + return hasSameName && fromSameCountry }) }) if (playlist.channels.length !== channels.length) { log.print(`updated`) playlist.channels = channels + playlist.updated = true } return playlist