Skip to content

Commit

Permalink
improve attribute access in DownloadJob.handle_url()
Browse files Browse the repository at this point in the history
Storing a value in a local variable an accessing it that way is faster
than going through 'self' if it is accessed more than once.
  • Loading branch information
mikf committed Jul 13, 2019
1 parent 56c7a66 commit fe7805d
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,18 @@ def __init__(self, url, parent=None):

def handle_url(self, url, keywords, fallback=None):
"""Download the resource specified in 'url'"""
postprocessors = self.postprocessors
pathfmt = self.pathfmt
archive = self.archive

# prepare download
self.pathfmt.set_keywords(keywords)
pathfmt.set_keywords(keywords)

if self.postprocessors:
for pp in self.postprocessors:
pp.prepare(self.pathfmt)
if postprocessors:
for pp in postprocessors:
pp.prepare(pathfmt)

if self.pathfmt.exists(self.archive):
if pathfmt.exists(archive):
self.handle_skip()
return

Expand All @@ -214,24 +218,24 @@ def handle_url(self, url, keywords, fallback=None):
break
else:
# download failed
self.log.error(
"Failed to download %s", self.pathfmt.filename or url)
self.log.error("Failed to download %s",
pathfmt.filename or url)
return

if not self.pathfmt.temppath:
if not pathfmt.temppath:
self.handle_skip()
return

# run post processors
if self.postprocessors:
for pp in self.postprocessors:
pp.run(self.pathfmt)
if postprocessors:
for pp in postprocessors:
pp.run(pathfmt)

# download succeeded
self.pathfmt.finalize()
self.out.success(self.pathfmt.path, 0)
if self.archive:
self.archive.add(keywords)
pathfmt.finalize()
self.out.success(pathfmt.path, 0)
if archive:
archive.add(keywords)
self._skipcnt = 0

def handle_urllist(self, urls, keywords):
Expand Down

0 comments on commit fe7805d

Please sign in to comment.