Validate Guides
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
"programs:save": "node scripts/commands/programs/save.js",
|
"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": "NODE_OPTIONS=--max-old-space-size=5120 node scripts/commands/guides/update.js",
|
||||||
"guides:update_legacy": "node scripts/commands/guides/update_legacy.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:load": "./scripts/commands/api/load.sh",
|
||||||
"api:update": "node scripts/commands/api/update.js",
|
"api:update": "node scripts/commands/api/update.js",
|
||||||
"readme:update": "node scripts/commands/readme/update.js",
|
"readme:update": "node scripts/commands/readme/update.js",
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
mkdir -p scripts/data
|
mkdir -p scripts/data
|
||||||
curl -L -o scripts/data/channels.json https://iptv-org.github.io/api/channels.json
|
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/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/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/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
|
||||||
41
scripts/commands/guides/validate.js
Normal file
41
scripts/commands/guides/validate.js
Normal 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()
|
||||||
@@ -28,5 +28,6 @@ api.channels = new API(`${DATA_DIR}/channels.json`)
|
|||||||
api.regions = new API(`${DATA_DIR}/regions.json`)
|
api.regions = new API(`${DATA_DIR}/regions.json`)
|
||||||
api.countries = new API(`${DATA_DIR}/countries.json`)
|
api.countries = new API(`${DATA_DIR}/countries.json`)
|
||||||
api.subdivisions = new API(`${DATA_DIR}/subdivisions.json`)
|
api.subdivisions = new API(`${DATA_DIR}/subdivisions.json`)
|
||||||
|
api.guides = new API(`${DATA_DIR}/guides.json`)
|
||||||
|
|
||||||
module.exports = api
|
module.exports = api
|
||||||
|
|||||||
Reference in New Issue
Block a user