mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update update-api.js
This commit is contained in:
parent
876b1a44b7
commit
e60b642c98
1 changed files with 15 additions and 25 deletions
|
@ -5,45 +5,35 @@ const DB_DIR = process.env.DB_DIR || 'scripts/database'
|
||||||
const API_DIR = process.env.API_DIR || '.gh-pages/api'
|
const API_DIR = process.env.API_DIR || '.gh-pages/api'
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await saveToChannelsJson(await loadChannels())
|
await saveToGuidesJson(await loadGuides())
|
||||||
await saveToProgramsJson(await loadPrograms())
|
await saveToProgramsJson(await loadPrograms())
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
async function loadChannels() {
|
async function loadGuides() {
|
||||||
logger.info('Loading channels from database...')
|
logger.info('Loading guides from database...')
|
||||||
|
|
||||||
await db.channels.load()
|
await db.channels.load()
|
||||||
|
|
||||||
const channels = await db.channels.find({}).sort({ xmltv_id: 1 })
|
const channels = await db.channels.find({}).sort({ xmltv_id: 1 })
|
||||||
|
|
||||||
const output = {}
|
const output = []
|
||||||
for (const channel of channels) {
|
for (const channel of channels) {
|
||||||
if (!output[channel.xmltv_id]) {
|
|
||||||
output[channel.xmltv_id] = {
|
|
||||||
id: channel.xmltv_id,
|
|
||||||
name: [],
|
|
||||||
logo: channel.logo || null,
|
|
||||||
country: channel.country,
|
|
||||||
guides: []
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
output[channel.xmltv_id].logo = output[channel.xmltv_id].logo || channel.logo
|
|
||||||
}
|
|
||||||
|
|
||||||
output[channel.xmltv_id].name.push(channel.name)
|
|
||||||
output[channel.xmltv_id].name = _.uniq(output[channel.xmltv_id].name)
|
|
||||||
channel.groups.forEach(group => {
|
channel.groups.forEach(group => {
|
||||||
if (channel.programCount) {
|
if (channel.programCount) {
|
||||||
output[channel.xmltv_id].guides.push(
|
output.push({
|
||||||
`https://iptv-org.github.io/epg/guides/${group}.epg.xml`
|
channel: channel.xmltv_id,
|
||||||
)
|
display_name: channel.name,
|
||||||
|
site: channel.site,
|
||||||
|
lang: channel.lang,
|
||||||
|
url: `https://iptv-org.github.io/epg/guides/${group}.epg.xml`
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.values(output)
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadPrograms() {
|
async function loadPrograms() {
|
||||||
|
@ -76,10 +66,10 @@ async function loadPrograms() {
|
||||||
return programs
|
return programs
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveToChannelsJson(channels = []) {
|
async function saveToGuidesJson(guides = []) {
|
||||||
const channelsPath = `${API_DIR}/channels.json`
|
const channelsPath = `${API_DIR}/guides.json`
|
||||||
logger.info(`Saving to "${channelsPath}"...`)
|
logger.info(`Saving to "${channelsPath}"...`)
|
||||||
await file.create(channelsPath, JSON.stringify(channels))
|
await file.create(channelsPath, JSON.stringify(guides))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveToProgramsJson(programs = []) {
|
async function saveToProgramsJson(programs = []) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue