iptv/scripts/generators/countries.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

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-07 23:11:47 +01:00
2022-02-06 23:22:20 +01:00
await api.countries.load()
const countries = await api.countries.all()
await api.regions.load()
const regions = await api.regions.all()
await api.subdivisions.load()
const subdivisions = await api.subdivisions.all()
2022-02-07 23:11:47 +01:00
const output = []
2022-02-06 23:22:20 +01:00
for (const country of countries) {
let countryRegionCodes = _.filter(regions, { countries: [country.code] }).map(
2022-02-07 23:11:47 +01:00
r => `r/${r.code}`
)
2022-09-12 06:18:17 +02:00
const countrySubdivisions = _.filter(subdivisions, { country: country.code })
const countryAreaCodes = countryRegionCodes.concat(countrySubdivisions.map(s => `s/${s.code}`))
2022-02-07 23:11:47 +01:00
countryAreaCodes.push(`c/${country.code}`)
2022-02-11 17:56:11 +01:00
let items = _.filter(streams, stream => {
return _.intersection(stream.broadcast_area, countryAreaCodes).length
})
2022-02-07 00:27:15 +01:00
output.push({ filepath: `countries/${country.code.toLowerCase()}.m3u`, items })
2022-09-12 06:18:17 +02:00
for (let subdivision of countrySubdivisions) {
let subdivisionItems = _.filter(streams, stream => {
return stream.broadcast_area.includes(`s/${subdivision.code}`)
})
if (subdivisionItems.length) {
output.push({
2022-09-12 06:51:28 +02:00
filepath: `subdivisions/${subdivision.code.toLowerCase()}.m3u`,
2022-09-12 06:18:17 +02:00
items: subdivisionItems
})
}
}
2022-02-06 23:22:20 +01:00
}
return output
}