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

43 lines
1.0 KiB
JavaScript

3 years ago
const blacklist = require('./helpers/blacklist.json')
const parser = require('./helpers/parser')
const log = require('./helpers/log')
4 years ago
async function main() {
3 years ago
log.start()
log.print(`Parsing 'index.m3u'...`)
const playlists = parser.parseIndex()
4 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())
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()