iptv/scripts/generators/languages.js

25 lines
688 B
JavaScript
Raw Normal View History

2022-02-07 01:22:20 +03:00
const _ = require('lodash')
module.exports = async function (streams = []) {
2022-02-11 19:56:11 +03:00
streams = _.filter(streams, stream => stream.is_nsfw === false)
2022-02-07 05:21:22 +03:00
2022-02-12 07:01:12 +03:00
let languages = []
streams.forEach(stream => {
languages = languages.concat(stream.languages)
})
2022-02-07 01:22:20 +03:00
languages = _.uniqBy(languages, 'code')
2022-02-07 05:21:22 +03:00
const output = []
2022-02-07 01:22:20 +03:00
for (const language of languages) {
2022-02-11 19:56:11 +03:00
let items = _.filter(streams, { languages: [{ code: language.code }] })
2022-02-07 01:22:20 +03:00
if (items.length) {
2022-02-07 02:27:15 +03:00
output.push({ filepath: `languages/${language.code}.m3u`, items })
2022-02-07 01:22:20 +03:00
}
}
2022-02-11 19:56:11 +03:00
let items = _.filter(streams, stream => !stream.languages.length)
2022-02-07 02:27:15 +03:00
output.push({ filepath: 'languages/undefined.m3u', items })
2022-02-07 01:22:20 +03:00
return output
}