2021-08-16 19:51:05 +02:00
|
|
|
const parser = require('./helpers/parser')
|
2021-09-08 19:52:57 +02:00
|
|
|
const file = require('./helpers/file')
|
2021-08-16 19:51:05 +02:00
|
|
|
const log = require('./helpers/log')
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
log.start()
|
|
|
|
|
2021-09-08 19:52:57 +02:00
|
|
|
let files = await file.list()
|
|
|
|
if (!files.length) log.print(`No files is selected\n`)
|
|
|
|
files = files.filter(file => file !== 'channels/unsorted.m3u')
|
|
|
|
for (const file of files) {
|
|
|
|
log.print(`\nProcessing '${file}'...`)
|
2021-08-16 19:51:05 +02:00
|
|
|
await parser
|
2021-09-08 19:52:57 +02:00
|
|
|
.parsePlaylist(file)
|
2021-08-16 19:51:05 +02:00
|
|
|
.then(removeBrokenLinks)
|
|
|
|
.then(p => p.save())
|
|
|
|
}
|
|
|
|
|
|
|
|
log.print('\n')
|
|
|
|
log.finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
async function removeBrokenLinks(playlist) {
|
|
|
|
const buffer = []
|
|
|
|
const channels = playlist.channels.filter(channel => {
|
|
|
|
const sameHash = buffer.find(item => item.hash === channel.hash)
|
|
|
|
if (sameHash && channel.status === 'Offline') return false
|
|
|
|
|
|
|
|
buffer.push(channel)
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
if (playlist.channels.length !== channels.length) {
|
|
|
|
log.print('updated')
|
|
|
|
playlist.channels = channels
|
|
|
|
playlist.updated = true
|
|
|
|
}
|
|
|
|
|
|
|
|
return playlist
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|