mirror of https://github.com/iptv-org/iptv
wip
parent
9a4a62fd10
commit
109deb476d
@ -1,47 +1,27 @@
|
|||||||
const { create: createPlaylist } = require('../core/playlist')
|
|
||||||
const api = require('../core/api')
|
const api = require('../core/api')
|
||||||
const file = require('../core/file')
|
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
|
|
||||||
|
|
||||||
module.exports = async function (streams = []) {
|
module.exports = async function (streams = []) {
|
||||||
const logs = []
|
streams = _.orderBy(
|
||||||
|
streams,
|
||||||
|
['channel.name', 'status.level', 'resolution.height'],
|
||||||
|
['asc', 'asc', 'desc']
|
||||||
|
)
|
||||||
|
streams = _.uniqBy(streams, s => s.channel_id || _.uniqueId())
|
||||||
|
const output = []
|
||||||
await api.categories.load()
|
await api.categories.load()
|
||||||
const categories = await api.categories.all()
|
const categories = await api.categories.all()
|
||||||
|
|
||||||
for (const category of categories) {
|
for (const category of categories) {
|
||||||
let output = _.filter(streams, { channel: { categories: [category.id] } })
|
let items = _.filter(streams, { channel: { categories: [category.id] } })
|
||||||
output = _.orderBy(
|
output.push({ id: category.id, items })
|
||||||
output,
|
|
||||||
['channel.name', 'status.level', 'resolution.height'],
|
|
||||||
['asc', 'asc', 'desc']
|
|
||||||
)
|
|
||||||
output = _.uniqBy(output, s => s.channel_id || _.uniqueId())
|
|
||||||
|
|
||||||
const playlist = createPlaylist(output, { public: true })
|
|
||||||
await file.create(`${PUBLIC_DIR}/categories/${category.id}.m3u`, playlist.toString())
|
|
||||||
|
|
||||||
logs.push({ id: category.id, count: output.length })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = _.filter(streams, s => !s.categories.length)
|
let items = _.filter(streams, s => !s.categories.length)
|
||||||
output = _.orderBy(
|
items = items.map(item => {
|
||||||
output,
|
|
||||||
['channel.name', 'status.level', 'resolution.height'],
|
|
||||||
['asc', 'asc', 'desc']
|
|
||||||
)
|
|
||||||
output = _.uniqBy(output, s => s.channel_id || _.uniqueId())
|
|
||||||
output = output.map(item => {
|
|
||||||
item.group_title = 'Other'
|
item.group_title = 'Other'
|
||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
|
output.push({ id: 'other', items })
|
||||||
|
|
||||||
const playlist = createPlaylist(output, { public: true })
|
return output
|
||||||
await file.create(`${PUBLIC_DIR}/categories/other.m3u`, playlist.toString())
|
|
||||||
|
|
||||||
logs.push({ id: 'other', count: output.length })
|
|
||||||
|
|
||||||
return logs
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue