0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-27 03:03:01 +00:00

Added --sleep-interval option

This commit is contained in:
rupertbaxter2 2014-08-03 07:34:04 -07:00
parent 493987fefe
commit 03359e9864
3 changed files with 14 additions and 0 deletions

View file

@ -351,6 +351,8 @@ def _hide_login_info(opts):
downloader.add_option('-r', '--rate-limit',
dest='ratelimit', metavar='LIMIT', help='maximum download rate in bytes per second (e.g. 50K or 4.2M)')
downloader.add_option('--sleep-interval',
dest='sleepinterval', metavar='SLEEPINTERVAL', help='number of seconds to sleep between downloads (default is %default)', default="0")
downloader.add_option('-R', '--retries',
dest='retries', metavar='RETRIES', help='number of retries (default is %default)', default=10)
downloader.add_option('--buffer-size',
@ -671,6 +673,11 @@ def _real_main(argv=None):
if numeric_limit is None:
parser.error(u'invalid rate limit specified')
opts.ratelimit = numeric_limit
if opts.sleepinterval is not None:
try:
opts.sleepinterval = abs(int(opts.sleepinterval))
except ValueError:
parser.error(u'invalid sleep interval specified')
if opts.min_filesize is not None:
numeric_limit = FileDownloader.parse_bytes(opts.min_filesize)
if numeric_limit is None:
@ -767,6 +774,7 @@ def _real_main(argv=None):
'restrictfilenames': opts.restrictfilenames,
'ignoreerrors': opts.ignoreerrors,
'ratelimit': opts.ratelimit,
'sleepinterval': opts.sleepinterval,
'nooverwrites': opts.nooverwrites,
'retries': opts.retries,
'buffersize': opts.buffersize,

View file

@ -278,6 +278,9 @@ def download(self, filename, info_dict):
"""Download to a filename using the info from info_dict
Return True on success and False otherwise
"""
sleep_interval = self.params.get('sleepinterval', 0)
self.to_screen(u'[download] Sleeping %d seconds...' %sleep_interval)
time.sleep(sleep_interval)
# Check file already present
if self.params.get('continuedl', False) and os.path.isfile(encodeFilename(filename)) and not self.params.get('nopart', False):
self.report_file_already_downloaded(filename)

View file

@ -6,6 +6,7 @@
import contextlib
import ctypes
import datetime
import time
import email.utils
import errno
import getpass
@ -747,6 +748,8 @@ def http_request(self, req):
del req.headers['User-agent']
req.headers['User-agent'] = req.headers['Youtubedl-user-agent']
del req.headers['Youtubedl-user-agent']
#print("sleeping\n")
#time.sleep(1)
return req
def http_response(self, req, resp):