From 1dfe5e49561b25105ef80745eb619377a8bbacd7 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 16 Aug 2021 13:07:27 +0300 Subject: [PATCH] Add delay option --- scripts/format.js | 3 +++ scripts/helpers/utils.js | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/scripts/format.js b/scripts/format.js index 3a669d0d40..e5d5d040fb 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -14,6 +14,7 @@ program .option('-r, --resolution', 'Detect stream resolution') .option('-c, --country ', 'Comma-separated list of country codes', '') .option('-e, --exclude ', 'Comma-separated list of country codes to be excluded', '') + .option('--delay ', 'Set delay for each request', 0) .option('--timeout ', 'Set timeout for each request', 5000) .parse(process.argv) @@ -90,6 +91,8 @@ async function updatePlaylist(playlist) { .catch(err => { if (config.debug) log.print(` ERR: ${channel.url} (${err.message})\n`) }) + + await utils.sleep(config.delay) } if (!config.debug) bar.tick() } diff --git a/scripts/helpers/utils.js b/scripts/helpers/utils.js index f0d9b3e50d..3866ae4cae 100644 --- a/scripts/helpers/utils.js +++ b/scripts/helpers/utils.js @@ -90,4 +90,10 @@ utils.filterPlaylists = function (arr, include = '', exclude = '') { return arr } +utils.sleep = function (ms) { + return function (x) { + return new Promise(resolve => setTimeout(() => resolve(x), ms)) + } +} + module.exports = utils