From 3e2bd0c36bce5b2389ec4d75d1b5c1bbafd1c7a4 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 1 Aug 2021 07:55:18 +0300 Subject: [PATCH] Update filter.js --- scripts/filter.js | 59 +++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/scripts/filter.js b/scripts/filter.js index ec90cab56b..35017c4f76 100644 --- a/scripts/filter.js +++ b/scripts/filter.js @@ -1,32 +1,23 @@ +const blacklist = require('./blacklist.json') const parser = require('./parser') const utils = require('./utils') -const blacklist = require('./blacklist.json') +const log = require('./log') async function main() { - const playlists = parseIndex() + log.start() + + log.print(`Parsing 'index.m3u'...`) + const playlists = parser.parseIndex() for (const playlist of playlists) { - await loadPlaylist(playlist.url).then(removeBlacklisted).then(savePlaylist).then(done) + log.print(`\nProcessing '${playlist.url}'...`) + await parser.parsePlaylist(playlist.url).then(removeBlacklisted).then(utils.savePlaylist) } - finish() -} - -function parseIndex() { - console.info(`Parsing 'index.m3u'...`) - let playlists = parser.parseIndex() - console.info(`Found ${playlists.length} playlist(s)\n`) - - return playlists -} - -async function loadPlaylist(url) { - console.info(`Processing '${url}'...`) - return parser.parsePlaylist(url) + log.finish() } async function removeBlacklisted(playlist) { - console.info(` Looking for blacklisted channels...`) - playlist.channels = playlist.channels.filter(channel => { + const channels = playlist.channels.filter(channel => { return !blacklist.find(i => { const channelName = channel.name.toLowerCase() return ( @@ -37,31 +28,13 @@ async function removeBlacklisted(playlist) { }) }) + if (playlist.channels.length !== channels.length) { + log.print(`updated`) + } + + playlist.channels = channels + return playlist } -async function savePlaylist(playlist) { - console.info(` Saving playlist...`) - const original = utils.readFile(playlist.url) - const output = playlist.toString({ raw: true }) - - if (original === output) { - console.info(`No changes have been made.`) - return false - } else { - utils.createFile(playlist.url, output) - console.info(`Playlist has been updated.`) - } - - return true -} - -async function done() { - console.info(` `) -} - -function finish() { - console.info('Done.') -} - main()