Skip to content

Commit

Permalink
implement a 'fallback' option (closes #1770)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Aug 15, 2021
1 parent c866fcb commit d320ee6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
30 changes: 20 additions & 10 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,6 @@ Description
Share number of skipped downloads between parent and child extractors.


extractor.*.url-metadata
------------------------
Type
``string``
Default
``null``
Description
Insert a file's download URL into its metadata dictionary as the given name.


extractor.*.path-restrict
-------------------------
Type
Expand Down Expand Up @@ -507,6 +497,16 @@ Description
`format strings`_.


extractor.*.url-metadata
------------------------
Type
``string``
Default
``null``
Description
Insert a file's download URL into its metadata dictionary as the given name.


extractor.*.category-transfer
-----------------------------
Type
Expand Down Expand Up @@ -671,6 +671,16 @@ Description
will be executed as normal.


extractor.*.fallback
--------------------
Type
``bool``
Default
``true``
Description
Use fallback download URLs when a download fails.


extractor.*.image-range
-----------------------
Type
Expand Down
1 change: 1 addition & 0 deletions docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"retries": 4,
"timeout": 30.0,
"verify": true,
"fallback": true,

"sleep": 0,
"sleep-request": 0,
Expand Down
7 changes: 5 additions & 2 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def __init__(self, url, parent=None):
Job.__init__(self, url, parent)
self.log = self.get_logger("download")
self.blacklist = None
self.fallback = None
self.archive = None
self.sleep = None
self.hooks = ()
Expand Down Expand Up @@ -237,8 +238,9 @@ def handle_url(self, url, kwdict):
# download from URL
if not self.download(url):

# use fallback URLs if available
for num, url in enumerate(kwdict.get("_fallback", ()), 1):
# use fallback URLs if available/enabled
fallback = kwdict.get("_fallback", ()) if self.fallback else ()
for num, url in enumerate(fallback, 1):
util.remove_file(pathfmt.temppath)
self.log.info("Trying fallback URL #%d", num)
if self.download(url):
Expand Down Expand Up @@ -394,6 +396,7 @@ def initialize(self, kwdict=None):
pathfmt.set_directory(kwdict)

self.sleep = cfg("sleep")
self.fallback = cfg("fallback", True)
if not cfg("download", True):
# monkey-patch method to do nothing and always return True
self.download = pathfmt.fix_extension
Expand Down

0 comments on commit d320ee6

Please sign in to comment.