update PathFormat class
- change 'has_extension' from a simple flag/bool to a field that contains the original filename extension - rename 'keywords' to 'kwdict' and some other stuff as well - inline 'adjust_path()' - put enumeration index before filename extension (#306)
This commit is contained in:
@@ -33,7 +33,7 @@ class ClassifyPP(PostProcessor):
|
||||
}
|
||||
|
||||
def prepare(self, pathfmt):
|
||||
ext = pathfmt.keywords.get("extension")
|
||||
ext = pathfmt.extension
|
||||
|
||||
if ext in self.mapping:
|
||||
self._dir = pathfmt.realdirectory + os.sep + self.mapping[ext]
|
||||
|
||||
@@ -36,15 +36,14 @@ class MetadataPP(PostProcessor):
|
||||
def run(self, pathfmt):
|
||||
path = "{}.{}".format(pathfmt.realpath, self.extension)
|
||||
with open(path, "w", encoding="utf-8") as file:
|
||||
self.write(file, pathfmt)
|
||||
self.write(file, pathfmt.kwdict)
|
||||
|
||||
def _write_custom(self, file, pathfmt):
|
||||
output = self.formatter.format_map(pathfmt.keywords)
|
||||
def _write_custom(self, file, kwdict):
|
||||
output = self.formatter.format_map(kwdict)
|
||||
file.write(output)
|
||||
|
||||
def _write_tags(self, file, pathfmt):
|
||||
kwds = pathfmt.keywords
|
||||
tags = kwds.get("tags") or kwds.get("tag_string")
|
||||
def _write_tags(self, file, kwdict):
|
||||
tags = kwdict.get("tags") or kwdict.get("tag_string")
|
||||
|
||||
if not tags:
|
||||
return
|
||||
@@ -58,8 +57,8 @@ class MetadataPP(PostProcessor):
|
||||
file.write("\n".join(tags))
|
||||
file.write("\n")
|
||||
|
||||
def _write_json(self, file, pathfmt):
|
||||
util.dump_json(pathfmt.keywords, file, self.ascii, self.indent)
|
||||
def _write_json(self, file, kwdict):
|
||||
util.dump_json(kwdict, file, self.ascii, self.indent)
|
||||
|
||||
|
||||
__postprocessor__ = MetadataPP
|
||||
|
||||
@@ -19,9 +19,9 @@ class MtimePP(PostProcessor):
|
||||
self.key = options.get("key", "date")
|
||||
|
||||
def run(self, pathfmt):
|
||||
mtime = pathfmt.keywords.get(self.key)
|
||||
mtime = pathfmt.kwdict.get(self.key)
|
||||
ts = getattr(mtime, "timestamp", None)
|
||||
pathfmt.keywords["_mtime"] = ts() if ts else parse_int(mtime)
|
||||
pathfmt.kwdict["_mtime"] = ts() if ts else parse_int(mtime)
|
||||
|
||||
|
||||
__postprocessor__ = MtimePP
|
||||
|
||||
@@ -52,13 +52,13 @@ class UgoiraPP(PostProcessor):
|
||||
def prepare(self, pathfmt):
|
||||
self._frames = None
|
||||
|
||||
if pathfmt.keywords["extension"] != "zip":
|
||||
if pathfmt.extension != "zip":
|
||||
return
|
||||
|
||||
if "frames" in pathfmt.keywords:
|
||||
self._frames = pathfmt.keywords["frames"]
|
||||
elif "pixiv_ugoira_frame_data" in pathfmt.keywords:
|
||||
self._frames = pathfmt.keywords["pixiv_ugoira_frame_data"]["data"]
|
||||
if "frames" in pathfmt.kwdict:
|
||||
self._frames = pathfmt.kwdict["frames"]
|
||||
elif "pixiv_ugoira_frame_data" in pathfmt.kwdict:
|
||||
self._frames = pathfmt.kwdict["pixiv_ugoira_frame_data"]["data"]
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user