From 1ad6b891b21b45830736698a7b59c30d9605a562 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sergey=20M=E2=80=A4?= Date: Tue, 9 Aug 2016 03:47:56 +0700 Subject: [PATCH] Add more checks for --min/max-sleep-interval arguments and use more idiomatic naming --- youtube_dl/__init__.py | 12 ++++++++---- youtube_dl/downloader/common.py | 9 +++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 86af18d33..a9730292c 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -147,10 +147,14 @@ def _real_main(argv=None): opts.max_filesize = numeric_limit if opts.sleep_interval is not None: if opts.sleep_interval < 0: - parser.error('sleep interval should not be negative') - elif opts.max_sleep_interval is not None: - if opts.max_sleep_interval < opts.sleep_interval: - parser.error('max sleep interval should not be less than sleep interval') + parser.error('sleep interval must be positive or 0') + if opts.max_sleep_interval is not None: + if opts.max_sleep_interval < 0: + parser.error('max sleep interval must be positive or 0') + if opts.max_sleep_interval < opts.sleep_interval: + parser.error('max sleep interval must be greater than or equal to min sleep interval') + else: + opts.max_sleep_interval = opts.sleep_interval def parse_retries(retries): if retries in ('inf', 'infinite'): diff --git a/youtube_dl/downloader/common.py b/youtube_dl/downloader/common.py index 8e377c72c..8482cbd84 100644 --- a/youtube_dl/downloader/common.py +++ b/youtube_dl/downloader/common.py @@ -343,10 +343,11 @@ class FileDownloader(object): }) return True - sleep_lower_bound = self.params.get('sleep_interval') - if sleep_lower_bound: - sleep_upper_bound = self.params.get('max_sleep_interval', sleep_lower_bound) - sleep_interval = random.uniform(sleep_lower_bound, sleep_upper_bound) + min_sleep_interval = self.params.get('sleep_interval') + if min_sleep_interval: + max_sleep_interval = self.params.get('max_sleep_interval', min_sleep_interval) + print(min_sleep_interval, max_sleep_interval) + sleep_interval = random.uniform(min_sleep_interval, max_sleep_interval) self.to_screen('[download] Sleeping %s seconds...' % sleep_interval) time.sleep(sleep_interval) -- 2.22.2