Update generate-playlists.js

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

View file

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