Validate Guides

This commit is contained in:
RevGear 2023-01-07 21:08:48 +00:00
parent 92c20a7232
commit f21ae7f646
4 changed files with 49 additions and 5 deletions

View File

@ -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",

View File

@ -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
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

View File

@ -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()

View File

@ -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