mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-11 17:40:03 -04:00
wip
This commit is contained in:
parent
3fd0006b31
commit
e49dc7a39a
4 changed files with 583 additions and 52 deletions
|
@ -5,3 +5,4 @@ exports.regions = require('./regions')
|
|||
exports.index_m3u = require('./index_m3u')
|
||||
exports.index_nsfw_m3u = require('./index_nsfw_m3u')
|
||||
exports.index_category_m3u = require('./index_category_m3u')
|
||||
exports.index_country_m3u = require('./index_country_m3u')
|
||||
|
|
55
scripts/generators/index_country_m3u.js
Normal file
55
scripts/generators/index_country_m3u.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
const api = require('../core/api')
|
||||
const _ = require('lodash')
|
||||
|
||||
module.exports = async function (streams = []) {
|
||||
await api.regions.load()
|
||||
let regions = await api.regions.all()
|
||||
regions = _.keyBy(regions, 'code')
|
||||
|
||||
await api.countries.load()
|
||||
let countries = await api.countries.all()
|
||||
countries = _.keyBy(countries, 'code')
|
||||
|
||||
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
|
||||
let items = []
|
||||
streams.forEach(stream => {
|
||||
if (!stream.channel) return items.push(stream)
|
||||
|
||||
getBroadcastCountries(stream.channel, { countries, regions }).forEach(country => {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = country.name
|
||||
items.push(item)
|
||||
})
|
||||
})
|
||||
items = _.sortBy(items, i => {
|
||||
if (i.group_title === 'Undefined') return '_'
|
||||
return i.group_title
|
||||
})
|
||||
|
||||
return { filepath: 'index.country.m3u', items }
|
||||
}
|
||||
|
||||
function getBroadcastCountries(channel, { countries, regions }) {
|
||||
let codes = channel.broadcast_area.reduce((acc, item) => {
|
||||
const [type, code] = item.split('/')
|
||||
switch (type) {
|
||||
case 'c':
|
||||
acc.push(code)
|
||||
break
|
||||
case 'r':
|
||||
if (regions[code]) {
|
||||
acc = acc.concat(regions[code].countries)
|
||||
}
|
||||
break
|
||||
case 's':
|
||||
const [c] = item.split('-')
|
||||
acc.push(c)
|
||||
break
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
|
||||
codes = _.uniq(codes)
|
||||
|
||||
return codes.map(code => countries[code]).filter(c => c)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue