You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iptv/scripts/filter.js

44 lines
1.0 KiB
JavaScript

const blacklist = require('./data/blacklist.json')
3 years ago
const parser = require('./helpers/parser')
3 years ago
const file = require('./helpers/file')
3 years ago
const log = require('./helpers/log')
4 years ago
async function main() {
3 years ago
log.start()
3 years ago
const files = await file.list()
if (!files.length) log.print(`No files is selected\n`)
for (const file of files) {
log.print(`\nProcessing '${file}'...`)
3 years ago
await parser
3 years ago
.parsePlaylist(file)
3 years ago
.then(removeBlacklisted)
.then(p => p.save())
4 years ago
}
3 years ago
log.print('\n')
3 years ago
log.finish()
4 years ago
}
3 years ago
function removeBlacklisted(playlist) {
3 years ago
const channels = playlist.channels.filter(channel => {
3 years ago
return !blacklist.find(item => {
3 years ago
const regexp = new RegExp(item.regex, 'i')
const hasSameName = regexp.test(channel.name)
3 years ago
const fromSameCountry = playlist.country.code === item.country
3 years ago
return hasSameName && fromSameCountry
4 years ago
})
4 years ago
})
3 years ago
if (playlist.channels.length !== channels.length) {
log.print(`updated`)
3 years ago
playlist.channels = channels
3 years ago
playlist.updated = true
4 years ago
}
3 years ago
return playlist
4 years ago
}
main()