diff --git a/package.json b/package.json index e388af72..0a270759 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "programs:save": "node scripts/commands/programs/save.js", "guides:update": "NODE_OPTIONS=--max-old-space-size=5120 node scripts/commands/guides/update.js", "guides:update_legacy": "node scripts/commands/guides/update_legacy.js", + "guides:validate": "node scripts/commands/guides/validate.js", "api:load": "./scripts/commands/api/load.sh", "api:update": "node scripts/commands/api/update.js", "readme:update": "node scripts/commands/readme/update.js", diff --git a/scripts/commands/api/load.sh b/scripts/commands/api/load.sh index 00b0a62a..6915c456 100755 --- a/scripts/commands/api/load.sh +++ b/scripts/commands/api/load.sh @@ -1,7 +1,8 @@ #!/bin/bash -mkdir -p scripts/data -curl -L -o scripts/data/channels.json https://iptv-org.github.io/api/channels.json -curl -L -o scripts/data/countries.json https://iptv-org.github.io/api/countries.json -curl -L -o scripts/data/regions.json https://iptv-org.github.io/api/regions.json -curl -L -o scripts/data/subdivisions.json https://iptv-org.github.io/api/subdivisions.json \ No newline at end of file +mkdir -p scripts/data +curl -L -o scripts/data/channels.json https://iptv-org.github.io/api/channels.json +curl -L -o scripts/data/countries.json https://iptv-org.github.io/api/countries.json +curl -L -o scripts/data/regions.json https://iptv-org.github.io/api/regions.json +curl -L -o scripts/data/subdivisions.json https://iptv-org.github.io/api/subdivisions.json +curl -L -o scripts/data/guides.json https://iptv-org.github.io/api/guides.json \ No newline at end of file diff --git a/scripts/commands/guides/validate.js b/scripts/commands/guides/validate.js new file mode 100644 index 00000000..bfd045eb --- /dev/null +++ b/scripts/commands/guides/validate.js @@ -0,0 +1,41 @@ +const { db, logger, api } = require('../../core') +const chalk = require('chalk') + +async function main() { + await api.channels.load() + await api.guides.load() + logger.info('loading database/programs.db...') + await db.programs.load() + let db_programs = await db.programs.find({}) + logger.info(`found ${db_programs.length} programs`) + + const stats = { + files: 0, + errors: 0 + } + const errors = [] + let api_channels = await api.channels.all() + + api_channels.forEach(channel => { + let programs = db_programs.filter(p => p.channel == channel.id) + if (programs.length > 0) { + if (!api.guides.find({ channel: channel.id })) { + errors.push({ type: 'no_guide', xmltv_id: channel.id, ...channel }) + stats.errors++ + } + } + }) + + if (errors.length) { + console.table(errors, ['type', 'xmltv_id', 'name', 'country']) + console.log() + stats.files++ + } + + if (stats.errors > 0) { + logger.error(chalk.red(`${stats.errors} error(s)`)) + process.exit(1) + } +} + +main() diff --git a/scripts/core/api.js b/scripts/core/api.js index e18e4da3..9f96a2cd 100644 --- a/scripts/core/api.js +++ b/scripts/core/api.js @@ -28,5 +28,6 @@ api.channels = new API(`${DATA_DIR}/channels.json`) api.regions = new API(`${DATA_DIR}/regions.json`) api.countries = new API(`${DATA_DIR}/countries.json`) api.subdivisions = new API(`${DATA_DIR}/subdivisions.json`) +api.guides = new API(`${DATA_DIR}/guides.json`) module.exports = api