iptv/scripts/generators/index_language_m3u.js

33 lines
866 B
JavaScript
Raw Normal View History

2022-02-07 03:53:30 +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.languages.load()
let languages = await api.languages.all()
languages = _.keyBy(languages, 'code')
2022-02-07 03:53:30 +01:00
let items = []
streams.forEach(stream => {
2022-02-07 23:11:47 +01:00
if (!stream.channel || !stream.channel.languages.length) {
const item = _.cloneDeep(stream)
item.group_title = null
items.push(stream)
return
}
2022-02-07 03:53:30 +01:00
2022-02-07 23:11:47 +01:00
stream.channel.languages.forEach(code => {
2022-02-07 03:53:30 +01:00
const item = _.cloneDeep(stream)
2022-02-07 23:11:47 +01:00
item.group_title = languages[code] ? languages[code].name : null
2022-02-07 03:53:30 +01:00
items.push(item)
})
})
items = _.sortBy(items, i => {
2022-02-07 23:11:47 +01:00
if (!i.group_title) return ''
2022-02-07 03:53:30 +01:00
return i.group_title
})
return { filepath: 'index.language.m3u', items }
}