[path] implement conditional 'part-directory' (#8329)
This commit is contained in:
@@ -7202,15 +7202,29 @@ Description
|
||||
downloader.*.part-directory
|
||||
---------------------------
|
||||
Type
|
||||
|Path|_
|
||||
* |Path|_
|
||||
* ``object`` (Condition_ → |Path|_)
|
||||
Default
|
||||
``null``
|
||||
Description
|
||||
Alternate location for ``.part`` files.
|
||||
Example
|
||||
.. code:: json
|
||||
|
||||
Missing directories will be created as needed.
|
||||
If this value is ``null``, ``.part`` files are going to be stored
|
||||
alongside the actual output files.
|
||||
"/tmp/.gdl"
|
||||
|
||||
.. code:: json
|
||||
|
||||
{
|
||||
"size > 100000": "~/.gdl/part",
|
||||
"duration" : "/tmp/.gdl/video",
|
||||
}
|
||||
|
||||
Description
|
||||
Alternate location(s) for ``.part`` files.
|
||||
Note
|
||||
If this value is ``null`` or no Conditions_ apply,
|
||||
``.part`` files are stored alongside the actual output files.
|
||||
|
||||
For a single |Path|_, missing directories will be created as needed
|
||||
|
||||
|
||||
downloader.*.progress
|
||||
|
||||
@@ -31,8 +31,15 @@ class DownloaderBase():
|
||||
self.partdir = self.config("part-directory")
|
||||
|
||||
if self.partdir:
|
||||
self.partdir = util.expand_path(self.partdir)
|
||||
os.makedirs(self.partdir, exist_ok=True)
|
||||
if isinstance(self.partdir, dict):
|
||||
self.partdir = [
|
||||
(util.compile_filter(expr) if expr else util.true,
|
||||
util.expand_path(pdir))
|
||||
for expr, pdir in self.partdir.items()
|
||||
]
|
||||
else:
|
||||
self.partdir = util.expand_path(self.partdir)
|
||||
os.makedirs(self.partdir, exist_ok=True)
|
||||
|
||||
proxies = self.config("proxy", util.SENTINEL)
|
||||
if proxies is util.SENTINEL:
|
||||
|
||||
@@ -325,7 +325,15 @@ class PathFormat():
|
||||
self.kwdict["extension"] = self.prefix + self.extension_map(
|
||||
"part", "part")
|
||||
self.build_path()
|
||||
if part_directory:
|
||||
|
||||
if part_directory is not None:
|
||||
if isinstance(part_directory, list):
|
||||
for condition, part_directory in part_directory:
|
||||
if condition(self.kwdict):
|
||||
break
|
||||
else:
|
||||
return
|
||||
|
||||
self.temppath = os.path.join(
|
||||
part_directory,
|
||||
os.path.basename(self.temppath),
|
||||
|
||||
Reference in New Issue
Block a user