mirror of
https://github.com/l1ving/youtube-dl
synced 2025-01-25 07:12:52 +08:00
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.
This commit is contained in:
parent
c69aecf56a
commit
98d54f3f67
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user