mirror of https://github.com/iptv-org/iptv
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
3 years ago
|
const { db, logger, timer, checker, store, file, parser } = require('../../core')
|
||
3 years ago
|
const { program } = require('commander')
|
||
|
|
||
|
const options = program
|
||
|
.requiredOption('-c, --cluster-id <cluster-id>', 'The ID of cluster to load', parser.parseNumber)
|
||
|
.option('-t, --timeout <timeout>', 'Set timeout for each request', parser.parseNumber, 60000)
|
||
|
.option('-d, --delay <delay>', 'Set delay for each request', parser.parseNumber, 0)
|
||
|
.option('--debug', 'Enable debug mode')
|
||
|
.parse(process.argv)
|
||
|
.opts()
|
||
|
|
||
|
const config = {
|
||
|
timeout: options.timeout,
|
||
|
delay: options.delay,
|
||
|
debug: options.debug
|
||
|
}
|
||
|
|
||
3 years ago
|
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs/cluster/load'
|
||
3 years ago
|
|
||
|
async function main() {
|
||
3 years ago
|
logger.info('starting...')
|
||
|
logger.info(`timeout: ${options.timeout}ms`)
|
||
|
logger.info(`delay: ${options.delay}ms`)
|
||
3 years ago
|
timer.start()
|
||
|
|
||
3 years ago
|
const clusterLog = `${LOGS_DIR}/cluster_${options.clusterId}.log`
|
||
3 years ago
|
logger.info(`loading cluster: ${options.clusterId}`)
|
||
|
logger.info(`creating '${clusterLog}'...`)
|
||
3 years ago
|
await file.create(clusterLog)
|
||
3 years ago
|
await db.streams.load()
|
||
|
const items = await db.streams.find({ cluster_id: options.clusterId })
|
||
3 years ago
|
const total = items.length
|
||
3 years ago
|
logger.info(`found ${total} links`)
|
||
3 years ago
|
|
||
3 years ago
|
logger.info('checking...')
|
||
3 years ago
|
const results = {}
|
||
|
for (const [i, item] of items.entries()) {
|
||
|
const message = `[${i + 1}/${total}] ${item.filepath}: ${item.url}`
|
||
|
const result = await checker.check(item, config)
|
||
|
if (!result.error) {
|
||
|
logger.info(message)
|
||
|
} else {
|
||
|
logger.info(`${message} (${result.error})`)
|
||
|
}
|
||
|
await file.append(clusterLog, JSON.stringify(result) + '\n')
|
||
|
}
|
||
|
|
||
3 years ago
|
logger.info(`done in ${timer.format('HH[h] mm[m] ss[s]')}`)
|
||
3 years ago
|
}
|
||
|
|
||
|
main()
|