diff --git a/scripts/commands/api/update.js b/scripts/commands/api/update.js index f11afa47..db5212bd 100644 --- a/scripts/commands/api/update.js +++ b/scripts/commands/api/update.js @@ -2,35 +2,22 @@ const { file, parser, logger } = require('../../core') const { program } = require('commander') const _ = require('lodash') -const CHANNELS_PATH = process.env.CHANNELS_PATH || 'sites/**/*.channels.xml' +const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs' const OUTPUT_DIR = process.env.OUTPUT_DIR || '.api' async function main() { let guides = [] - const files = await file.list(CHANNELS_PATH).catch(console.error) - for (const filepath of files) { - try { - 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 logPath = `${LOGS_DIR}/guides/update.log` + const results = await parser.parseLogs(logPath) - const filename = file.basename(filepath) - const [__, suffix] = filename.match(/\_(.*)\.channels\.xml$/) || [null, null] - - for (const channel of channels) { - guides.push({ - channel: channel.id, - site: channel.site, - lang: channel.lang, - url: `https://iptv-org.github.io/epg/guides/${suffix}/${site}.epg.xml.gz` - }) - } - } catch (err) { - console.error(err) - continue - } + for (const result of results) { + guides.push({ + channel: result.channel, + site: result.site, + lang: result.lang, + url: `https://iptv-org.github.io/epg/guides/${result.filename}.xml.gz` + }) } guides = _.sortBy(guides, 'channel')