iptv/scripts/format.js

35 lines
807 B
JavaScript
Raw Normal View History

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