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

43 lines
1.2 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'
const OUTPUT_DIR = process.env.OUTPUT_DIR || '.gh-pages/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
try {
const files = await file.list(CHANNELS_PATH)
for (const filepath of files) {
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({
channel: channel.xmltv_id,
site,
lang: channel.lang,
url: `https://iptv-org.github.io/epg/guides/${suffix}/${site}.epg.xml`
})
}
2022-02-03 20:41:03 +03:00
}
2022-02-27 18:04:17 +03:00
} catch (err) {
console.error(err)
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()