mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-13 02:20:03 -04:00
Added debug mode
This commit is contained in:
parent
f22fe20415
commit
e68602fdd1
4 changed files with 441 additions and 11 deletions
|
@ -4,6 +4,7 @@ const utils = require('./utils')
|
|||
const axios = require('axios')
|
||||
const ProgressBar = require('progress')
|
||||
const https = require('https')
|
||||
const chalk = require('chalk')
|
||||
|
||||
program
|
||||
.usage('[OPTIONS]...')
|
||||
|
@ -30,6 +31,10 @@ const instance = axios.create({
|
|||
const ignore = ['Geo-blocked', 'Not 24/7']
|
||||
|
||||
async function main() {
|
||||
console.info(`\nStarting...`)
|
||||
if (config.debug) {
|
||||
console.info(chalk.yellow(`INFO: Debug mode enabled\n`))
|
||||
}
|
||||
const playlists = parseIndex()
|
||||
|
||||
for (const playlist of playlists) {
|
||||
|
@ -54,29 +59,47 @@ async function loadPlaylist(url) {
|
|||
}
|
||||
|
||||
async function checkStatus(playlist) {
|
||||
const bar = new ProgressBar(' Testing: [:bar] :current/:total (:percent) ', {
|
||||
total: playlist.channels.length
|
||||
})
|
||||
let bar
|
||||
if (!config.debug) {
|
||||
bar = new ProgressBar(' Testing: [:bar] :current/:total (:percent) ', {
|
||||
total: playlist.channels.length
|
||||
})
|
||||
}
|
||||
const results = []
|
||||
for (const channel of playlist.channels) {
|
||||
bar.tick()
|
||||
const total = playlist.channels.length
|
||||
for (const [index, channel] of playlist.channels.entries()) {
|
||||
const current = index + 1
|
||||
const counter = chalk.gray(`[${current}/${total}]`)
|
||||
if (bar) bar.tick()
|
||||
if (
|
||||
(channel.status && ignore.map(i => i.toLowerCase()).includes(channel.status.toLowerCase())) ||
|
||||
(!channel.url.startsWith('http://') && !channel.url.startsWith('https://'))
|
||||
) {
|
||||
results.push(channel)
|
||||
if (config.debug) {
|
||||
console.info(` ${counter} ${chalk.green('online')} ${chalk.white(channel.url)}`)
|
||||
}
|
||||
} else {
|
||||
await instance
|
||||
.get(channel.url)
|
||||
.then(() => {
|
||||
results.push(channel)
|
||||
if (config.debug) {
|
||||
console.info(` ${counter} ${chalk.green('online')} ${chalk.white(channel.url)}`)
|
||||
}
|
||||
})
|
||||
.then(utils.sleep(config.delay))
|
||||
.catch(err => {
|
||||
if (err.response && err.response.status === 404) {
|
||||
//console.error(err)
|
||||
if (config.debug) {
|
||||
console.info(` ${counter} ${chalk.red('offline')} ${chalk.white(channel.url)}`)
|
||||
}
|
||||
} else {
|
||||
results.push(channel)
|
||||
if (config.debug) {
|
||||
console.info(` ${counter} ${chalk.green('online')} ${chalk.white(channel.url)}`)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue