mirror of
https://github.com/iptv-org/iptv.git
synced 2024-09-05 00:01:35 +02:00
35 lines
807 B
JavaScript
35 lines
807 B
JavaScript
const parser = require('./helpers/parser')
|
|
const utils = require('./helpers/utils')
|
|
const log = require('./helpers/log')
|
|
|
|
async function main() {
|
|
log.start()
|
|
|
|
log.print(`Parsing 'index.m3u'...`)
|
|
let playlists = parser.parseIndex().filter(i => i.url !== 'channels/unsorted.m3u')
|
|
for (const playlist of playlists) {
|
|
log.print(`\nProcessing '${playlist.url}'...`)
|
|
await parser
|
|
.parsePlaylist(playlist.url)
|
|
.then(sortChannels)
|
|
.then(p => p.save())
|
|
}
|
|
|
|
log.print('\n')
|
|
log.finish()
|
|
}
|
|
|
|
async function sortChannels(playlist) {
|
|
const channels = [...playlist.channels]
|
|
utils.sortBy(channels, ['name', 'url'])
|
|
|
|
if (JSON.stringify(playlist.channels) !== JSON.stringify(channels)) {
|
|
log.print('updated')
|
|
playlist.channels = channels
|
|
}
|
|
|
|
return playlist
|
|
}
|
|
|
|
main()
|