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.
iptv/scripts/generators/countries.js

31 lines
994 B
JavaScript

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