iptv/scripts/generators/regions.js

21 lines
707 B
JavaScript

const api = require('../core/api')
const _ = require('lodash')
module.exports = async function (streams = []) {
const output = []
await api.regions.load()
const regions = await api.regions.all()
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
for (const region of regions) {
const areaCodes = region.countries
areaCodes.push(region.code)
let items = _.filter(streams, s => _.intersection(areaCodes, s.broadcast_area).length)
output.push({ filepath: `regions/${region.code.toLowerCase()}.m3u`, items })
}
let items = _.filter(streams, s => !s.broadcast_area.length)
output.push({ filepath: 'regions/undefined.m3u', items })
return output
}