Skip to content

Commit

Permalink
do not create directory structures when using '-s'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Sep 21, 2018
1 parent e066f35 commit 8c8da11
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,38 @@ def handle_urllist(self, urls, keywords):

def handle_directory(self, keywords):
"""Set and create the target directory for downloads"""
if self.pathfmt:
self.pathfmt.set_directory(keywords)
return
if not self.pathfmt:
self.initialize()
self.pathfmt.set_directory(keywords)

def handle_queue(self, url, keywords):
try:
self.__class__(url, self).run()
except exception.NoExtractorError:
self._write_unsupported(url)

def handle_finalize(self):
if self.postprocessors:
for pp in self.postprocessors:
pp.finalize()

def get_downloader(self, url):
"""Return, and possibly construct, a downloader suitable for 'url'"""
scheme = url.partition(":")[0]
if scheme == "https":
scheme = "http"
try:
return self.downloaders[scheme]
except KeyError:
pass
klass = downloader.find(scheme)
instance = klass(self.extractor.session, self.out)
self.downloaders[scheme] = instance
return instance

# delayed initialization
def initialize(self):
"""Delayed initialization of PathFormat, etc."""
self.pathfmt = util.PathFormat(self.extractor)
self.pathfmt.set_directory(keywords)
self.sleep = self.extractor.config("sleep")

archive = self.extractor.config("archive")
Expand Down Expand Up @@ -254,31 +279,6 @@ def handle_directory(self, keywords):
self.extractor.log.debug(
"Active postprocessor modules: %s", self.postprocessors)

def handle_queue(self, url, keywords):
try:
self.__class__(url, self).run()
except exception.NoExtractorError:
self._write_unsupported(url)

def handle_finalize(self):
if self.postprocessors:
for pp in self.postprocessors:
pp.finalize()

def get_downloader(self, url):
"""Return, and possibly construct, a downloader suitable for 'url'"""
scheme = url.partition(":")[0]
if scheme == "https":
scheme = "http"
try:
return self.downloaders[scheme]
except KeyError:
pass
klass = downloader.find(scheme)
instance = klass(self.extractor.session, self.out)
self.downloaders[scheme] = instance
return instance


class SimulationJob(DownloadJob):
"""Simulate the extraction process without downloading anything"""
Expand All @@ -291,6 +291,10 @@ def handle_url(self, url, keywords, fallback=None):
if self.archive:
self.archive.add(keywords)

def handle_directory(self, keywords):
if not self.pathfmt:
self.initialize()


class KeywordJob(Job):
"""Print available keywords"""
Expand Down

0 comments on commit 8c8da11

Please sign in to comment.