mirror of https://github.com/iptv-org/iptv
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
717 B
JavaScript
22 lines
717 B
JavaScript
3 years ago
|
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()
|
||
|
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)
|
||
|
output.push({ id: country.code.toLowerCase(), items })
|
||
|
}
|
||
|
|
||
|
let items = _.filter(streams, s => !s.broadcast_area.length)
|
||
|
output.push({ id: 'undefined', items })
|
||
|
|
||
|
return output
|
||
|
}
|