From 9903d36ca61fe3a76a4a9e7d6b94a3a77ee3864b Mon Sep 17 00:00:00 2001 From: shan3k Date: Fri, 1 Jul 2016 22:14:49 +0100 Subject: [PATCH 1/3] Added random number generation for sleep-interval --- youtube_dl/YoutubeDL.py | 3 ++- youtube_dl/downloader/common.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 5036289b0..96e59a4c9 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -248,7 +248,8 @@ class YoutubeDL(object): source_address: (Experimental) Client-side IP address to bind to. call_home: Boolean, true iff we are allowed to contact the youtube-dl servers for debugging. - sleep_interval: Number of seconds to sleep before each download. + sleep_interval: A random number of seconds to sleep before each download. + The script will choose a random number below sleep_interval. listformats: Print an overview of available video formats and exit. list_thumbnails: Print a table of all thumbnails and exit. match_filter: A function that gets called with the info_dict of diff --git a/youtube_dl/downloader/common.py b/youtube_dl/downloader/common.py index 1dba9f49a..9dcb103b7 100644 --- a/youtube_dl/downloader/common.py +++ b/youtube_dl/downloader/common.py @@ -4,6 +4,7 @@ import os import re import sys import time +import random from ..compat import compat_os_name from ..utils import ( @@ -342,7 +343,7 @@ class FileDownloader(object): }) return True - sleep_interval = self.params.get('sleep_interval') + sleep_interval = random.randrange(self.params.get('sleep_interval')) if sleep_interval: self.to_screen('[download] Sleeping %s seconds...' % sleep_interval) time.sleep(sleep_interval) From c69aecf56a30051d5f8c5883e02efea1364caa6b Mon Sep 17 00:00:00 2001 From: shan3k Date: Sat, 2 Jul 2016 20:41:44 +0100 Subject: [PATCH 2/3] Revert "Added random number generation for sleep-interval" This reverts commit 9903d36ca61fe3a76a4a9e7d6b94a3a77ee3864b. --- youtube_dl/YoutubeDL.py | 3 +-- youtube_dl/downloader/common.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 96e59a4c9..5036289b0 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -248,8 +248,7 @@ class YoutubeDL(object): source_address: (Experimental) Client-side IP address to bind to. call_home: Boolean, true iff we are allowed to contact the youtube-dl servers for debugging. - sleep_interval: A random number of seconds to sleep before each download. - The script will choose a random number below sleep_interval. + sleep_interval: Number of seconds to sleep before each download. listformats: Print an overview of available video formats and exit. list_thumbnails: Print a table of all thumbnails and exit. match_filter: A function that gets called with the info_dict of diff --git a/youtube_dl/downloader/common.py b/youtube_dl/downloader/common.py index 9dcb103b7..1dba9f49a 100644 --- a/youtube_dl/downloader/common.py +++ b/youtube_dl/downloader/common.py @@ -4,7 +4,6 @@ import os import re import sys import time -import random from ..compat import compat_os_name from ..utils import ( @@ -343,7 +342,7 @@ class FileDownloader(object): }) return True - sleep_interval = random.randrange(self.params.get('sleep_interval')) + sleep_interval = self.params.get('sleep_interval') if sleep_interval: self.to_screen('[download] Sleeping %s seconds...' % sleep_interval) time.sleep(sleep_interval) From 98d54f3f67c60613d3e6e5be9601aadc56bd78e8 Mon Sep 17 00:00:00 2001 From: shan3k Date: Sat, 2 Jul 2016 22:31:05 +0100 Subject: [PATCH 3/3] Updated sleep_interval to allow random range. Updated sleep_interval flag to allow range from which we derive a random timer for the sleep period. --- youtube_dl/YoutubeDL.py | 1 + youtube_dl/downloader/common.py | 7 +++++++ youtube_dl/options.py | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 5036289b0..fdbd948af 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -249,6 +249,7 @@ class YoutubeDL(object): call_home: Boolean, true iff we are allowed to contact the youtube-dl servers for debugging. sleep_interval: Number of seconds to sleep before each download. + Can accept range for random sleep in form a-b. listformats: Print an overview of available video formats and exit. list_thumbnails: Print a table of all thumbnails and exit. match_filter: A function that gets called with the info_dict of diff --git a/youtube_dl/downloader/common.py b/youtube_dl/downloader/common.py index 1dba9f49a..bf45bb8f1 100644 --- a/youtube_dl/downloader/common.py +++ b/youtube_dl/downloader/common.py @@ -4,6 +4,7 @@ import os import re import sys import time +import random from ..compat import compat_os_name from ..utils import ( @@ -343,6 +344,12 @@ class FileDownloader(object): return True sleep_interval = self.params.get('sleep_interval') + if '-' in sleep_interval: + try: + start, stop = sleep_interval.split('-') + sleep_interval = random.randrange(int(start), int(stop)) + except ValueError: + raise ValueError("Invalid range 'a-b' provided, expected 'a' to be integer less than 'b'") if sleep_interval: self.to_screen('[download] Sleeping %s seconds...' % sleep_interval) time.sleep(sleep_interval) diff --git a/youtube_dl/options.py b/youtube_dl/options.py index c9033e3cb..bab6d89bc 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -480,7 +480,7 @@ def parseOpts(overrideArguments=None): help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH') workarounds.add_option( '--sleep-interval', metavar='SECONDS', - dest='sleep_interval', type=float, + dest='sleep_interval', help='Number of seconds to sleep before each download.') verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')