From 5818c928c4125fd33c67d0cd174b1b828a97318c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 9 Jan 2021 02:33:42 +0100 Subject: [PATCH] refactor 'path-restrict' parsing --- gallery_dl/util.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 879af891..1733e093 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -726,6 +726,11 @@ class PathFormat(): "jif" : "jpg", "jfi" : "jpg", } + RESTRICT_MAP = { + "auto" : "\\\\|/<>:\"?*" if WINDOWS else "/", + "unix" : "/", + "windows": "\\\\|/<>:\"?*", + } def __init__(self, extractor): filename_fmt = extractor.config("filename", extractor.filename_fmt) @@ -769,13 +774,7 @@ class PathFormat(): restrict = extractor.config("path-restrict", "auto") replace = extractor.config("path-replace", "_") - - if restrict == "auto": - restrict = "\\\\|/<>:\"?*" if WINDOWS else "/" - elif restrict == "unix": - restrict = "/" - elif restrict == "windows": - restrict = "\\\\|/<>:\"?*" + restrict = self.RESTRICT_MAP.get(restrict, restrict) self.clean_segment = self._build_cleanfunc(restrict, replace) remove = extractor.config("path-remove", "\x00-\x1f\x7f")