iptv/scripts/commands/update-playlists.js

28 lines
736 B
JavaScript
Raw Normal View History

2021-12-12 05:10:03 +01:00
const _ = require('lodash')
2022-02-07 05:00:48 +01:00
const { create: createPlaylist } = require('../core/playlist')
const { db, logger, file } = require('../core')
2021-12-12 05:10:03 +01:00
async function main() {
2022-02-07 05:00:48 +01:00
await db.streams.load()
let items = await db.streams
2021-12-12 05:10:03 +01:00
.find({})
.sort({ name: 1, 'status.level': 1, 'resolution.height': -1, url: 1 })
const files = _.groupBy(items, 'filepath')
for (const filepath in files) {
2022-02-07 07:25:14 +01:00
let items = files[filepath]
items = items.sort(naturalOrder)
2022-02-07 05:00:48 +01:00
const playlist = createPlaylist(items, { public: false })
await file.create(filepath, playlist.toString())
2021-12-12 05:10:03 +01:00
}
}
main()
2022-02-07 07:25:14 +01:00
function naturalOrder(a, b) {
return a.channel_name.localeCompare(b.channel_name, undefined, {
numeric: true,
sensitivity: 'base'
})
}