From 07bd967f59e87881187655dad61cf10b29555fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 5 Sep 2024 18:43:06 +0200 Subject: [PATCH] [pp:ugoira] update (#6056) - introduce '_ugoira_frame_index' metadata field - store Ugoira file exts separately - add 'skip' option --- docs/configuration.rst | 33 ++++++++++++++++++++++++++++++ gallery_dl/extractor/pixiv.py | 2 +- gallery_dl/postprocessor/ugoira.py | 30 +++++++++++++++++---------- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index dc6df5f1..3fefc911 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -5643,6 +5643,28 @@ Example Description Hash digests to compute. + For a list of available hash algorithms, run + + .. code:: + + python -c "import hashlib; print('\n'.join(hashlib.algorithms_available))" + + or see `python/hashlib `__. + + * If this is a ``string``, + it is parsed as a a comma-separated list of algorthm-fieldname pairs: + + .. code:: + + [ ":"] ["," ...] + + When ```` is omitted, + ```` is used as algorithm name. + + * If this is an ``object``, + it is a ```` to ```` mapping + for hash digests to compute. + metadata.mode ------------- @@ -6259,6 +6281,16 @@ Description to prevent it from only being displayed for a very short amount of time. +ugoira.skip +----------- +Type + ``bool`` +Default + ``true`` +Description + Do not convert frames if target file already exists. + + zip.compression --------------- Type @@ -6270,6 +6302,7 @@ Description Possible values are ``"store"``, ``"zip"``, ``"bzip2"``, ``"lzma"``. + zip.extension ------------- Type diff --git a/gallery_dl/extractor/pixiv.py b/gallery_dl/extractor/pixiv.py index eda0405c..3479b88f 100644 --- a/gallery_dl/extractor/pixiv.py +++ b/gallery_dl/extractor/pixiv.py @@ -119,7 +119,7 @@ class PixivExtractor(Extractor): for num, frame in enumerate(frames): url = ("{}{}.{}".format(base, num, ext)) - work["num"] = num + work["num"] = work["_ugoira_frame_index"] = num work["suffix"] = "_p{:02}".format(num) text.nameext_from_url(url, work) yield Message.Url, url, work diff --git a/gallery_dl/postprocessor/ugoira.py b/gallery_dl/postprocessor/ugoira.py index 0ab58b2a..f053afa0 100644 --- a/gallery_dl/postprocessor/ugoira.py +++ b/gallery_dl/postprocessor/ugoira.py @@ -36,6 +36,7 @@ class UgoiraPP(PostProcessor): self.delete = not options.get("keep-files", False) self.repeat = options.get("repeat-last-frame", True) self.mtime = options.get("mtime", True) + self.skip = options.get("skip", True) self.uniform = self._convert_zip = self._convert_files = False ffmpeg = options.get("ffmpeg-location") @@ -109,12 +110,17 @@ class UgoiraPP(PostProcessor): pathfmt.build_path() else: pathfmt.build_path() - num = pathfmt.kwdict["num"] - if not num: - self._files = [pathfmt.realpath] + index = pathfmt.kwdict["_ugoira_frame_index"] + frame = self._frames[index].copy() + frame["index"] = index + frame["path"] = pathfmt.realpath + frame["ext"] = pathfmt.kwdict["extension"] + + if not index: + self._files = [frame] else: - self._files.append(pathfmt.realpath) - if num+1 >= len(self._frames): + self._files.append(frame) + if len(self._files) >= len(self._frames): self._convert_files = True def convert_zip(self, pathfmt): @@ -144,32 +150,34 @@ class UgoiraPP(PostProcessor): self._convert_files = False with tempfile.TemporaryDirectory() as tempdir: - for frame, path in zip(self._frames, self._files): + for frame in self._files: # update frame filename extension frame["file"] = name = "{}.{}".format( - frame["file"].partition(".")[0], - path.rpartition(".")[2]) + frame["file"].partition(".")[0], frame["ext"]) # move frame into tempdir try: - self._copy_file(path, tempdir + "/" + name) + self._copy_file(frame["path"], tempdir + "/" + name) except OSError as exc: self.log.debug("Unable to copy frame %s (%s: %s)", name, exc.__class__.__name__, exc) return pathfmt.kwdict["num"] = 0 + self._frames = self._files if self.convert(pathfmt, tempdir): self.log.info(pathfmt.filename) if self.delete: self.log.debug("Deleting frames") - for path in self._files: - util.remove_file(path) + for frame in self._files: + util.remove_file(frame["path"]) def convert(self, pathfmt, tempdir): pathfmt.set_extension(self.extension) pathfmt.build_path() + if self.skip and pathfmt.exists(): + return True # process frames and collect command-line arguments args = self._process(pathfmt, tempdir)