iptv/scripts/generators/categories.js

18 lines
549 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] } })
2022-02-07 00:27:15 +01:00
output.push({ filepath: `categories/${category.id}.m3u`, 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-07 00:27:15 +01:00
output.push({ filepath: 'categories/undefined.m3u', 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
}