Files
epg/scripts/commands/api/update.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-02-26 23:21:44 +03:00
const { file, parser, logger } = require('../../core')
2022-02-03 20:41:03 +03:00
const { program } = require('commander')
2022-01-09 16:09:19 +03:00
const _ = require('lodash')
2022-02-03 20:41:03 +03:00
const CHANNELS_PATH = process.env.CHANNELS_PATH || 'sites/**/*.channels.xml'
2022-02-28 22:13:05 +03:00
const OUTPUT_DIR = process.env.OUTPUT_DIR || '.api'
2022-01-09 16:09:19 +03:00
async function main() {
2022-02-03 20:41:03 +03:00
let guides = []
2022-02-27 18:04:17 +03:00
2022-05-11 15:46:07 +03:00
const files = await file.list(CHANNELS_PATH).catch(console.error)
for (const filepath of files) {
try {
2022-02-27 18:04:17 +03:00
const { site, channels } = await parser.parseChannels(filepath)
const dir = file.dirname(filepath)
const config = require(file.resolve(`${dir}/${site}.config.js`))
if (config.ignore) continue
const filename = file.basename(filepath)
const [__, suffix] = filename.match(/\_(.*)\.channels\.xml$/) || [null, null]
for (const channel of channels) {
guides.push({
2022-06-16 21:58:15 +03:00
channel: channel.id,
site: channel.site,
2022-02-27 18:04:17 +03:00
lang: channel.lang,
2022-08-25 00:09:04 +03:00
url: `https://iptv-org.github.io/epg/guides/${suffix}/${site}.epg.xml.gz`
2022-02-27 18:04:17 +03:00
})
}
2022-05-11 15:46:07 +03:00
} catch (err) {
console.error(err)
continue
2022-02-03 20:41:03 +03:00
}
2022-01-21 20:10:45 +03:00
}
2022-01-18 22:19:36 +03:00
2022-02-03 20:41:03 +03:00
guides = _.sortBy(guides, 'channel')
2022-01-18 22:19:36 +03:00
2022-02-03 20:41:03 +03:00
const outputFilepath = `${OUTPUT_DIR}/guides.json`
await file.create(outputFilepath, JSON.stringify(guides))
logger.info(`saved to "${outputFilepath}"...`)
2022-01-31 01:36:14 +03:00
}
2022-02-03 20:41:03 +03:00
main()