Update test.js

This commit is contained in:
freearhey 2021-01-30 06:41:19 +03:00
parent ea761db9d5
commit 8127e77b07

View File

@ -1,5 +1,6 @@
const { program } = require('commander') const { program } = require('commander')
const helper = require('./helper') const utils = require('./utils')
const parser = require('./parser')
const axios = require('axios') const axios = require('axios')
const https = require('https') const https = require('https')
const ProgressBar = require('progress') const ProgressBar = require('progress')
@ -30,28 +31,27 @@ let stats = {
} }
async function test() { async function test() {
const playlist = helper.parsePlaylist('index.m3u') let items = parser.parseIndex()
items = utils.filterPlaylists(items, config.country, config.exclude)
const countries = helper.filterPlaylists(playlist.items, config.country, config.exclude) for (const item of items) {
const playlist = parser.parsePlaylist(item.url)
for (let country of countries) { const bar = new ProgressBar(`Processing '${item.url}'...:current/:total`, {
const playlist = helper.parsePlaylist(country.url) total: playlist.channels.length
const bar = new ProgressBar(`Processing '${country.url}'...:current/:total\n`, {
total: playlist.items.length
}) })
stats.playlists++ stats.playlists++
for (let channel of playlist.items) { for (let channel of playlist.channels) {
bar.tick() bar.tick()
stats.channels++ stats.channels++
await instance await instance
.get(channel.url) .get(channel.url)
.then(helper.sleep(config.delay)) .then(utils.sleep(config.delay))
.catch(error => { .catch(error => {
if (error.response) { if (error.response) {
stats.failures++ stats.failures++
helper.writeToLog(country.url, error.message, channel.url) utils.writeToLog(country.url, error.message, channel.url)
console.log(`Error: ${error.message} '${channel.url}'`) console.log(`Error: ${error.message} '${channel.url}'`)
} }
}) })