1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

implement a 'path-replace' option (#662, #755)

This commit is contained in:
Mike Fährmann 2020-05-24 17:35:25 +02:00
parent 15c3d29062
commit ddc253cf9a
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 18 additions and 5 deletions

View File

@ -135,9 +135,10 @@ Type ``string`` or ``object``
Default ``"auto"``
Example | ``"/!? (){}"``
| ``{" ": "_", "/": "-", "|": "-", ":": "-", "*": "+"}``
Description | String of characters to be replaced with underscores (``_``)
| or an object mapping specific characters to others
| in generated path segment names.
Description | A string of characters to be replaced with the value of
`path-replace <extractor.*.path-replace>`__
| or an object mapping invalid/unwanted characters to their replacements
| for generated path segment names.
Special values:
@ -151,6 +152,16 @@ Description | String of characters to be replaced with underscores (``_``)
=========== =====
extractor.*.path-replace
------------------------
=========== =====
Type ``string``
Default ``"_"``
Description The replacement character(s) for
`path-restrict <extractor.*.path-restrict>`__
=========== =====
extractor.*.path-remove
-----------------------
=========== =====

View File

@ -10,6 +10,7 @@
"skip": true,
"sleep": 0,
"path-restrict": "auto",
"path-replace": "_",
"path-remove": "\\u0000-\\u001f\\u007f",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0",

View File

@ -725,16 +725,17 @@ class PathFormat():
self.basedirectory = basedir
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 = "\\\\|/<>:\"?*"
self.clean_segment = self._build_cleanfunc(restrict, replace)
remove = extractor.config("path-remove", "\x00-\x1f\x7f")
self.clean_segment = self._build_cleanfunc(restrict, "_")
self.clean_path = self._build_cleanfunc(remove, "")
@staticmethod