summaryrefslogtreecommitdiffstats
path: root/gallery_dl/postprocessor/metadata.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2022-11-22 04:28:38 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2022-11-22 04:28:38 -0500
commit7af5cc29d1c02d20a6890b7b7ba78ab41532a763 (patch)
tree4f0366e5653074c7eb31ac7ca59a1ee55f2d736e /gallery_dl/postprocessor/metadata.py
parente59d46ecda74190381b1d2725b0bd9df5c0be8d8 (diff)
New upstream version 1.24.0.upstream/1.24.0
Diffstat (limited to 'gallery_dl/postprocessor/metadata.py')
-rw-r--r--gallery_dl/postprocessor/metadata.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/gallery_dl/postprocessor/metadata.py b/gallery_dl/postprocessor/metadata.py
index b21e483..2ee1cf8 100644
--- a/gallery_dl/postprocessor/metadata.py
+++ b/gallery_dl/postprocessor/metadata.py
@@ -21,6 +21,9 @@ class MetadataPP(PostProcessor):
mode = options.get("mode")
cfmt = options.get("content-format") or options.get("format")
+ omode = "w"
+ filename = None
+
if mode == "tags":
self.write = self._write_tags
ext = "txt"
@@ -41,6 +44,12 @@ class MetadataPP(PostProcessor):
cfmt = "\n".join(cfmt) + "\n"
self._content_fmt = formatter.parse(cfmt).format_map
ext = "txt"
+ elif mode == "jsonl":
+ self.write = self._write_json
+ self.indent = None
+ self.ascii = options.get("ascii", False)
+ omode = "a"
+ filename = "data.jsonl"
else:
self.write = self._write_json
self.indent = options.get("indent", 4)
@@ -53,7 +62,7 @@ class MetadataPP(PostProcessor):
sep = os.sep + (os.altsep or "")
self._metadir = util.expand_path(directory).rstrip(sep) + os.sep
- filename = options.get("filename")
+ filename = options.get("filename", filename)
extfmt = options.get("extension-format")
if filename:
if filename == "-":
@@ -97,6 +106,9 @@ class MetadataPP(PostProcessor):
self.archive = None
self.mtime = options.get("mtime")
+ self.omode = options.get("open", omode)
+ self.encoding = options.get("encoding", "utf-8")
+ self.private = options.get("private", False)
def run(self, pathfmt):
archive = self.archive
@@ -107,11 +119,11 @@ class MetadataPP(PostProcessor):
path = directory + self._filename(pathfmt)
try:
- with open(path, "w", encoding="utf-8") as fp:
+ with open(path, self.omode, encoding=self.encoding) as fp:
self.write(fp, pathfmt.kwdict)
except FileNotFoundError:
os.makedirs(directory, exist_ok=True)
- with open(path, "w", encoding="utf-8") as fp:
+ with open(path, self.omode, encoding=self.encoding) as fp:
self.write(fp, pathfmt.kwdict)
if archive:
@@ -198,7 +210,9 @@ class MetadataPP(PostProcessor):
fp.write("\n".join(tags) + "\n")
def _write_json(self, fp, kwdict):
- util.dump_json(util.filter_dict(kwdict), fp, self.ascii, self.indent)
+ if not self.private:
+ kwdict = util.filter_dict(kwdict)
+ util.dump_json(kwdict, fp, self.ascii, self.indent)
__postprocessor__ = MetadataPP