Added random sleep for given interval range. Fixes #9930

This commit is contained in:
singh-pratyush96 2016-07-25 01:51:52 +05:30
parent e8be2943a7
commit 63000dd01f
4 changed files with 22 additions and 6 deletions

View File

@ -329,8 +329,11 @@ which means you can modify it, redistribute it or use it however you like.
--bidi-workaround Work around terminals that lack
bidirectional text support. Requires bidiv
or fribidi executable in PATH
--sleep-interval SECONDS Number of seconds to sleep before each
download.
--sleep-interval SECONDS/RANGE Number of seconds to sleep before each
download. Also accepts random sleep in
format <lower limit>to<upper limit> and
<upper limit>to<lower limit>, where limits
are in seconds.
## Video Format Options:
-f, --format FORMAT Video format code, see the "FORMAT

View File

@ -250,6 +250,10 @@ 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.
Accepts range for random sleep in formats:
- <lower limit>to<upper limit>
- <upper limit>to<lower limit>
where limits are in seconds
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
@ -1684,7 +1688,7 @@ class YoutubeDL(object):
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
self.report_error('unable to download video data: %s' % error_to_compat_str(err))
return
except (OSError, IOError) as err:
except (OSError, IOError, ValueError) as err:
raise UnavailableVideoError(err)
except (ContentTooShortError, ) as err:
self.report_error('content too short (expected %s bytes and served %s)' % (err.expected, err.downloaded))

View File

@ -4,6 +4,7 @@ import os
import re
import sys
import time
import random
from ..compat import compat_os_name
from ..utils import (
@ -344,8 +345,16 @@ class FileDownloader(object):
sleep_interval = self.params.get('sleep_interval')
if sleep_interval:
self.to_screen('[download] Sleeping %s seconds...' % sleep_interval)
time.sleep(sleep_interval)
sleep_interval_lower = sleep_interval.lower()
if 'to' in sleep_interval_lower:
lower_sleep_limit, upper_sleep_limit = map(float, sleep_interval_lower.split('to'))
sleep_time = random.uniform(lower_sleep_limit, upper_sleep_limit)
else:
sleep_time = float(sleep_interval)
self.to_screen('[download] Sleeping %s seconds...' % sleep_time)
time.sleep(sleep_time)
return self.real_download(filename, info_dict)

View File

@ -489,7 +489,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', type=str,
help='Number of seconds to sleep before each download.')
verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')