iptv/scripts/generators/index_category_m3u.js

36 lines
880 B
JavaScript
Raw Normal View History

2022-02-07 01:52:47 +01:00
const api = require('../core/api')
const _ = require('lodash')
module.exports = async function (streams = []) {
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
2022-02-07 23:11:47 +01:00
await api.categories.load()
let categories = await api.categories.all()
categories = _.keyBy(categories, 'id')
2022-02-07 01:52:47 +01:00
let items = []
streams.forEach(stream => {
2022-02-07 23:11:47 +01:00
if (!stream.channel || !stream.channel.categories.length) {
const item = _.cloneDeep(stream)
item.group_title = null
items.push(item)
2022-02-07 01:52:47 +01:00
2022-02-07 23:11:47 +01:00
return
}
stream.channel.categories.forEach(id => {
2022-02-07 01:52:47 +01:00
const item = _.cloneDeep(stream)
2022-02-07 23:11:47 +01:00
item.group_title = categories[id] ? categories[id].name : null
2022-02-07 01:52:47 +01:00
items.push(item)
})
})
2022-02-07 23:11:47 +01:00
items = _.sortBy(items, item => {
if (!item.group_title) return ''
return item.group_title
2022-02-07 01:52:47 +01:00
})
return { filepath: 'index.category.m3u', items }
}