summaryrefslogtreecommitdiffstats
path: root/gallery_dl/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/util.py')
-rw-r--r--gallery_dl/util.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/gallery_dl/util.py b/gallery_dl/util.py
index 2c0fae6..935bf99 100644
--- a/gallery_dl/util.py
+++ b/gallery_dl/util.py
@@ -547,6 +547,7 @@ class Formatter():
- "u": calls str.upper
- "c": calls str.capitalize
- "C": calls string.capwords
+ - "j". calls json.dumps
- "t": calls str.strip
- "d": calls text.parse_timestamp
- "U": calls urllib.parse.unquote
@@ -581,6 +582,7 @@ class Formatter():
"u": str.upper,
"c": str.capitalize,
"C": string.capwords,
+ "j": json.dumps,
"t": str.strip,
"T": to_timestamp,
"d": text.parse_timestamp,
@@ -849,6 +851,15 @@ class PathFormat():
remove = config("path-remove", "\x00-\x1f\x7f")
self.clean_path = self._build_cleanfunc(remove, "")
+ strip = config("path-strip", "auto")
+ if strip == "auto":
+ strip = ". " if WINDOWS else ""
+ elif strip == "unix":
+ strip = ""
+ elif strip == "windows":
+ strip = ". "
+ self.strip = strip
+
basedir = extractor._parentdir
if not basedir:
basedir = config("base-directory")
@@ -982,13 +993,14 @@ class PathFormat():
"""Apply 'kwdict' to directory format strings"""
segments = []
append = segments.append
+ strip = self.strip
try:
for formatter in self.directory_formatters:
segment = formatter(kwdict).strip()
- if WINDOWS:
+ if strip:
# remove trailing dots and spaces (#647)
- segment = segment.rstrip(". ")
+ segment = segment.rstrip(strip)
if segment:
append(self.clean_segment(segment))
return segments
@@ -998,6 +1010,7 @@ class PathFormat():
def build_directory_conditional(self, kwdict):
segments = []
append = segments.append
+ strip = self.strip
try:
for condition, formatters in self.directory_conditions:
@@ -1007,8 +1020,8 @@ class PathFormat():
formatters = self.directory_formatters
for formatter in formatters:
segment = formatter(kwdict).strip()
- if WINDOWS:
- segment = segment.rstrip(". ")
+ if strip:
+ segment = segment.rstrip(strip)
if segment:
append(self.clean_segment(segment))
return segments