1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[pixiv] rework ugoira handling

Frame information now gets attached to the ZIP file's keyword dict
instead of being written to a separate text file.
This commit is contained in:
Mike Fährmann 2018-06-18 17:25:52 +02:00
parent 017188d268
commit eb7a1f3b98
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 28 additions and 24 deletions

View File

@ -838,7 +838,7 @@ Description The command to run.
ugoira
------
Convert Pixiv ugoira to webm.
Convert Pixiv Ugoira to WebM (requires `FFmpeg <https://www.ffmpeg.org/>`__).
ugoira.extension
----------------
@ -865,6 +865,14 @@ Default ``"ffmpeg"``
Description Location of the ``ffmpeg`` (or ``avconv``) executable to use.
=========== =====
ugoira.keep-files
-----------------
=========== =====
Type ``bool``
Default ``false``
Description Controls whether to keep the ZIP archives or to delete them.
=========== =====
zip
---

View File

@ -53,16 +53,10 @@ class PixivExtractor(Extractor):
url = ugoira["zip_urls"]["medium"].replace(
"_ugoira600x600", "_ugoira1920x1080")
work["frames"] = ugoira["frames"]
work["extension"] = "zip"
yield Message.Url, url, work
framelist = "".join(
"{file} {delay}\n".format_map(frame)
for frame in ugoira["frames"]
)
work["extension"] = "txt"
yield Message.Url, "text:" + framelist, work
elif work["page_count"] == 1:
url = meta_single_page["original_image_url"]
work["extension"] = url.rpartition(".")[2]

View File

@ -9,6 +9,7 @@
"""Convert pixiv ugoira to webm"""
from .common import PostProcessor
from .. import util
import subprocess
import tempfile
import zipfile
@ -21,26 +22,25 @@ class UgoiraPP(PostProcessor):
self.extension = options.get("extension") or "webm"
self.ffmpeg = options.get("ffmpeg-location") or "ffmpeg"
self.args = options.get("ffmpeg-args")
self.delete = not options.get("keep-files", False)
def run(self, pathfmt):
if pathfmt.keywords["extension"] != "txt":
if (pathfmt.keywords["extension"] != "zip" or
"frames" not in pathfmt.keywords):
return
framelist = []
# get frames and their durations
with pathfmt.open("r") as file:
for line in file:
name, _, duration = line.partition(" ")
framelist.append((name, int(duration.rstrip())))
# add the last frame twice to prevent it from only being
framelist = [
(frame["file"], frame["delay"] / 1000)
for frame in pathfmt.keywords["frames"]
]
if self.extension != "gif":
# repeat the last frame to prevent it from only being
# displayed for a very short amount of time
framelist.append((name, int(duration.rstrip())))
framelist.append(framelist[-1])
with tempfile.TemporaryDirectory() as tempdir:
# extract frames
pathfmt.set_extension("zip")
with zipfile.ZipFile(pathfmt.realpath) as zfile:
with zipfile.ZipFile(pathfmt.temppath) as zfile:
zfile.extractall(tempdir)
# write ffconcat file
@ -49,18 +49,20 @@ class UgoiraPP(PostProcessor):
file.write("ffconcat version 1.0\n")
for name, duration in framelist:
file.write("file '{}'\n".format(name))
file.write("duration {}\n".format(duration / 1000))
file.write("duration {}\n".format(duration))
# invoke ffmpeg
pathfmt.set_extension(self.extension)
args = [self.ffmpeg, "-i", ffconcat]
args = [util.expand_path(self.ffmpeg), "-i", ffconcat]
if self.args:
args += self.args
args.append(pathfmt.realpath)
subprocess.Popen(args).wait()
# mark framelist file for deletion
pathfmt.delete = True
if self.delete:
pathfmt.delete = True
else:
pathfmt.set_extension("zip")
__postprocessor__ = UgoiraPP