You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iptv/scripts/generators/index_category_m3u.js

36 lines
880 B
JavaScript

3 years ago
const api = require('../core/api')
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')
3 years ago
let items = []
streams.forEach(stream => {
if (!stream.channel || !stream.channel.categories.length) {
const item = _.cloneDeep(stream)
item.group_title = null
items.push(item)
3 years ago
return
}
stream.channel.categories.forEach(id => {
3 years ago
const item = _.cloneDeep(stream)
item.group_title = categories[id] ? categories[id].name : null
3 years ago
items.push(item)
})
})
items = _.sortBy(items, item => {
if (!item.group_title) return ''
return item.group_title
3 years ago
})
return { filepath: 'index.category.m3u', items }
}