1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

add 'prepare()' step for post-processors

This allows post-processors to modify the destination path before
checking if a file already exists.
This commit is contained in:
Mike Fährmann 2018-10-18 22:32:03 +02:00
parent c9861ca812
commit d3d7f01543
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
5 changed files with 32 additions and 11 deletions

View File

@ -182,6 +182,10 @@ class DownloadJob(Job):
# prepare download
self.pathfmt.set_keywords(keywords)
if self.postprocessors:
for pp in self.postprocessors:
pp.prepare(self.pathfmt)
if self.pathfmt.exists(self.archive):
self.handle_skip()
return

View File

@ -32,13 +32,18 @@ class ClassifyPP(PostProcessor):
for ext in exts
}
def run(self, pathfmt):
def prepare(self, pathfmt):
ext = pathfmt.keywords["extension"]
if ext in self.mapping:
path = pathfmt.realdirectory + os.sep + self.mapping[ext]
pathfmt.realpath = path + os.sep + pathfmt.filename
os.makedirs(path, exist_ok=True)
self._dir = pathfmt.realdirectory + os.sep + self.mapping[ext]
pathfmt.realpath = self._dir + os.sep + pathfmt.filename
else:
self._dir = None
def run(self, pathfmt):
if self._dir:
os.makedirs(self._dir, exist_ok=True)
__postprocessor__ = ClassifyPP

View File

@ -15,6 +15,9 @@ class PostProcessor():
"""Base class for postprocessors"""
log = log
def prepare(self, pathfmt):
""" """
def run(self, pathfmt):
"""Execute the postprocessor for a file"""

View File

@ -49,18 +49,27 @@ class UgoiraPP(PostProcessor):
else:
self.prevent_odd = False
def run(self, pathfmt):
def prepare(self, pathfmt):
self._frames = None
if pathfmt.keywords["extension"] != "zip":
return
if "frames" in pathfmt.keywords:
framelist = pathfmt.keywords["frames"]
self._frames = pathfmt.keywords["frames"]
elif "pixiv_ugoira_frame_data" in pathfmt.keywords:
framelist = pathfmt.keywords["pixiv_ugoira_frame_data"]["data"]
self._frames = pathfmt.keywords["pixiv_ugoira_frame_data"]["data"]
else:
return
rate_in, rate_out = self.calculate_framerate(framelist)
if self.delete:
pathfmt.set_extension(self.extension)
def run(self, pathfmt):
if not self._frames:
return
rate_in, rate_out = self.calculate_framerate(self._frames)
with tempfile.TemporaryDirectory() as tempdir:
# extract frames
@ -71,13 +80,13 @@ class UgoiraPP(PostProcessor):
ffconcat = tempdir + "/ffconcat.txt"
with open(ffconcat, "w") as file:
file.write("ffconcat version 1.0\n")
for frame in framelist:
for frame in self._frames:
file.write("file '{}'\n".format(frame["file"]))
file.write("duration {}\n".format(frame["delay"] / 1000))
if self.extension != "gif":
# repeat the last frame to prevent it from only being
# displayed for a very short amount of time
file.write("file '{}'\n".format(framelist[-1]["file"]))
file.write("file '{}'\n".format(self._frames[-1]["file"]))
# collect command-line arguments
args = [self.ffmpeg]

View File

@ -524,7 +524,7 @@ class PathFormat():
def part_enable(self, part_directory=None):
"""Enable .part file usage"""
if self.has_extension:
self.temppath = self.realpath + ".part"
self.temppath += ".part"
else:
self.set_extension("part", False)
if part_directory: