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.
iptv/scripts/test.js

75 lines
1.9 KiB
JavaScript

4 years ago
const { program } = require('commander')
4 years ago
const utils = require('./utils')
const parser = require('./parser')
4 years ago
const axios = require('axios')
const https = require('https')
const ProgressBar = require('progress')
4 years ago
program
.usage('[OPTIONS]...')
.option('-d, --debug', 'Debug mode')
.option('-c, --country <country>', 'Comma-separated list of country codes', '')
.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 = {
playlists: 0,
channels: 0,
failures: 0
}
async function test() {
4 years ago
let items = parser.parseIndex()
items = utils.filterPlaylists(items, config.country, config.exclude)
4 years ago
for (const item of items) {
const playlist = parser.parsePlaylist(item.url)
const bar = new ProgressBar(`Processing '${item.url}'...:current/:total`, {
total: playlist.channels.length
4 years ago
})
4 years ago
stats.playlists++
4 years ago
for (let channel of playlist.channels) {
4 years ago
bar.tick()
stats.channels++
await instance
.get(channel.url)
4 years ago
.then(utils.sleep(config.delay))
4 years ago
.catch(error => {
if (error.response) {
stats.failures++
utils.writeToLog(item.url, error.message, channel.url)
4 years ago
}
})
}
}
if (stats.failures === 0) {
4 years ago
console.log(`\nOK (${stats.playlists} playlists, ${stats.channels} channels)`)
} else {
console.log(
`\nFAILURES! (${stats.playlists} playlists, ${stats.channels} channels, ${stats.failures} failures)
\n\nCheck the "error.log" file to see which links failed.`
)
5 years ago
process.exit(1)
}
}
4 years ago
console.log('Test is running...\n')
test()