emit log messages on download failure

and when retrying with fallback URLs
This commit is contained in:
Mike Fährmann
2018-01-28 18:44:10 +01:00
parent d951f13e37
commit db7f04dd97
2 changed files with 15 additions and 5 deletions

View File

@@ -155,14 +155,20 @@ class DownloadJob(Job):
def handle_url(self, url, keywords): def handle_url(self, url, keywords):
"""Download the resource specified in 'url'""" """Download the resource specified in 'url'"""
if self._prepare_download(keywords): 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): def handle_urllist(self, urls, keywords):
"""Download the resource specified in 'url'""" """Download the resource specified in 'url'"""
if self._prepare_download(keywords): if self._prepare_download(keywords):
for url in urls: for num, url in enumerate(urls):
if self.get_downloader(url).download(url, self.pathfmt): dlobj = self.get_downloader(url)
if num:
dlobj.log.info("Trying fallback URL #%d", num)
if dlobj.download(url, self.pathfmt):
return return
self._report_failure(dlobj)
def handle_directory(self, keywords): def handle_directory(self, keywords):
"""Set and create the target directory for downloads""" """Set and create the target directory for downloads"""
@@ -199,6 +205,9 @@ class DownloadJob(Job):
time.sleep(self.sleep) time.sleep(self.sleep)
return True return True
def _report_failure(self, dlobj):
dlobj.log.error("Failed to download %s", self.pathfmt.filename)
class KeywordJob(Job): class KeywordJob(Job):
"""Print available keywords""" """Print available keywords"""

View File

@@ -352,6 +352,7 @@ class PathFormat():
self.has_extension = False self.has_extension = False
self.keywords = {} self.keywords = {}
self.filename = ""
self.directory = self.realdirectory = "" self.directory = self.realdirectory = ""
self.path = self.realpath = self.partpath = "" self.path = self.realpath = self.partpath = ""
@@ -419,12 +420,12 @@ class PathFormat():
def build_path(self): def build_path(self):
"""Use filename-keywords and directory to build a full path""" """Use filename-keywords and directory to build a full path"""
try: try:
filename = text.clean_path( self.filename = text.clean_path(
self.formatter.vformat(self.filename_fmt, self.keywords)) self.formatter.vformat(self.filename_fmt, self.keywords))
except Exception as exc: except Exception as exc:
raise exception.FormatError(exc, "filename") raise exception.FormatError(exc, "filename")
filename = os.sep + filename filename = os.sep + self.filename
self.path = self.directory + filename self.path = self.directory + filename
self.realpath = self.realdirectory + filename self.realpath = self.realdirectory + filename