2022-02-06 23:22:20 +01:00
|
|
|
const api = require('../core/api')
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
module.exports = async function (streams = []) {
|
2022-02-07 03:21:22 +01:00
|
|
|
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
|
|
|
|
|
2022-02-06 23:22:20 +01:00
|
|
|
await api.languages.load()
|
|
|
|
let languages = await api.languages.all()
|
|
|
|
languages = _.uniqBy(languages, 'code')
|
2022-02-07 03:21:22 +01:00
|
|
|
|
|
|
|
const output = []
|
2022-02-06 23:22:20 +01:00
|
|
|
for (const language of languages) {
|
|
|
|
let items = _.filter(streams, { channel: { languages: [language.code] } })
|
|
|
|
if (items.length) {
|
2022-02-07 00:27:15 +01:00
|
|
|
output.push({ filepath: `languages/${language.code}.m3u`, items })
|
2022-02-06 23:22:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 23:11:47 +01:00
|
|
|
let items = _.filter(streams, stream => !stream.channel || !stream.channel.languages.length)
|
2022-02-07 00:27:15 +01:00
|
|
|
output.push({ filepath: 'languages/undefined.m3u', items })
|
2022-02-06 23:22:20 +01:00
|
|
|
|
|
|
|
return output
|
|
|
|
}
|