Skip to content

Commit

Permalink
[postprocessor:classify] improve path generation (fixes #138)
Browse files Browse the repository at this point in the history
It still doesn't work for converted ugoira animations thanks to how
those files are handled, but everything else, including files with
unknown or changing file extension, now works as it should.
  • Loading branch information
mikf committed Aug 19, 2019
1 parent e77a656 commit 2495b99
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions gallery_dl/postprocessor/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,24 @@ def __init__(self, pathfmt, options):

def prepare(self, pathfmt):
ext = pathfmt.extension

if ext in self.mapping:
self._dir = pathfmt.realdirectory + os.sep + self.mapping[ext]
pathfmt.realpath = self._dir + os.sep + pathfmt.filename
else:
self._dir = None
# set initial paths to enable download skips
self._build_paths(pathfmt, self.mapping[ext])

def run(self, pathfmt):
if self._dir:
os.makedirs(self._dir, exist_ok=True)
ext = pathfmt.extension
if ext in self.mapping:
# rebuild paths in case the filename extension changed
path = self._build_paths(pathfmt, self.mapping[ext])
os.makedirs(path, exist_ok=True)

@staticmethod
def _build_paths(pathfmt, extra):
path = pathfmt.realdirectory + os.sep + extra
pathfmt.realpath = path + os.sep + pathfmt.filename
pathfmt.path = (pathfmt.directory + os.sep +
extra + os.sep + pathfmt.filename)
return path


__postprocessor__ = ClassifyPP

0 comments on commit 2495b99

Please sign in to comment.