iptv/scripts/commands/playlist/update.js

23 lines
654 B
JavaScript
Raw Normal View History

2022-02-11 19:07:16 +01:00
const { create: createPlaylist } = require('../../core/playlist')
const { db, logger, file } = require('../../core')
2022-02-07 23:13:35 +01:00
const { orderBy } = require('natural-orderby')
2022-02-11 19:07:16 +01:00
const _ = require('lodash')
2021-12-12 05:10:03 +01:00
async function main() {
2022-02-07 05:00:48 +01:00
await db.streams.load()
2022-02-12 02:05:31 +01:00
let streams = await db.streams.find({})
streams = orderBy(
streams,
['channel_name', i => i.status.level, i => i.resolution.height, 'url'],
['asc', 'asc', 'desc', 'asc']
)
2021-12-12 05:10:03 +01:00
2022-02-12 02:05:31 +01:00
const files = _.groupBy(streams, 'filepath')
2021-12-12 05:10:03 +01:00
for (const filepath in files) {
2022-02-12 02:05:31 +01:00
const playlist = createPlaylist(files[filepath], { public: false })
2022-02-07 05:00:48 +01:00
await file.create(filepath, playlist.toString())
2021-12-12 05:10:03 +01:00
}
}
main()