diff options
Diffstat (limited to 'gallery_dl/postprocessor/metadata.py')
| -rw-r--r-- | gallery_dl/postprocessor/metadata.py | 22 |
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 |
