You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iptv/scripts/format.js

30 lines
738 B
JavaScript

4 years ago
const parser = require('./parser')
const utils = require('./utils')
3 years ago
const log = require('./log')
6 years ago
5 years ago
async function main() {
3 years ago
log.start()
4 years ago
3 years ago
log.print(`Parsing 'index.m3u'...`)
let playlists = parser.parseIndex().filter(i => i.url !== 'channels/unsorted.m3u')
4 years ago
for (const playlist of playlists) {
3 years ago
log.print(`\nProcessing '${playlist.url}'...`)
await parser.parsePlaylist(playlist.url).then(sortChannels).then(utils.savePlaylist)
5 years ago
}
3 years ago
log.finish()
}
async function sortChannels(playlist) {
3 years ago
const channels = [...playlist.channels]
utils.sortBy(channels, ['name', 'url'])
5 years ago
3 years ago
if (JSON.stringify(playlist.channels) !== JSON.stringify(channels)) log.print('updated')
5 years ago
3 years ago
playlist.channels = channels
3 years ago
return playlist
}
5 years ago
main()