Skip to content

Commit

Permalink
emit log messages on download failure
Browse files Browse the repository at this point in the history
and when retrying with fallback URLs
  • Loading branch information
mikf committed Jan 28, 2018
1 parent d951f13 commit db7f04d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 12 additions & 3 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,20 @@ def __init__(self, url, parent=None):
def handle_url(self, url, keywords):
"""Download the resource specified in 'url'"""
if self._prepare_download(keywords):
self.get_downloader(url).download(url, self.pathfmt)
dlobj = self.get_downloader(url)
if not dlobj.download(url, self.pathfmt):
self._report_failure(dlobj)

def handle_urllist(self, urls, keywords):
"""Download the resource specified in 'url'"""
if self._prepare_download(keywords):
for url in urls:
if self.get_downloader(url).download(url, self.pathfmt):
for num, url in enumerate(urls):
dlobj = self.get_downloader(url)
if num:
dlobj.log.info("Trying fallback URL #%d", num)
if dlobj.download(url, self.pathfmt):
return
self._report_failure(dlobj)

def handle_directory(self, keywords):
"""Set and create the target directory for downloads"""
Expand Down Expand Up @@ -199,6 +205,9 @@ def _prepare_download(self, keywords):
time.sleep(self.sleep)
return True

def _report_failure(self, dlobj):
dlobj.log.error("Failed to download %s", self.pathfmt.filename)


class KeywordJob(Job):
"""Print available keywords"""
Expand Down
5 changes: 3 additions & 2 deletions gallery_dl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def __init__(self, extractor):

self.has_extension = False
self.keywords = {}
self.filename = ""
self.directory = self.realdirectory = ""
self.path = self.realpath = self.partpath = ""

Expand Down Expand Up @@ -419,12 +420,12 @@ def adjust_extension(self, extension):
def build_path(self):
"""Use filename-keywords and directory to build a full path"""
try:
filename = text.clean_path(
self.filename = text.clean_path(
self.formatter.vformat(self.filename_fmt, self.keywords))
except Exception as exc:
raise exception.FormatError(exc, "filename")

filename = os.sep + filename
filename = os.sep + self.filename
self.path = self.directory + filename
self.realpath = self.realdirectory + filename

Expand Down

0 comments on commit db7f04d

Please sign in to comment.