2022-02-06 23:22:20 +01:00
|
|
|
const api = require('../core/api')
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
module.exports = async function (streams = []) {
|
|
|
|
const output = []
|
|
|
|
await api.countries.load()
|
|
|
|
const countries = await api.countries.all()
|
|
|
|
await api.regions.load()
|
|
|
|
const regions = await api.regions.all()
|
2022-02-07 01:05:43 +01:00
|
|
|
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
|
2022-02-06 23:22:20 +01:00
|
|
|
for (const country of countries) {
|
|
|
|
const areaCodes = _.filter(regions, { countries: [country.code] }).map(r => r.code)
|
|
|
|
areaCodes.push(country.code)
|
|
|
|
let items = _.filter(streams, s => _.intersection(areaCodes, s.broadcast_area).length)
|
2022-02-07 00:27:15 +01:00
|
|
|
output.push({ filepath: `countries/${country.code.toLowerCase()}.m3u`, items })
|
2022-02-06 23:22:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let items = _.filter(streams, s => !s.broadcast_area.length)
|
2022-02-07 00:27:15 +01:00
|
|
|
output.push({ filepath: 'countries/undefined.m3u', items })
|
2022-02-06 23:22:20 +01:00
|
|
|
|
|
|
|
return output
|
|
|
|
}
|