mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-11 17:40:03 -04:00
Update index_country_m3u.js
This commit is contained in:
parent
1a6df4ef83
commit
9746f31eaa
1 changed files with 62 additions and 51 deletions
|
@ -2,68 +2,79 @@ const api = require('../core/api')
|
|||
const _ = require('lodash')
|
||||
|
||||
module.exports = async function (streams = []) {
|
||||
streams = _.filter(streams, stream => stream.is_nsfw === false)
|
||||
streams = _.filter(streams, stream => stream.is_nsfw === false)
|
||||
|
||||
await api.regions.load()
|
||||
let regions = await api.regions.all()
|
||||
regions = _.keyBy(regions, 'code')
|
||||
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')
|
||||
await api.countries.load()
|
||||
let countries = await api.countries.all()
|
||||
countries = _.keyBy(countries, 'code')
|
||||
|
||||
await api.subdivisions.load()
|
||||
let subdivisions = await api.subdivisions.all()
|
||||
subdivisions = _.keyBy(subdivisions, 'code')
|
||||
await api.subdivisions.load()
|
||||
let subdivisions = await api.subdivisions.all()
|
||||
subdivisions = _.keyBy(subdivisions, 'code')
|
||||
|
||||
let items = []
|
||||
streams.forEach(stream => {
|
||||
if (!stream.broadcast_area.length) {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = 'Undefined'
|
||||
items.push(item)
|
||||
return
|
||||
}
|
||||
let items = []
|
||||
streams.forEach(stream => {
|
||||
if (!stream.broadcast_area.length) {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = 'Undefined'
|
||||
items.push(item)
|
||||
return
|
||||
}
|
||||
|
||||
const broadcastCountries = getBroadcastCountries(stream, { countries, regions, subdivisions })
|
||||
broadcastCountries.forEach(country => {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = country.name
|
||||
items.push(item)
|
||||
})
|
||||
})
|
||||
if (stream.broadcast_area.includes('r/INT')) {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = 'International'
|
||||
items.push(item)
|
||||
}
|
||||
|
||||
items = _.sortBy(items, item => {
|
||||
if (item.group_title === 'Undefined') return ''
|
||||
const broadcastCountries = getBroadcastCountries(stream, { countries, regions, subdivisions })
|
||||
broadcastCountries.forEach(country => {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = country.name
|
||||
items.push(item)
|
||||
})
|
||||
})
|
||||
|
||||
return item.group_title
|
||||
})
|
||||
items = sortByGroupTitle(items)
|
||||
|
||||
return { filepath: 'index.country.m3u', items }
|
||||
return { filepath: 'index.country.m3u', items }
|
||||
}
|
||||
|
||||
function getBroadcastCountries(stream, { countries, regions, subdivisions }) {
|
||||
let codes = stream.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':
|
||||
if (subdivisions[code]) {
|
||||
acc.push(subdivisions[code].country)
|
||||
}
|
||||
break
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
let codes = stream.broadcast_area.reduce((acc, item) => {
|
||||
const [type, code] = item.split('/')
|
||||
switch (type) {
|
||||
case 'c':
|
||||
acc.push(code)
|
||||
break
|
||||
case 'r':
|
||||
if (code !== 'INT' && regions[code]) {
|
||||
acc = acc.concat(regions[code].countries)
|
||||
}
|
||||
break
|
||||
case 's':
|
||||
if (subdivisions[code]) {
|
||||
acc.push(subdivisions[code].country)
|
||||
}
|
||||
break
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
|
||||
codes = _.uniq(codes)
|
||||
codes = _.uniq(codes)
|
||||
|
||||
return codes.map(code => countries[code]).filter(c => c)
|
||||
return codes.map(code => countries[code]).filter(c => c)
|
||||
}
|
||||
|
||||
function sortByGroupTitle(items) {
|
||||
return _.sortBy(items, item => {
|
||||
if (item.group_title === 'International') return '[' // ASCII character 91
|
||||
if (item.group_title === 'Undefined') return ']' // ASCII character 93
|
||||
|
||||
return item.group_title
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue