Add delay option

This commit is contained in:
Aleksandr Statciuk 2021-08-16 13:07:27 +03:00
parent 8fce5218db
commit 1dfe5e4956
2 changed files with 9 additions and 0 deletions

View File

@ -14,6 +14,7 @@ program
.option('-r, --resolution', 'Detect stream resolution') .option('-r, --resolution', 'Detect stream resolution')
.option('-c, --country <country>', 'Comma-separated list of country codes', '') .option('-c, --country <country>', 'Comma-separated list of country codes', '')
.option('-e, --exclude <exclude>', 'Comma-separated list of country codes to be excluded', '') .option('-e, --exclude <exclude>', 'Comma-separated list of country codes to be excluded', '')
.option('--delay <delay>', 'Set delay for each request', 0)
.option('--timeout <timeout>', 'Set timeout for each request', 5000) .option('--timeout <timeout>', 'Set timeout for each request', 5000)
.parse(process.argv) .parse(process.argv)
@ -90,6 +91,8 @@ async function updatePlaylist(playlist) {
.catch(err => { .catch(err => {
if (config.debug) log.print(` ERR: ${channel.url} (${err.message})\n`) if (config.debug) log.print(` ERR: ${channel.url} (${err.message})\n`)
}) })
await utils.sleep(config.delay)
} }
if (!config.debug) bar.tick() if (!config.debug) bar.tick()
} }

View File

@ -90,4 +90,10 @@ utils.filterPlaylists = function (arr, include = '', exclude = '') {
return arr return arr
} }
utils.sleep = function (ms) {
return function (x) {
return new Promise(resolve => setTimeout(() => resolve(x), ms))
}
}
module.exports = utils module.exports = utils