From 3c794d6eb76e853cbe39b4d4b194a04f124f9541 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Tue, 13 Jul 2021 18:14:49 +0300 Subject: [PATCH] Create filter.js --- scripts/filter.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 scripts/filter.js diff --git a/scripts/filter.js b/scripts/filter.js new file mode 100644 index 0000000000..ff08aa1ade --- /dev/null +++ b/scripts/filter.js @@ -0,0 +1,63 @@ +const parser = require('./parser') +const utils = require('./utils') +const blacklist = require('./blacklist.json') + +let globalBuffer = [] + +async function main() { + const playlists = parseIndex() + for (const playlist of playlists) { + await loadPlaylist(playlist.url).then(removeBlacklisted).then(savePlaylist).then(done) + } + + 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) +} + +async function removeBlacklisted(playlist) { + console.info(` Looking for blacklisted channels...`) + const list = blacklist.map(i => i.toLowerCase()) + playlist.channels = playlist.channels.filter(i => { + return !list.includes(i.name.toLowerCase()) + }) + + 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()