diff --git a/helpers/filter.js b/helpers/filter.js new file mode 100644 index 000000000..176c3cca2 --- /dev/null +++ b/helpers/filter.js @@ -0,0 +1,54 @@ +const util = require('./util') + +const debug = false +const blacklist = [ + '80.80.160.168', // repeats on a loop +] +let stats = { + total: 0, + removed: 0 +} + +function init() { + + let countries = util.parsePlaylist('index.m3u') + + if(debug) { + countries = countries.slice(0, 2) + } + + let channels = [] + + for(let country of countries) { + + const playlist = util.parsePlaylist(country.file) + + for(let item of playlist) { + + const url = new URL(item.file) + const host = url.hostname + + if(blacklist.indexOf(host) === -1) { + channels.push(item) + } else { + stats.removed += 1 + } + } + + util.createFile(country.file, '#EXTM3U\n') + + channels.forEach(item => { + const data = '#EXTINF:' + item.title + '\n' + item.file + '\n' + + util.writeToFile(country.file, data) + }) + + stats.total += channels.length + + channels = [] + } +} + +init() + +console.log(`Total: ${stats.total}. Removed: ${stats.removed}`) diff --git a/package.json b/package.json index fce6d373c..97bfcb567 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "scripts": { "test": "node test/index.js", "generate": "node helpers/generate.js", - "format": "node helpers/format.js" + "format": "node helpers/format.js", + "filter": "node helpers/filter.js" }, "repository": { "type": "git",