improve and simplify attribute access in DownloadJob.initialize()
This commit is contained in:
@@ -338,19 +338,20 @@ class DownloadJob(Job):
|
|||||||
|
|
||||||
def initialize(self, kwdict=None):
|
def initialize(self, kwdict=None):
|
||||||
"""Delayed initialization of PathFormat, etc."""
|
"""Delayed initialization of PathFormat, etc."""
|
||||||
self.pathfmt = util.PathFormat(self.extractor)
|
config = self.extractor.config
|
||||||
|
pathfmt = self.pathfmt = util.PathFormat(self.extractor)
|
||||||
if kwdict:
|
if kwdict:
|
||||||
self.pathfmt.set_directory(kwdict)
|
pathfmt.set_directory(kwdict)
|
||||||
|
|
||||||
self.sleep = self.extractor.config("sleep")
|
self.sleep = config("sleep")
|
||||||
if not self.extractor.config("download", True):
|
if not config("download", True):
|
||||||
self.download = self.pathfmt.fix_extension
|
self.download = pathfmt.fix_extension
|
||||||
|
|
||||||
skip = self.extractor.config("skip", True)
|
skip = config("skip", True)
|
||||||
if skip:
|
if skip:
|
||||||
self._skipexc = None
|
self._skipexc = None
|
||||||
if skip == "enumerate":
|
if skip == "enumerate":
|
||||||
self.pathfmt.check_file = self.pathfmt._enum_file
|
pathfmt.check_file = pathfmt._enum_file
|
||||||
elif isinstance(skip, str):
|
elif isinstance(skip, str):
|
||||||
skip, _, smax = skip.partition(":")
|
skip, _, smax = skip.partition(":")
|
||||||
if skip == "abort":
|
if skip == "abort":
|
||||||
@@ -360,9 +361,9 @@ class DownloadJob(Job):
|
|||||||
self._skipcnt = 0
|
self._skipcnt = 0
|
||||||
self._skipmax = text.parse_int(smax)
|
self._skipmax = text.parse_int(smax)
|
||||||
else:
|
else:
|
||||||
self.pathfmt.exists = lambda x=None: False
|
pathfmt.exists = lambda x=None: False
|
||||||
|
|
||||||
archive = self.extractor.config("archive")
|
archive = config("archive")
|
||||||
if archive:
|
if archive:
|
||||||
path = util.expand_path(archive)
|
path = util.expand_path(archive)
|
||||||
try:
|
try:
|
||||||
@@ -374,15 +375,16 @@ class DownloadJob(Job):
|
|||||||
else:
|
else:
|
||||||
self.extractor.log.debug("Using download archive '%s'", path)
|
self.extractor.log.debug("Using download archive '%s'", path)
|
||||||
|
|
||||||
postprocessors = self.extractor.config("postprocessors")
|
postprocessors = config("postprocessors")
|
||||||
if postprocessors:
|
if postprocessors:
|
||||||
pp_list = []
|
pp_list = []
|
||||||
|
category = self.extractor.category
|
||||||
|
|
||||||
for pp_dict in postprocessors:
|
for pp_dict in postprocessors:
|
||||||
whitelist = pp_dict.get("whitelist")
|
whitelist = pp_dict.get("whitelist")
|
||||||
blacklist = pp_dict.get("blacklist")
|
blacklist = pp_dict.get("blacklist")
|
||||||
if (whitelist and self.extractor.category not in whitelist or
|
if (whitelist and category not in whitelist or
|
||||||
blacklist and self.extractor.category in blacklist):
|
blacklist and category in blacklist):
|
||||||
continue
|
continue
|
||||||
name = pp_dict.get("name")
|
name = pp_dict.get("name")
|
||||||
pp_cls = postprocessor.find(name)
|
pp_cls = postprocessor.find(name)
|
||||||
@@ -390,7 +392,7 @@ class DownloadJob(Job):
|
|||||||
postprocessor.log.warning("module '%s' not found", name)
|
postprocessor.log.warning("module '%s' not found", name)
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
pp_obj = pp_cls(self.pathfmt, pp_dict)
|
pp_obj = pp_cls(pathfmt, pp_dict)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
postprocessor.log.error(
|
postprocessor.log.error(
|
||||||
"'%s' initialization failed: %s: %s",
|
"'%s' initialization failed: %s: %s",
|
||||||
|
|||||||
Reference in New Issue
Block a user