Skip to content

Commit

Permalink
[tumblr] add 'fallback-*' options (#2957)
Browse files Browse the repository at this point in the history
specifically 'fallback-delay' and 'fallback-retries'
and change default number of retries to 2 (down from 3)
  • Loading branch information
mikf committed Oct 29, 2022
1 parent 474bc1b commit 225752a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
21 changes: 21 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,27 @@ Description
You can use ``"all"`` instead of listing all types separately.


extractor.tumblr.fallback-delay
-------------------------------
Type
``float``
Default
``120.0``
Description
Number of seconds to wait between retries
for fetching full-resolution images.


extractor.tumblr.fallback-retries
---------------------------------
Type
``integer``
Default
``2``
Description
Number of retries for fetching full-resolution images.


extractor.twibooru.api-key
--------------------------
Type
Expand Down
6 changes: 4 additions & 2 deletions gallery_dl/extractor/tumblr.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def __init__(self, match):
self.reblogs = self.config("reblogs", True)
self.external = self.config("external", False)
self.original = self.config("original", True)
self.fallback_delay = self.config("fallback-delay", 120.0)
self.fallback_retries = self.config("fallback-retries", 2)

if len(self.types) == 1:
self.api.posts_type = next(iter(self.types))
Expand Down Expand Up @@ -250,8 +252,8 @@ def _update_image_token(self, resized):
return updated, (resized == updated)

def _original_image_fallback(self, url, post_id):
for _ in range(3):
self.sleep(120, "image token")
for _ in range(self.fallback_retries):
self.sleep(self.fallback_delay, "image token")
yield self._update_image_token(url)[0]
self.log.warning("Unable to fetch higher-resolution "
"version of %s (%s)", url, post_id)
Expand Down

0 comments on commit 225752a

Please sign in to comment.