iptv/scripts/generators/categories.js

28 lines
766 B
JavaScript
Raw Normal View History

2022-02-06 22:04:56 +01:00
const api = require('../core/api')
const _ = require('lodash')
module.exports = async function (streams = []) {
2022-02-06 22:19:09 +01:00
streams = _.orderBy(
streams,
['channel.name', 'status.level', 'resolution.height'],
['asc', 'asc', 'desc']
)
streams = _.uniqBy(streams, s => s.channel_id || _.uniqueId())
const output = []
2022-02-06 22:04:56 +01:00
await api.categories.load()
const categories = await api.categories.all()
for (const category of categories) {
2022-02-06 22:19:09 +01:00
let items = _.filter(streams, { channel: { categories: [category.id] } })
output.push({ id: category.id, items })
2022-02-06 22:04:56 +01:00
}
2022-02-06 22:19:09 +01:00
let items = _.filter(streams, s => !s.categories.length)
items = items.map(item => {
2022-02-06 22:04:56 +01:00
item.group_title = 'Other'
return item
})
2022-02-06 22:19:09 +01:00
output.push({ id: 'other', items })
2022-02-06 22:04:56 +01:00
2022-02-06 22:19:09 +01:00
return output
2022-02-06 22:04:56 +01:00
}