2021-08-30 19:26:04 +02:00
|
|
|
const blacklist = require('./data/blacklist.json')
|
2021-08-01 18:50:33 +02:00
|
|
|
const parser = require('./helpers/parser')
|
2021-09-08 19:49:27 +02:00
|
|
|
const file = require('./helpers/file')
|
2021-08-01 18:50:33 +02:00
|
|
|
const log = require('./helpers/log')
|
2021-07-13 17:14:49 +02:00
|
|
|
|
|
|
|
async function main() {
|
2021-08-01 06:55:18 +02:00
|
|
|
log.start()
|
|
|
|
|
2021-09-08 19:49:27 +02:00
|
|
|
const files = await file.list()
|
|
|
|
if (!files.length) log.print(`No files is selected\n`)
|
|
|
|
for (const file of files) {
|
|
|
|
log.print(`\nProcessing '${file}'...`)
|
2021-08-02 20:18:59 +02:00
|
|
|
await parser
|
2021-09-08 19:49:27 +02:00
|
|
|
.parsePlaylist(file)
|
2021-08-02 20:18:59 +02:00
|
|
|
.then(removeBlacklisted)
|
|
|
|
.then(p => p.save())
|
2021-07-13 17:14:49 +02:00
|
|
|
}
|
|
|
|
|
2021-08-01 18:50:33 +02:00
|
|
|
log.print('\n')
|
2021-08-01 06:55:18 +02:00
|
|
|
log.finish()
|
2021-07-13 17:14:49 +02:00
|
|
|
}
|
|
|
|
|
2021-08-22 15:02:18 +02:00
|
|
|
function removeBlacklisted(playlist) {
|
2021-08-01 06:55:18 +02:00
|
|
|
const channels = playlist.channels.filter(channel => {
|
2021-08-02 20:18:59 +02:00
|
|
|
return !blacklist.find(item => {
|
2021-08-22 16:50:24 +02:00
|
|
|
const regexp = new RegExp(item.regex, 'i')
|
|
|
|
const hasSameName = regexp.test(channel.name)
|
2021-08-22 15:02:18 +02:00
|
|
|
const fromSameCountry = playlist.country.code === item.country
|
2021-08-02 20:18:59 +02:00
|
|
|
|
|
|
|
return hasSameName && fromSameCountry
|
2021-07-13 18:10:31 +02:00
|
|
|
})
|
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-08-01 19:46:26 +02:00
|
|
|
playlist.channels = channels
|
2021-08-02 20:18:59 +02:00
|
|
|
playlist.updated = true
|
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()
|