Update test.js
This commit is contained in:
parent
e1afcafcaa
commit
c3676dd23c
@ -1,14 +1,27 @@
|
|||||||
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0
|
const { program } = require('commander')
|
||||||
|
|
||||||
const helper = require('./helper')
|
const helper = require('./helper')
|
||||||
const iptvChecker = require('iptv-checker-module')
|
const axios = require('axios')
|
||||||
|
const https = require('https')
|
||||||
|
const ProgressBar = require('progress')
|
||||||
|
|
||||||
const config = {
|
program
|
||||||
debug: process.env.npm_config_debug || false,
|
.usage('[OPTIONS]...')
|
||||||
country: process.env.npm_config_country,
|
.option('-d, --debug', 'Debug mode')
|
||||||
exclude: process.env.npm_config_exclude,
|
.option('-c, --country <country>', 'Comma-separated list of country codes', '')
|
||||||
timeout: 10000
|
.option('-e, --exclude <exclude>', 'Comma-separated list of country codes to be excluded', '')
|
||||||
}
|
.option('--delay <delay>', 'Delay between parser requests', 1000)
|
||||||
|
.option('--timeout <timeout>', 'Set timeout for each request', 5000)
|
||||||
|
.parse(process.argv)
|
||||||
|
|
||||||
|
const config = program.opts()
|
||||||
|
|
||||||
|
const instance = axios.create({
|
||||||
|
timeout: config.timeout,
|
||||||
|
maxContentLength: 20000,
|
||||||
|
httpsAgent: new https.Agent({
|
||||||
|
rejectUnauthorized: false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
let stats = {
|
let stats = {
|
||||||
playlists: 0,
|
playlists: 0,
|
||||||
@ -22,47 +35,40 @@ async function test() {
|
|||||||
const countries = helper.filterPlaylists(playlist.items, config.country, config.exclude)
|
const countries = helper.filterPlaylists(playlist.items, config.country, config.exclude)
|
||||||
|
|
||||||
for (let country of countries) {
|
for (let country of countries) {
|
||||||
|
const playlist = helper.parsePlaylist(country.url)
|
||||||
|
const bar = new ProgressBar(`Processing '${country.url}'...:current/:total\n`, {
|
||||||
|
total: playlist.items.length
|
||||||
|
})
|
||||||
|
|
||||||
stats.playlists++
|
stats.playlists++
|
||||||
|
|
||||||
console.log(`Processing '${country.url}'...`)
|
for (let channel of playlist.items) {
|
||||||
|
bar.tick()
|
||||||
const options = {
|
stats.channels++
|
||||||
timeout: config.timeout,
|
await instance
|
||||||
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
|
.get(channel.url)
|
||||||
debug: config.debug,
|
.then(helper.sleep(config.delay))
|
||||||
omitMetadata: true,
|
.catch(error => {
|
||||||
parallel: 1,
|
if (error.response) {
|
||||||
itemCallback: item => {
|
stats.failures++
|
||||||
stats.channels++
|
helper.writeToLog(country.url, error.message, channel.url)
|
||||||
if (
|
console.log(`Error: ${error.message} '${channel.url}'`)
|
||||||
!item.status.ok &&
|
}
|
||||||
item.status.reason !== 'Timed out' &&
|
})
|
||||||
item.status.reason !== 'Duplicate' &&
|
|
||||||
item.status.reason !== 'Server returned 403 Forbidden (access denied)'
|
|
||||||
) {
|
|
||||||
stats.failures++
|
|
||||||
|
|
||||||
helper.writeToLog(country.url, item.status.reason, item.url)
|
|
||||||
|
|
||||||
console.log(`${item.status.reason} '${item.url}'`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await iptvChecker(country.url, options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stats.failures === 0) {
|
if (stats.failures === 0) {
|
||||||
console.log(`OK (${stats.playlists} playlists, ${stats.channels} channels)`)
|
console.log(`\nOK (${stats.playlists} playlists, ${stats.channels} channels)`)
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
`FAILURES! (${stats.playlists} playlists, ${stats.channels} channels, ${stats.failures} failures)`
|
`\nFAILURES! (${stats.playlists} playlists, ${stats.channels} channels, ${stats.failures} failures)`
|
||||||
)
|
)
|
||||||
|
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Test is running...')
|
console.log('Test is running...\n')
|
||||||
|
|
||||||
test()
|
test()
|
||||||
|
Loading…
Reference in New Issue
Block a user