[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
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
-------------
@ -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

@ -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

@ -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)

Loading…
Cancel
Save