2022-02-06 22:04:56 +01:00
|
|
|
const api = require('../core/api')
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
module.exports = async function (streams = []) {
|
|
|
|
await api.categories.load()
|
|
|
|
const categories = await api.categories.all()
|
2022-02-11 17:56:11 +01:00
|
|
|
|
|
|
|
const output = []
|
2022-02-06 22:04:56 +01:00
|
|
|
for (const category of categories) {
|
2022-02-11 17:56:11 +01:00
|
|
|
let items = _.filter(streams, { categories: [{ id: 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-11 17:56:11 +01:00
|
|
|
let items = _.filter(streams, stream => !stream.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
|
|
|
}
|