iptv/scripts/generators/categories.js

18 lines
502 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
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)
2022-02-06 23:22:20 +01:00
output.push({ id: 'undefined', 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
}