[pp:ugoira] update (#6056)

- introduce '_ugoira_frame_index' metadata field
- store Ugoira file exts separately
- add 'skip' option
pull/5071/merge
Mike Fährmann 2 weeks ago
parent 32d2e686c2
commit 07bd967f59
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -5643,6 +5643,28 @@ Example
Description Description
Hash digests to compute. 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 <https://docs.python.org/3/library/hashlib.html>`__.
* If this is a ``string``,
it is parsed as a a comma-separated list of algorthm-fieldname pairs:
.. code::
[<hash algorithm> ":"] <field name> ["," ...]
When ``<hash algorithm>`` is omitted,
``<field name>`` is used as algorithm name.
* If this is an ``object``,
it is a ``<field name>`` to ``<algorithm name>`` mapping
for hash digests to compute.
metadata.mode metadata.mode
------------- -------------
@ -6259,6 +6281,16 @@ Description
to prevent it from only being displayed for a very short amount of time. 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 zip.compression
--------------- ---------------
Type Type
@ -6270,6 +6302,7 @@ Description
Possible values are ``"store"``, ``"zip"``, ``"bzip2"``, ``"lzma"``. Possible values are ``"store"``, ``"zip"``, ``"bzip2"``, ``"lzma"``.
zip.extension zip.extension
------------- -------------
Type Type

@ -119,7 +119,7 @@ class PixivExtractor(Extractor):
for num, frame in enumerate(frames): for num, frame in enumerate(frames):
url = ("{}{}.{}".format(base, num, ext)) url = ("{}{}.{}".format(base, num, ext))
work["num"] = num work["num"] = work["_ugoira_frame_index"] = num
work["suffix"] = "_p{:02}".format(num) work["suffix"] = "_p{:02}".format(num)
text.nameext_from_url(url, work) text.nameext_from_url(url, work)
yield Message.Url, url, work yield Message.Url, url, work

@ -36,6 +36,7 @@ class UgoiraPP(PostProcessor):
self.delete = not options.get("keep-files", False) self.delete = not options.get("keep-files", False)
self.repeat = options.get("repeat-last-frame", True) self.repeat = options.get("repeat-last-frame", True)
self.mtime = options.get("mtime", True) self.mtime = options.get("mtime", True)
self.skip = options.get("skip", True)
self.uniform = self._convert_zip = self._convert_files = False self.uniform = self._convert_zip = self._convert_files = False
ffmpeg = options.get("ffmpeg-location") ffmpeg = options.get("ffmpeg-location")
@ -109,12 +110,17 @@ class UgoiraPP(PostProcessor):
pathfmt.build_path() pathfmt.build_path()
else: else:
pathfmt.build_path() pathfmt.build_path()
num = pathfmt.kwdict["num"] index = pathfmt.kwdict["_ugoira_frame_index"]
if not num: frame = self._frames[index].copy()
self._files = [pathfmt.realpath] frame["index"] = index
frame["path"] = pathfmt.realpath
frame["ext"] = pathfmt.kwdict["extension"]
if not index:
self._files = [frame]
else: else:
self._files.append(pathfmt.realpath) self._files.append(frame)
if num+1 >= len(self._frames): if len(self._files) >= len(self._frames):
self._convert_files = True self._convert_files = True
def convert_zip(self, pathfmt): def convert_zip(self, pathfmt):
@ -144,32 +150,34 @@ class UgoiraPP(PostProcessor):
self._convert_files = False self._convert_files = False
with tempfile.TemporaryDirectory() as tempdir: with tempfile.TemporaryDirectory() as tempdir:
for frame, path in zip(self._frames, self._files): for frame in self._files:
# update frame filename extension # update frame filename extension
frame["file"] = name = "{}.{}".format( frame["file"] = name = "{}.{}".format(
frame["file"].partition(".")[0], frame["file"].partition(".")[0], frame["ext"])
path.rpartition(".")[2])
# move frame into tempdir # move frame into tempdir
try: try:
self._copy_file(path, tempdir + "/" + name) self._copy_file(frame["path"], tempdir + "/" + name)
except OSError as exc: except OSError as exc:
self.log.debug("Unable to copy frame %s (%s: %s)", self.log.debug("Unable to copy frame %s (%s: %s)",
name, exc.__class__.__name__, exc) name, exc.__class__.__name__, exc)
return return
pathfmt.kwdict["num"] = 0 pathfmt.kwdict["num"] = 0
self._frames = self._files
if self.convert(pathfmt, tempdir): if self.convert(pathfmt, tempdir):
self.log.info(pathfmt.filename) self.log.info(pathfmt.filename)
if self.delete: if self.delete:
self.log.debug("Deleting frames") self.log.debug("Deleting frames")
for path in self._files: for frame in self._files:
util.remove_file(path) util.remove_file(frame["path"])
def convert(self, pathfmt, tempdir): def convert(self, pathfmt, tempdir):
pathfmt.set_extension(self.extension) pathfmt.set_extension(self.extension)
pathfmt.build_path() pathfmt.build_path()
if self.skip and pathfmt.exists():
return True
# process frames and collect command-line arguments # process frames and collect command-line arguments
args = self._process(pathfmt, tempdir) args = self._process(pathfmt, tempdir)

Loading…
Cancel
Save