A feature-rich command-line audio/video downloader
Add option `--sleep-requests` to sleep b/w requests (Closes #106)
pukkandan1cf376f55a3d
diff --git a/README.md b/README.mdindex 69813c2b75..8def97e4c1 100644--- a/README.md+++ b/README.md@@ -491,6 +491,8 @@ Then simply run `make`. You can also run `make yt-dlp` instead to compile only t--bidi-workaround Work around terminals that lackbidirectional text support. Requires bidivor fribidi executable in PATH+ --sleep-requests SECONDS Number of seconds to sleep between requests+ during data extraction--sleep-interval SECONDS Number of seconds to sleep before eachdownload when used alone or a lower boundof a range for randomized sleep before each@@ -501,7 +503,8 @@ Then simply run `make`. You can also run `make yt-dlp` instead to compile only tbefore each download (maximum possiblenumber of seconds to sleep). Must only beused along with --min-sleep-interval- --sleep-subtitles SECONDS Enforce sleep interval on subtitles as well+ --sleep-subtitles SECONDS Number of seconds to sleep before each+ subtitle download## Video Format Options:-f, --format FORMAT Video format code, see "FORMAT SELECTION"diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.pyindex a54755e158..3c53f4cd88 100644--- a/yt_dlp/YoutubeDL.py+++ b/yt_dlp/YoutubeDL.py@@ -324,6 +324,8 @@ class YoutubeDL(object):source_address: Client-side IP address to bind to.call_home: Boolean, true iff we are allowed to contact theyt-dlp servers for debugging. (BROKEN)+ sleep_interval_requests: Number of seconds to sleep between requests+ during extractionsleep_interval: Number of seconds to sleep before each download whenused alone or a lower bound of a range for randomizedsleep before each download (minimum possible number@@ -334,6 +336,7 @@ class YoutubeDL(object):Must only be used along with sleep_interval.Actual sleep time will be a random float from range[sleep_interval; max_sleep_interval].+ sleep_interval_subtitles: Number of seconds to sleep before each subtitle downloadlistformats: 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@@ -406,6 +409,7 @@ class YoutubeDL(object):_ies = []_pps = {'beforedl': [], 'aftermove': [], 'normal': []}__prepare_filename_warned = False+ _first_webpage_request = True_download_retcode = None_num_downloads = None_playlist_level = 0@@ -420,6 +424,7 @@ class YoutubeDL(object):self._ies_instances = {}self._pps = {'beforedl': [], 'aftermove': [], 'normal': []}self.__prepare_filename_warned = False+ self._first_webpage_request = Trueself._post_hooks = []self._progress_hooks = []self._download_retcode = 0@@ -2166,15 +2171,6 @@ class YoutubeDL(object):else:try:dl(sub_filename, sub_info, subtitle=True)- '''- if self.params.get('sleep_interval_subtitles', False):- dl(sub_filename, sub_info)- else:- sub_data = ie._request_webpage(- sub_info['url'], info_dict['id'], note=False).read()- with io.open(encodeFilename(sub_filename), 'wb') as subfile:- subfile.write(sub_data)- '''files_to_move[sub_filename] = sub_filename_finalexcept (ExtractorError, IOError, OSError, ValueError, compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:self.report_warning('Unable to download subtitle for "%s": %s' %diff --git a/yt_dlp/__init__.py b/yt_dlp/__init__.pyindex 91539daaf8..15605ab31e 100644--- a/yt_dlp/__init__.py+++ b/yt_dlp/__init__.py@@ -169,6 +169,12 @@ def _real_main(argv=None):parser.error('max sleep interval must be greater than or equal to min sleep interval')else:opts.max_sleep_interval = opts.sleep_interval+ if opts.sleep_interval_subtitles is not None:+ if opts.sleep_interval_subtitles < 0:+ parser.error('subtitles sleep interval must be positive or 0')+ if opts.sleep_interval_requests is not None:+ if opts.sleep_interval_requests < 0:+ parser.error('requests sleep interval must be positive or 0')if opts.ap_mso and opts.ap_mso not in MSO_INFO:parser.error('Unsupported TV Provider, use --ap-list-mso to get a list of supported TV Providers')if opts.overwrites:@@ -524,6 +530,7 @@ def _real_main(argv=None):'fixup': opts.fixup,'source_address': opts.source_address,'call_home': opts.call_home,+ 'sleep_interval_requests': opts.sleep_interval_requests,'sleep_interval': opts.sleep_interval,'max_sleep_interval': opts.max_sleep_interval,'sleep_interval_subtitles': opts.sleep_interval_subtitles,diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.pyindex 677a61b867..47b91a00a7 100644--- a/yt_dlp/extractor/common.py+++ b/yt_dlp/extractor/common.py@@ -606,6 +606,14 @@ class InfoExtractor(object):See _download_webpage docstring for arguments specification."""+ if not self._downloader._first_webpage_request:+ sleep_interval = float_or_none(self._downloader.params.get('sleep_interval_requests')) or 0+ if sleep_interval > 0:+ self.to_screen('Sleeping %s seconds...' % sleep_interval)+ time.sleep(sleep_interval)+ else:+ self._downloader._first_webpage_request = False+if note is None:self.report_download_webpage(video_id)elif note is not False:diff --git a/yt_dlp/options.py b/yt_dlp/options.pyindex 5f200fb8f7..ae11e6b8bc 100644--- a/yt_dlp/options.py+++ b/yt_dlp/options.py@@ -696,6 +696,10 @@ def parseOpts(overrideArguments=None):'--bidi-workaround',dest='bidi_workaround', action='store_true',help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')+ workarounds.add_option(+ '--sleep-requests', metavar='SECONDS',+ dest='sleep_interval_requests', type=float,+ help='Number of seconds to sleep between requests during data extraction')workarounds.add_option('--sleep-interval', '--min-sleep-interval', metavar='SECONDS',dest='sleep_interval', type=float,@@ -714,7 +718,7 @@ def parseOpts(overrideArguments=None):workarounds.add_option('--sleep-subtitles', metavar='SECONDS',dest='sleep_interval_subtitles', default=0, type=int,- help='Enforce sleep interval on subtitles as well')+ help='Number of seconds to sleep before each subtitle download')verbosity = optparse.OptionGroup(parser, 'Verbosity and Simulation Options')verbosity.add_option(