mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-13 10:30: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')
|
const _ = require('lodash')
|
||||||
|
|
||||||
module.exports = async function (streams = []) {
|
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()
|
await api.regions.load()
|
||||||
let regions = await api.regions.all()
|
let regions = await api.regions.all()
|
||||||
regions = _.keyBy(regions, 'code')
|
regions = _.keyBy(regions, 'code')
|
||||||
|
|
||||||
await api.countries.load()
|
await api.countries.load()
|
||||||
let countries = await api.countries.all()
|
let countries = await api.countries.all()
|
||||||
countries = _.keyBy(countries, 'code')
|
countries = _.keyBy(countries, 'code')
|
||||||
|
|
||||||
await api.subdivisions.load()
|
await api.subdivisions.load()
|
||||||
let subdivisions = await api.subdivisions.all()
|
let subdivisions = await api.subdivisions.all()
|
||||||
subdivisions = _.keyBy(subdivisions, 'code')
|
subdivisions = _.keyBy(subdivisions, 'code')
|
||||||
|
|
||||||
let items = []
|
let items = []
|
||||||
streams.forEach(stream => {
|
streams.forEach(stream => {
|
||||||
if (!stream.broadcast_area.length) {
|
if (!stream.broadcast_area.length) {
|
||||||
const item = _.cloneDeep(stream)
|
const item = _.cloneDeep(stream)
|
||||||
item.group_title = 'Undefined'
|
item.group_title = 'Undefined'
|
||||||
items.push(item)
|
items.push(item)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const broadcastCountries = getBroadcastCountries(stream, { countries, regions, subdivisions })
|
if (stream.broadcast_area.includes('r/INT')) {
|
||||||
broadcastCountries.forEach(country => {
|
const item = _.cloneDeep(stream)
|
||||||
const item = _.cloneDeep(stream)
|
item.group_title = 'International'
|
||||||
item.group_title = country.name
|
items.push(item)
|
||||||
items.push(item)
|
}
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
items = _.sortBy(items, item => {
|
const broadcastCountries = getBroadcastCountries(stream, { countries, regions, subdivisions })
|
||||||
if (item.group_title === 'Undefined') return ''
|
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 }) {
|
function getBroadcastCountries(stream, { countries, regions, subdivisions }) {
|
||||||
let codes = stream.broadcast_area.reduce((acc, item) => {
|
let codes = stream.broadcast_area.reduce((acc, item) => {
|
||||||
const [type, code] = item.split('/')
|
const [type, code] = item.split('/')
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'c':
|
case 'c':
|
||||||
acc.push(code)
|
acc.push(code)
|
||||||
break
|
break
|
||||||
case 'r':
|
case 'r':
|
||||||
if (regions[code]) {
|
if (code !== 'INT' && regions[code]) {
|
||||||
acc = acc.concat(regions[code].countries)
|
acc = acc.concat(regions[code].countries)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 's':
|
case 's':
|
||||||
if (subdivisions[code]) {
|
if (subdivisions[code]) {
|
||||||
acc.push(subdivisions[code].country)
|
acc.push(subdivisions[code].country)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return acc
|
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