[path] implement conditional 'part-directory' (#8329)
This commit is contained in:
@@ -7202,15 +7202,29 @@ Description
|
|||||||
downloader.*.part-directory
|
downloader.*.part-directory
|
||||||
---------------------------
|
---------------------------
|
||||||
Type
|
Type
|
||||||
|Path|_
|
* |Path|_
|
||||||
|
* ``object`` (Condition_ → |Path|_)
|
||||||
Default
|
Default
|
||||||
``null``
|
``null``
|
||||||
Description
|
Example
|
||||||
Alternate location for ``.part`` files.
|
.. code:: json
|
||||||
|
|
||||||
Missing directories will be created as needed.
|
"/tmp/.gdl"
|
||||||
If this value is ``null``, ``.part`` files are going to be stored
|
|
||||||
alongside the actual output files.
|
.. 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
|
downloader.*.progress
|
||||||
|
|||||||
@@ -31,8 +31,15 @@ class DownloaderBase():
|
|||||||
self.partdir = self.config("part-directory")
|
self.partdir = self.config("part-directory")
|
||||||
|
|
||||||
if self.partdir:
|
if self.partdir:
|
||||||
self.partdir = util.expand_path(self.partdir)
|
if isinstance(self.partdir, dict):
|
||||||
os.makedirs(self.partdir, exist_ok=True)
|
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)
|
proxies = self.config("proxy", util.SENTINEL)
|
||||||
if proxies is util.SENTINEL:
|
if proxies is util.SENTINEL:
|
||||||
|
|||||||
@@ -325,7 +325,15 @@ class PathFormat():
|
|||||||
self.kwdict["extension"] = self.prefix + self.extension_map(
|
self.kwdict["extension"] = self.prefix + self.extension_map(
|
||||||
"part", "part")
|
"part", "part")
|
||||||
self.build_path()
|
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(
|
self.temppath = os.path.join(
|
||||||
part_directory,
|
part_directory,
|
||||||
os.path.basename(self.temppath),
|
os.path.basename(self.temppath),
|
||||||
|
|||||||
Reference in New Issue
Block a user