summaryrefslogtreecommitdiffstats
path: root/gallery_dl/postprocessor/zip.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/postprocessor/zip.py')
-rw-r--r--gallery_dl/postprocessor/zip.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/gallery_dl/postprocessor/zip.py b/gallery_dl/postprocessor/zip.py
index ff97add..4f376fe 100644
--- a/gallery_dl/postprocessor/zip.py
+++ b/gallery_dl/postprocessor/zip.py
@@ -26,6 +26,7 @@ class ZipPP(PostProcessor):
def __init__(self, job, options):
PostProcessor.__init__(self, job)
self.delete = not options.get("keep-files", False)
+ self.files = options.get("files")
ext = "." + options.get("extension", "zip")
algorithm = options.get("compression", "store")
if algorithm not in self.COMPRESSION_ALGORITHMS:
@@ -56,6 +57,9 @@ class ZipPP(PostProcessor):
# 'NameToInfo' is not officially documented, but it's available
# for all supported Python versions and using it directly is a lot
# faster than calling getinfo()
+ if self.files:
+ self.write_extra(pathfmt, zfile, self.files)
+ self.files = None
if pathfmt.filename not in zfile.NameToInfo:
zfile.write(pathfmt.temppath, pathfmt.filename)
pathfmt.delete = self.delete
@@ -69,6 +73,21 @@ class ZipPP(PostProcessor):
with self.open() as zfile:
self.write(pathfmt, zfile)
+ def write_extra(self, pathfmt, zfile, files):
+ for path in map(util.expand_path, files):
+ if not os.path.isabs(path):
+ path = os.path.join(pathfmt.realdirectory, path)
+ try:
+ zfile.write(path, os.path.basename(path))
+ except OSError as exc:
+ self.log.warning(
+ "Unable to write %s to %s", path, zfile.filename)
+ self.log.debug("%s: %s", exc, exc.__class__.__name__)
+ pass
+ else:
+ if self.delete:
+ util.remove_file(path)
+
def finalize(self, pathfmt, status):
if self.zfile:
self.zfile.close()