Update generate-playlists.js

This commit is contained in:
Aleksandr Statciuk
2022-02-08 01:11:47 +03:00
parent 5844ed0cd1
commit 02a5c9bfa2
32 changed files with 187 additions and 117 deletions

View File

@@ -3,19 +3,32 @@ const _ = require('lodash')
module.exports = async function (streams = []) {
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
await api.categories.load()
let categories = await api.categories.all()
categories = _.keyBy(categories, 'id')
let items = []
streams.forEach(stream => {
if (!stream.categories.length) return items.push(stream)
stream.categories.forEach(category => {
if (!stream.channel || !stream.channel.categories.length) {
const item = _.cloneDeep(stream)
item.group_title = category.name
item.group_title = null
items.push(item)
return
}
stream.channel.categories.forEach(id => {
const item = _.cloneDeep(stream)
item.group_title = categories[id] ? categories[id].name : null
items.push(item)
})
})
items = _.sortBy(items, i => {
if (i.group_title === 'Undefined') return '_'
return i.group_title
items = _.sortBy(items, item => {
if (!item.group_title) return ''
return item.group_title
})
return { filepath: 'index.category.m3u', items }