iptv/scripts/filter.js

41 lines
996 B
JavaScript
Raw Normal View History

2021-08-01 06:55:18 +02:00
const blacklist = require('./blacklist.json')
2021-07-13 17:14:49 +02:00
const parser = require('./parser')
const utils = require('./utils')
2021-08-01 06:55:18 +02:00
const log = require('./log')
2021-07-13 17:14:49 +02:00
async function main() {
2021-08-01 06:55:18 +02:00
log.start()
log.print(`Parsing 'index.m3u'...`)
const playlists = parser.parseIndex()
2021-07-13 17:14:49 +02:00
for (const playlist of playlists) {
2021-08-01 06:55:18 +02:00
log.print(`\nProcessing '${playlist.url}'...`)
await parser.parsePlaylist(playlist.url).then(removeBlacklisted).then(utils.savePlaylist)
2021-07-13 17:14:49 +02:00
}
2021-08-01 06:55:18 +02:00
log.finish()
2021-07-13 17:14:49 +02:00
}
async function removeBlacklisted(playlist) {
2021-08-01 06:55:18 +02:00
const channels = playlist.channels.filter(channel => {
2021-07-13 18:10:31 +02:00
return !blacklist.find(i => {
const channelName = channel.name.toLowerCase()
return (
(i.name.toLowerCase() === channelName ||
i.aliases.map(i => i.toLowerCase()).includes(channelName)) &&
i.country === channel.filename
)
})
2021-07-13 17:14:49 +02:00
})
2021-08-01 06:55:18 +02:00
if (playlist.channels.length !== channels.length) {
log.print(`updated`)
2021-07-13 17:14:49 +02:00
}
2021-08-01 06:55:18 +02:00
playlist.channels = channels
2021-07-13 17:14:49 +02:00
2021-08-01 06:55:18 +02:00
return playlist
2021-07-13 17:14:49 +02:00
}
main()