2022-02-06 23:22:20 +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 03:21:22 +01:00
|
|
|
|
2022-02-12 05:01:12 +01:00
|
|
|
let languages = []
|
|
|
|
streams.forEach(stream => {
|
|
|
|
languages = languages.concat(stream.languages)
|
|
|
|
})
|
2022-02-06 23:22:20 +01:00
|
|
|
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) {
|
2022-02-11 17:56:11 +01:00
|
|
|
let items = _.filter(streams, { languages: [{ code: language.code }] })
|
2022-02-06 23:22:20 +01:00
|
|
|
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-11 17:56:11 +01:00
|
|
|
let items = _.filter(streams, stream => !stream.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
|
|
|
|
}
|