iptv/scripts/commands/playlist/update.js

24 lines
731 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,
['title', s => levels[s.status] || levels['default'], '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()