aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/path.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2025-10-14 00:23:10 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2025-10-14 00:23:10 -0400
commit33f8a8a37a9cba738ef25fb99955f0730da9eb48 (patch)
treeb51fb48b160f5e5e034e6b4542e6f00703bae7ec /gallery_dl/path.py
parentbbe7fac03d881662a458e7fbf870c9d71f5257f4 (diff)
New upstream version 1.30.10.upstream/1.30.10
Diffstat (limited to 'gallery_dl/path.py')
-rw-r--r--gallery_dl/path.py43
1 files changed, 31 insertions, 12 deletions
diff --git a/gallery_dl/path.py b/gallery_dl/path.py
index 6381622..763fb55 100644
--- a/gallery_dl/path.py
+++ b/gallery_dl/path.py
@@ -118,22 +118,32 @@ class PathFormat():
if WINDOWS:
self.extended = config("path-extended", True)
+ self.basedirectory_conditions = None
basedir = extractor._parentdir
if not basedir:
basedir = config("base-directory")
- sep = os.sep
if basedir is None:
- basedir = f".{sep}gallery-dl{sep}"
+ basedir = self.clean_path(f".{os.sep}gallery-dl{os.sep}")
elif basedir:
- basedir = util.expand_path(basedir)
- altsep = os.altsep
- if altsep and altsep in basedir:
- basedir = basedir.replace(altsep, sep)
- if basedir[-1] != sep:
- basedir += sep
- basedir = self.clean_path(basedir)
+ if isinstance(basedir, dict):
+ self.basedirectory_conditions = conds = []
+ for expr, bdir in basedir.items():
+ if not expr:
+ basedir = bdir
+ continue
+ conds.append((util.compile_filter(expr),
+ self._prepare_basedirectory(bdir)))
+ basedir = self._prepare_basedirectory(basedir)
self.basedirectory = basedir
+ def _prepare_basedirectory(self, basedir):
+ basedir = util.expand_path(basedir)
+ if os.altsep and os.altsep in basedir:
+ basedir = basedir.replace(os.altsep, os.sep)
+ if basedir[-1] != os.sep:
+ basedir += os.sep
+ return self.clean_path(basedir)
+
def __str__(self):
return self.realpath
@@ -175,11 +185,20 @@ class PathFormat():
"""Build directory path and create it if necessary"""
self.kwdict = kwdict
+ if self.basedirectory_conditions is None:
+ basedir = self.basedirectory
+ else:
+ for condition, basedir in self.basedirectory_conditions:
+ if condition(kwdict):
+ break
+ else:
+ basedir = self.basedirectory
+
if segments := self.build_directory(kwdict):
- self.directory = directory = self.basedirectory + self.clean_path(
- os.sep.join(segments) + os.sep)
+ self.directory = directory = \
+ f"{basedir}{self.clean_path(os.sep.join(segments))}{os.sep}"
else:
- self.directory = directory = self.basedirectory
+ self.directory = directory = basedir
if WINDOWS and self.extended:
directory = self._extended_path(directory)