iptv/scripts/format.js

30 lines
738 B
JavaScript
Raw Normal View History

2021-01-30 00:26:20 +01:00
const parser = require('./parser')
const utils = require('./utils')
2021-08-01 07:25:39 +02:00
const log = require('./log')
2019-07-20 09:06:29 +02:00
2019-11-03 14:03:35 +01:00
async function main() {
2021-08-01 07:25:39 +02:00
log.start()
2021-05-07 11:51:57 +02:00
2021-08-01 07:25:39 +02:00
log.print(`Parsing 'index.m3u'...`)
let playlists = parser.parseIndex().filter(i => i.url !== 'channels/unsorted.m3u')
2021-01-30 00:26:20 +01:00
for (const playlist of playlists) {
2021-08-01 07:25:39 +02:00
log.print(`\nProcessing '${playlist.url}'...`)
await parser.parsePlaylist(playlist.url).then(sortChannels).then(utils.savePlaylist)
2019-11-03 14:03:35 +01:00
}
2021-08-01 07:25:39 +02:00
log.finish()
}
async function sortChannels(playlist) {
2021-08-01 07:25:39 +02:00
const channels = [...playlist.channels]
utils.sortBy(channels, ['name', 'url'])
2019-11-03 17:01:04 +01:00
2021-08-01 07:25:39 +02:00
if (JSON.stringify(playlist.channels) !== JSON.stringify(channels)) log.print('updated')
2019-11-03 14:03:35 +01:00
2021-08-01 07:25:39 +02:00
playlist.channels = channels
2021-08-01 07:25:39 +02:00
return playlist
2020-04-22 15:41:54 +02:00
}
2019-11-03 08:56:54 +01:00
main()