iptv/scripts/generators/languages.js

24 lines
691 B
JavaScript
Raw Normal View History

2022-02-06 23:22:20 +01:00
const api = require('../core/api')
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-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) {
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
}