From 37d97ff02c29d249a81ac91c6033ac39bdc3eabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 6 Jun 2018 21:10:28 +0200 Subject: [PATCH] [pp:classify] use temppath --- gallery_dl/postprocessor/classify.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/gallery_dl/postprocessor/classify.py b/gallery_dl/postprocessor/classify.py index f3a09c5a..a43b2b98 100644 --- a/gallery_dl/postprocessor/classify.py +++ b/gallery_dl/postprocessor/classify.py @@ -6,7 +6,7 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. -"""Categorize files by media type""" +"""Categorize files by file extension""" from .common import PostProcessor import os @@ -24,9 +24,9 @@ class ClassifyPP(PostProcessor): def __init__(self, options): PostProcessor.__init__(self) - mapping = options.get("map", self.DEFAULT_MAP) + mapping = options.get("mapping", self.DEFAULT_MAP) - self.map = { + self.mapping = { ext: directory for directory, exts in mapping.items() for ext in exts @@ -35,17 +35,10 @@ class ClassifyPP(PostProcessor): def run(self, pathfmt): ext = pathfmt.keywords["extension"] - if ext in self.map: - directory = self.map[ext] - path = os.path.join(pathfmt.realdirectory, directory) - try: - os.mkdir(path) - except FileExistsError: - pass - os.replace( - pathfmt.realpath, - os.path.join(path, pathfmt.filename) - ) + if ext in self.mapping: + path = pathfmt.realdirectory + os.sep + self.mapping[ext] + pathfmt.realpath = path + os.sep + pathfmt.filename + os.makedirs(path, exist_ok=True) __postprocessor__ = ClassifyPP