mirror of
https://github.com/l1ving/youtube-dl
synced 2025-03-13 22:07:17 +08:00
Added random sleep for given interval range. Fixes #9930
This commit is contained in:
parent
e8be2943a7
commit
b6e542a3df
@ -250,6 +250,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.
|
||||
max_sleep_interval:Upper bound of number of seconds for random sleep.
|
||||
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
|
||||
|
@ -370,6 +370,7 @@ def _real_main(argv=None):
|
||||
'source_address': opts.source_address,
|
||||
'call_home': opts.call_home,
|
||||
'sleep_interval': opts.sleep_interval,
|
||||
'max_sleep_interval': opts.max_sleep_interval,
|
||||
'external_downloader': opts.external_downloader,
|
||||
'list_thumbnails': opts.list_thumbnails,
|
||||
'playlist_items': opts.playlist_items,
|
||||
|
@ -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)
|
||||
min_sleep_interval = sleep_interval
|
||||
max_sleep_interval = self.params.get('max_sleep_interval') or min_sleep_interval
|
||||
|
||||
sleep_time = random.uniform(
|
||||
min_sleep_interval,
|
||||
max_sleep_interval
|
||||
)
|
||||
|
||||
self.to_screen('[download] Sleeping %s seconds...' % sleep_time)
|
||||
time.sleep(sleep_time)
|
||||
|
||||
return self.real_download(filename, info_dict)
|
||||
|
||||
|
@ -491,6 +491,11 @@ def parseOpts(overrideArguments=None):
|
||||
'--sleep-interval', metavar='SECONDS',
|
||||
dest='sleep_interval', type=float,
|
||||
help='Number of seconds to sleep before each download.')
|
||||
workarounds.add_option(
|
||||
'--max-sleep-interval', metavar='SECONDS',
|
||||
dest='max_sleep_interval', type=float,
|
||||
help='Maximum sleep time for random sleep.'
|
||||
)
|
||||
|
||||
verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
|
||||
verbosity.add_option(
|
||||
|
Loading…
x
Reference in New Issue
Block a user