iptv/scripts/sort.js

42 lines
968 B
JavaScript
Raw Normal View History

2021-08-02 20:34:54 +02:00
const parser = require('./helpers/parser')
const utils = require('./helpers/utils')
2021-09-08 20:04:38 +02:00
const file = require('./helpers/file')
2021-08-02 20:34:54 +02:00
const log = require('./helpers/log')
async function main() {
log.start()
2021-09-08 20:04:38 +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-02 20:34:54 +02:00
await parser
2021-09-08 20:04:38 +02:00
.parsePlaylist(file)
2021-08-02 20:34:54 +02:00
.then(sortChannels)
.then(p => p.save())
}
log.print('\n')
log.finish()
}
async function sortChannels(playlist) {
2021-09-20 16:14:45 +02:00
let channels = [...playlist.channels]
channels = utils.sortBy(
channels,
['name', 'status', 'resolution.height', 'url'],
['asc', 'asc', 'desc', 'asc']
)
2021-08-02 20:34:54 +02:00
if (JSON.stringify(channels) !== JSON.stringify(playlist.channels)) {
log.print('updated')
playlist.channels = channels
playlist.updated = true
}
return playlist
}
main()