Skip to content

Commit

Permalink
add 'sleep-extractor' option (closes #964)
Browse files Browse the repository at this point in the history
(would have been nice if this were possible without code duplication)
  • Loading branch information
mikf committed Sep 12, 2020
1 parent 3108e85 commit 3afd362
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ Description Number of seconds to sleep before each download.
=========== =====


extractor.*.sleep-extractor
---------------------------
=========== =====
Type ``float``
Default ``0``
Description Number of seconds to sleep before handling an input URL,
i.e. before starting a new extractor.
=========== =====


extractor.*.username & .password
--------------------------------
=========== =====
Expand Down
7 changes: 7 additions & 0 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def __init__(self, extr, parent=None):

def run(self):
"""Execute or run the job"""
sleep = self.extractor.config("sleep-extractor")
if sleep:
time.sleep(sleep)
try:
log = self.extractor.log
for msg in self.extractor:
Expand Down Expand Up @@ -586,6 +589,10 @@ def __init__(self, url, parent=None, file=sys.stdout, ensure_ascii=True):
self.filter = (lambda x: x) if private else util.filter_dict

def run(self):
sleep = self.extractor.config("sleep-extractor")
if sleep:
time.sleep(sleep)

# collect data
try:
for msg in self.extractor:
Expand Down

2 comments on commit 3afd362

@Vrihub
Copy link
Contributor

@Vrihub Vrihub commented on 3afd362 Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I've noticed there are no command-line options in option.py for sleep-extractor (and sleep-request), although we have --sleep.
Is this intentional? Otherwise, I could add them if you think they would be useful.

@mikf
Copy link
Owner Author

@mikf mikf commented on 3afd362 Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

Kind of. I didn't think it was necessary to add them since 1) they are more specialized than the standard --sleep and 2) it is always possible to do -o sleep-extractor=N or -o sleep-request=N if one want's to set these options via cmdline.
Feel free to open a PR if you'd like to have them as regular cmdline options.

Please sign in to comment.