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-06 23:22:20 +01:00
|
|
|
await api.regions.load()
|
|
|
|
const regions = await api.regions.all()
|
2022-02-11 17:56:11 +01:00
|
|
|
|
2022-03-14 22:43:06 +01:00
|
|
|
await api.subdivisions.load()
|
|
|
|
const subdivisions = await api.subdivisions.all()
|
|
|
|
|
2022-02-11 17:56:11 +01:00
|
|
|
const output = []
|
2022-02-06 23:22:20 +01:00
|
|
|
for (const region of regions) {
|
2022-03-14 22:43:06 +01:00
|
|
|
const regionCountries = region.countries
|
|
|
|
let areaCodes = regionCountries.map(code => `c/${code}`)
|
|
|
|
|
|
|
|
const regionSubdivisions = _.filter(
|
|
|
|
subdivisions,
|
|
|
|
s => regionCountries.indexOf(s.country) > -1
|
|
|
|
).map(s => `s/${s.code}`)
|
|
|
|
areaCodes = areaCodes.concat(regionSubdivisions)
|
|
|
|
|
2022-02-07 23:11:47 +01:00
|
|
|
areaCodes.push(`r/${region.code}`)
|
2022-02-11 17:56:11 +01:00
|
|
|
|
|
|
|
let items = _.filter(streams, stream => _.intersection(stream.broadcast_area, areaCodes).length)
|
2022-02-07 00:27:15 +01:00
|
|
|
output.push({ filepath: `regions/${region.code.toLowerCase()}.m3u`, items })
|
2022-02-06 23:22:20 +01:00
|
|
|
}
|
|
|
|
|
2022-02-11 17:56:11 +01:00
|
|
|
let items = _.filter(streams, stream => !stream.broadcast_area.length)
|
2022-02-07 00:27:15 +01:00
|
|
|
output.push({ filepath: 'regions/undefined.m3u', items })
|
2022-02-06 23:22:20 +01:00
|
|
|
|
|
|
|
return output
|
|
|
|
}
|