iptv/scripts/commands/playlist/update.js

31 lines
837 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({})
2022-02-24 20:18:10 +01:00
const levels = { online: 1, blocked: 2, timeout: 3, error: 4, default: 5 }
streams = orderBy(
streams,
2022-09-10 15:45:37 +02:00
[
'channel',
2022-09-11 10:07:51 +02:00
s => (s.channel ? '' : s.title),
2022-09-11 18:50:43 +02:00
s => levels[s.status] || levels['default'],
2022-09-10 15:45:37 +02:00
'height',
'frame_rate',
'url'
],
2022-09-09 19:19:49 +02:00
['asc', 'asc', 'asc', 'desc', 'desc', 'asc']
2022-02-24 20:18:10 +01:00
)
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()