diff options
| author | 2019-12-25 19:40:28 -0500 | |
|---|---|---|
| committer | 2019-12-25 19:40:28 -0500 | |
| commit | f9a1a9dcb7df977eeac9544786df9c0b93795815 (patch) | |
| tree | 8cb69cf7685da8d7e4deb7dc1d6b209098e1ddfb /gallery_dl/postprocessor | |
| parent | 0c73e982fa596da07f23b377621ab894a9e64884 (diff) | |
New upstream version 1.12.1upstream/1.12.1
Diffstat (limited to 'gallery_dl/postprocessor')
| -rw-r--r-- | gallery_dl/postprocessor/common.py | 4 | ||||
| -rw-r--r-- | gallery_dl/postprocessor/metadata.py | 38 |
2 files changed, 33 insertions, 9 deletions
diff --git a/gallery_dl/postprocessor/common.py b/gallery_dl/postprocessor/common.py index 83b42eb..70b0dfb 100644 --- a/gallery_dl/postprocessor/common.py +++ b/gallery_dl/postprocessor/common.py @@ -27,6 +27,10 @@ class PostProcessor(): """Execute the postprocessor for a file""" @staticmethod + def run_metadata(pathfmt): + """Execute the postprocessor for a file""" + + @staticmethod def run_after(pathfmt): """Execute postprocessor after moving a file to its target location""" diff --git a/gallery_dl/postprocessor/metadata.py b/gallery_dl/postprocessor/metadata.py index 467ef11..bc26484 100644 --- a/gallery_dl/postprocessor/metadata.py +++ b/gallery_dl/postprocessor/metadata.py @@ -18,29 +18,49 @@ class MetadataPP(PostProcessor): PostProcessor.__init__(self) mode = options.get("mode", "json") - ext = "txt" - if mode == "custom": self.write = self._write_custom - self.formatter = util.Formatter(options.get("format")) + cfmt = options.get("content-format") or options.get("format") + self.contentfmt = util.Formatter(cfmt).format_map + ext = "txt" elif mode == "tags": self.write = self._write_tags + ext = "txt" else: self.write = self._write_json self.indent = options.get("indent", 4) self.ascii = options.get("ascii", False) ext = "json" - self.extension = options.get("extension", ext) + extfmt = options.get("extension-format") + if extfmt: + self.path = self._path_format + self.extfmt = util.Formatter(extfmt).format_map + else: + self.path = self._path_append + self.extension = options.get("extension", ext) + + if options.get("bypost"): + self.run_metadata, self.run = self.run, self.run_metadata def run(self, pathfmt): - path = "{}.{}".format(pathfmt.realpath, self.extension) - with open(path, "w", encoding="utf-8") as file: + with open(self.path(pathfmt), "w", encoding="utf-8") as file: self.write(file, pathfmt.kwdict) + def _path_append(self, pathfmt): + return "{}.{}".format(pathfmt.realpath, self.extension) + + def _path_format(self, pathfmt): + kwdict = pathfmt.kwdict + ext = kwdict["extension"] + kwdict["extension"] = pathfmt.extension + kwdict["extension"] = pathfmt.prefix + self.extfmt(kwdict) + path = pathfmt.realdirectory + pathfmt.build_filename() + kwdict["extension"] = ext + return path + def _write_custom(self, file, kwdict): - output = self.formatter.format_map(kwdict) - file.write(output) + file.write(self.contentfmt(kwdict)) def _write_tags(self, file, kwdict): tags = kwdict.get("tags") or kwdict.get("tag_string") @@ -58,7 +78,7 @@ class MetadataPP(PostProcessor): file.write("\n") def _write_json(self, file, kwdict): - util.dump_json(kwdict, file, self.ascii, self.indent) + util.dump_json(util.filter_dict(kwdict), file, self.ascii, self.indent) __postprocessor__ = MetadataPP |
