Update regions.js

This commit is contained in:
Aleksandr Statciuk 2022-03-15 00:43:06 +03:00
parent c35b3f6aa1
commit faaac2e627
1 changed files with 12 additions and 1 deletions

View File

@ -7,9 +7,20 @@ module.exports = async function (streams = []) {
await api.regions.load() await api.regions.load()
const regions = await api.regions.all() const regions = await api.regions.all()
await api.subdivisions.load()
const subdivisions = await api.subdivisions.all()
const output = [] const output = []
for (const region of regions) { for (const region of regions) {
const areaCodes = region.countries.map(code => `c/${code}`) 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)
areaCodes.push(`r/${region.code}`) areaCodes.push(`r/${region.code}`)
let items = _.filter(streams, stream => _.intersection(stream.broadcast_area, areaCodes).length) let items = _.filter(streams, stream => _.intersection(stream.broadcast_area, areaCodes).length)