mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 18:53:21 +01:00
[pp:zip] use temppath; add options
This commit is contained in:
parent
821535b458
commit
97189e50cd
@ -6,7 +6,7 @@
|
||||
# it under the terms of the GNU General Public License version 2 as
|
||||
# published by the Free Software Foundation.
|
||||
|
||||
"""Add files to ZIP archive"""
|
||||
"""Add files to ZIP archives"""
|
||||
|
||||
from .common import PostProcessor
|
||||
import zipfile
|
||||
@ -14,12 +14,26 @@ import zipfile
|
||||
|
||||
class ZipPP(PostProcessor):
|
||||
|
||||
COMPRESSION_ALGORITHMS = {
|
||||
"store": zipfile.ZIP_STORED,
|
||||
"zip": zipfile.ZIP_DEFLATED,
|
||||
"bzip2": zipfile.ZIP_BZIP2,
|
||||
"lzma": zipfile.ZIP_LZMA,
|
||||
}
|
||||
|
||||
def __init__(self, options):
|
||||
PostProcessor.__init__(self)
|
||||
self.ext = "." + options.get("extension", "zip")
|
||||
|
||||
algorithm = options.get("compression", "store")
|
||||
if algorithm not in self.COMPRESSION_ALGORITHMS:
|
||||
algorithm = "store"
|
||||
self.compression = self.COMPRESSION_ALGORITHMS[algorithm]
|
||||
|
||||
def run(self, pathfmt):
|
||||
with zipfile.ZipFile(pathfmt.realdirectory + ".zip", "a") as zfile:
|
||||
zfile.write(pathfmt.realpath, pathfmt.filename)
|
||||
archive = pathfmt.realdirectory + self.ext
|
||||
with zipfile.ZipFile(archive, "a", self.compression, True) as zfile:
|
||||
zfile.write(pathfmt.temppath, pathfmt.filename)
|
||||
|
||||
|
||||
__postprocessor__ = ZipPP
|
||||
|
Loading…
Reference in New Issue
Block a user