mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-11 17:40:03 -04:00
Update generate-playlists.js
This commit is contained in:
parent
96403d463e
commit
62ce78bbdf
32 changed files with 187 additions and 117 deletions
|
@ -10,7 +10,7 @@ module.exports = async function (streams = []) {
|
|||
output.push({ filepath: `categories/${category.id}.m3u`, items })
|
||||
}
|
||||
|
||||
let items = _.filter(streams, s => !s.categories.length)
|
||||
let items = _.filter(streams, stream => !stream.channel || !stream.channel.categories.length)
|
||||
output.push({ filepath: 'categories/undefined.m3u', items })
|
||||
|
||||
return output
|
||||
|
|
|
@ -2,20 +2,28 @@ const api = require('../core/api')
|
|||
const _ = require('lodash')
|
||||
|
||||
module.exports = async function (streams = []) {
|
||||
const output = []
|
||||
streams = _.filter(streams, stream => !stream.channel || stream.channel.is_nsfw === false)
|
||||
|
||||
await api.countries.load()
|
||||
const countries = await api.countries.all()
|
||||
await api.regions.load()
|
||||
const regions = await api.regions.all()
|
||||
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
|
||||
|
||||
const output = []
|
||||
for (const country of countries) {
|
||||
const areaCodes = _.filter(regions, { countries: [country.code] }).map(r => r.code)
|
||||
areaCodes.push(country.code)
|
||||
let items = _.filter(streams, s => _.intersection(areaCodes, s.broadcast_area).length)
|
||||
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
|
||||
)
|
||||
output.push({ filepath: `countries/${country.code.toLowerCase()}.m3u`, items })
|
||||
}
|
||||
|
||||
let items = _.filter(streams, s => !s.broadcast_area.length)
|
||||
let items = _.filter(streams, stream => !stream.channel || !stream.channel.broadcast_area.length)
|
||||
output.push({ filepath: 'countries/undefined.m3u', items })
|
||||
|
||||
return output
|
||||
|
|
|
@ -3,19 +3,32 @@ const _ = require('lodash')
|
|||
|
||||
module.exports = async function (streams = []) {
|
||||
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
|
||||
|
||||
await api.categories.load()
|
||||
let categories = await api.categories.all()
|
||||
categories = _.keyBy(categories, 'id')
|
||||
|
||||
let items = []
|
||||
streams.forEach(stream => {
|
||||
if (!stream.categories.length) return items.push(stream)
|
||||
|
||||
stream.categories.forEach(category => {
|
||||
if (!stream.channel || !stream.channel.categories.length) {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = category.name
|
||||
item.group_title = null
|
||||
items.push(item)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
stream.channel.categories.forEach(id => {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = categories[id] ? categories[id].name : null
|
||||
items.push(item)
|
||||
})
|
||||
})
|
||||
items = _.sortBy(items, i => {
|
||||
if (i.group_title === 'Undefined') return '_'
|
||||
return i.group_title
|
||||
|
||||
items = _.sortBy(items, item => {
|
||||
if (!item.group_title) return ''
|
||||
|
||||
return item.group_title
|
||||
})
|
||||
|
||||
return { filepath: 'index.category.m3u', items }
|
||||
|
|
|
@ -2,6 +2,8 @@ const api = require('../core/api')
|
|||
const _ = require('lodash')
|
||||
|
||||
module.exports = async function (streams = []) {
|
||||
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
|
||||
|
||||
await api.regions.load()
|
||||
let regions = await api.regions.all()
|
||||
regions = _.keyBy(regions, 'code')
|
||||
|
@ -10,10 +12,14 @@ module.exports = async function (streams = []) {
|
|||
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)
|
||||
if (!stream.channel || !stream.channel.broadcast_area.length) {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = null
|
||||
items.push(item)
|
||||
return
|
||||
}
|
||||
|
||||
getBroadcastCountries(stream.channel, { countries, regions }).forEach(country => {
|
||||
const item = _.cloneDeep(stream)
|
||||
|
@ -21,9 +27,10 @@ module.exports = async function (streams = []) {
|
|||
items.push(item)
|
||||
})
|
||||
})
|
||||
items = _.sortBy(items, i => {
|
||||
if (i.group_title === 'Undefined') return '_'
|
||||
return i.group_title
|
||||
|
||||
items = _.sortBy(items, item => {
|
||||
if (!item.group_title) return false
|
||||
return item.group_title
|
||||
})
|
||||
|
||||
return { filepath: 'index.country.m3u', items }
|
||||
|
|
|
@ -3,18 +3,28 @@ const _ = require('lodash')
|
|||
|
||||
module.exports = async function (streams = []) {
|
||||
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
|
||||
|
||||
await api.languages.load()
|
||||
let languages = await api.languages.all()
|
||||
languages = _.keyBy(languages, 'code')
|
||||
|
||||
let items = []
|
||||
streams.forEach(stream => {
|
||||
if (!stream.languages.length) return items.push(stream)
|
||||
|
||||
stream.languages.forEach(language => {
|
||||
if (!stream.channel || !stream.channel.languages.length) {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = language.name
|
||||
item.group_title = null
|
||||
items.push(stream)
|
||||
return
|
||||
}
|
||||
|
||||
stream.channel.languages.forEach(code => {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = languages[code] ? languages[code].name : null
|
||||
items.push(item)
|
||||
})
|
||||
})
|
||||
items = _.sortBy(items, i => {
|
||||
if (i.group_title === 'Undefined') return '_'
|
||||
if (!i.group_title) return ''
|
||||
return i.group_title
|
||||
})
|
||||
|
||||
|
|
|
@ -2,21 +2,55 @@ const api = require('../core/api')
|
|||
const _ = require('lodash')
|
||||
|
||||
module.exports = async function (streams = []) {
|
||||
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
|
||||
streams = _.filter(streams, stream => !stream.channel || stream.channel.is_nsfw === false)
|
||||
|
||||
await api.regions.load()
|
||||
let regions = await api.regions.all()
|
||||
regions = _.keyBy(regions, 'code')
|
||||
|
||||
let items = []
|
||||
streams.forEach(stream => {
|
||||
if (!stream.regions.length) return items.push(stream)
|
||||
if (!stream.channel || !stream.channel.broadcast_area.length) {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = null
|
||||
items.push(item)
|
||||
return
|
||||
}
|
||||
|
||||
stream.regions.forEach(region => {
|
||||
getChannelRegions(stream.channel, { regions }).forEach(region => {
|
||||
const item = _.cloneDeep(stream)
|
||||
item.group_title = region.name
|
||||
items.push(item)
|
||||
})
|
||||
})
|
||||
|
||||
items = _.sortBy(items, i => {
|
||||
if (i.group_title === 'Undefined') return '_'
|
||||
if (!i.group_title) return ''
|
||||
return i.group_title
|
||||
})
|
||||
|
||||
return { filepath: 'index.region.m3u', items }
|
||||
}
|
||||
|
||||
function getChannelRegions(channel, { regions }) {
|
||||
return channel.broadcast_area
|
||||
.reduce((acc, item) => {
|
||||
const [type, code] = item.split('/')
|
||||
switch (type) {
|
||||
case 'r':
|
||||
acc.push(regions[code])
|
||||
break
|
||||
case 's':
|
||||
const [c] = item.split('-')
|
||||
const r1 = _.filter(regions, { countries: [c] })
|
||||
acc = acc.concat(r1)
|
||||
break
|
||||
case 'c':
|
||||
const r2 = _.filter(regions, { countries: [code] })
|
||||
acc = acc.concat(r2)
|
||||
break
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
.filter(i => i)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ module.exports = async function (streams = []) {
|
|||
}
|
||||
}
|
||||
|
||||
let items = _.filter(streams, s => !s.languages.length)
|
||||
let items = _.filter(streams, stream => !stream.channel || !stream.channel.languages.length)
|
||||
output.push({ filepath: 'languages/undefined.m3u', items })
|
||||
|
||||
return output
|
||||
|
|
|
@ -5,15 +5,18 @@ module.exports = async function (streams = []) {
|
|||
const output = []
|
||||
await api.regions.load()
|
||||
const regions = await api.regions.all()
|
||||
streams = _.filter(streams, s => !s.channel || s.channel.is_nsfw === false)
|
||||
streams = _.filter(streams, stream => !stream.channel || stream.channel.is_nsfw === false)
|
||||
for (const region of regions) {
|
||||
const areaCodes = region.countries
|
||||
areaCodes.push(region.code)
|
||||
let items = _.filter(streams, s => _.intersection(areaCodes, s.broadcast_area).length)
|
||||
const areaCodes = region.countries.map(code => `c/${code}`)
|
||||
areaCodes.push(`r/${region.code}`)
|
||||
let items = _.filter(
|
||||
streams,
|
||||
stream => stream.channel && _.intersection(stream.channel.broadcast_area, areaCodes).length
|
||||
)
|
||||
output.push({ filepath: `regions/${region.code.toLowerCase()}.m3u`, items })
|
||||
}
|
||||
|
||||
let items = _.filter(streams, s => !s.broadcast_area.length)
|
||||
let items = _.filter(streams, stream => !stream.channel || !stream.channel.broadcast_area.length)
|
||||
output.push({ filepath: 'regions/undefined.m3u', items })
|
||||
|
||||
return output
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue