iptv/scripts/commands/playlist/update.js
Aleksandr Statciuk e7ae344702 Update update.js
2022-09-11 19:50:43 +03:00

31 lines
837 B
JavaScript

const { create: createPlaylist } = require('../../core/playlist')
const { db, logger, file } = require('../../core')
const { orderBy } = require('natural-orderby')
const _ = require('lodash')
async function main() {
await db.streams.load()
let streams = await db.streams.find({})
const levels = { online: 1, blocked: 2, timeout: 3, error: 4, default: 5 }
streams = orderBy(
streams,
[
'channel',
s => (s.channel ? '' : s.title),
s => levels[s.status] || levels['default'],
'height',
'frame_rate',
'url'
],
['asc', 'asc', 'asc', 'desc', 'desc', 'asc']
)
const files = _.groupBy(streams, 'filepath')
for (const filepath in files) {
const playlist = createPlaylist(files[filepath], { public: false })
await file.create(filepath, playlist.toString())
}
}
main()