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.1 KiB
JavaScript

3 years ago
const blacklist = require('./helpers/blacklist.json')
const parser = require('./helpers/parser')
const log = require('./helpers/log')
3 years ago
async function main() {
3 years ago
log.start()
log.print(`Parsing 'index.m3u'...`)
const playlists = parser.parseIndex()
3 years ago
for (const playlist of playlists) {
3 years ago
log.print(`\nProcessing '${playlist.url}'...`)
3 years ago
await parser
.parsePlaylist(playlist.url)
.then(removeBlacklisted)
.then(p => p.save())
3 years ago
}
3 years ago
log.print('\n')
3 years ago
log.finish()
3 years ago
}
async function removeBlacklisted(playlist) {
3 years ago
const channels = playlist.channels.filter(channel => {
3 years ago
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
3 years ago
})
3 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
3 years ago
}
3 years ago
return playlist
3 years ago
}
main()