iptv/scripts/generators/index_category_m3u.js

33 lines
705 B
JavaScript
Raw Normal View History

2022-02-07 01:52:47 +01:00
const _ = require('lodash')
module.exports = async function (streams = []) {
2022-02-11 17:56:11 +01:00
streams = _.filter(streams, stream => stream.is_nsfw === false)
2022-02-07 23:11:47 +01:00
2022-02-07 01:52:47 +01:00
let items = []
streams.forEach(stream => {
2022-02-11 17:56:11 +01:00
if (!stream.categories.length) {
2022-02-07 23:11:47 +01:00
const item = _.cloneDeep(stream)
2022-02-11 17:56:11 +01:00
item.group_title = 'Undefined'
2022-02-07 23:11:47 +01:00
items.push(item)
2022-02-07 01:52:47 +01:00
2022-02-07 23:11:47 +01:00
return
}
2022-02-12 01:12:00 +01:00
stream.categories
.filter(c => c)
.forEach(category => {
const item = _.cloneDeep(stream)
item.group_title = category.name
items.push(item)
})
2022-02-07 01:52:47 +01:00
})
2022-02-07 23:11:47 +01:00
items = _.sortBy(items, item => {
2022-02-11 17:56:11 +01:00
if (item.group_title === 'Undefined') return ''
2022-02-07 23:11:47 +01:00
return item.group_title
2022-02-07 01:52:47 +01:00
})
return { filepath: 'index.category.m3u', items }
}