mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-26 04:32:51 +01:00
extend 'path-restrict' option
Allow its value to be a JSON object / Python dict that specifies a mapping from invalid/unwanted input characters to specific output characters. For example {"/": "-", "*": "+"} will transform "foo / ***bar***" into "foo - +++bar+++" (closes #662, #755)
This commit is contained in:
parent
bcac31b7c7
commit
bc53302ad6
@ -131,11 +131,13 @@ Description Use an extractor's current target directory as
|
||||
extractor.*.path-restrict
|
||||
-------------------------
|
||||
=========== =====
|
||||
Type ``string``
|
||||
Type ``string`` or ``object``
|
||||
Default ``"auto"``
|
||||
Example ``"/!? (){}"``
|
||||
Description Set of characters to replace with underscores (``_``)
|
||||
in generated path segment names.
|
||||
Example | ``"/!? (){}"``
|
||||
| ``{" ": "_", "/": "-", "|": "-", ":": "-", "*": "+"}``
|
||||
Description | String of characters to be replaced with underscores (``_``)
|
||||
| or an object mapping specific characters to others
|
||||
| in generated path segment names.
|
||||
|
||||
Special values:
|
||||
|
||||
@ -144,7 +146,7 @@ Description Set of characters to replace with underscores (``_``)
|
||||
* ``"unix"``: ``"/"``
|
||||
* ``"windows"``: ``"\\\\|/<>:\"?*"``
|
||||
|
||||
Note: In a set with 2 or more characters, ``[]^-\`` need to be
|
||||
Note: In a string with 2 or more characters, ``[]^-\`` need to be
|
||||
escaped with backslashes, e.g. ``"\\[\\]"``
|
||||
=========== =====
|
||||
|
||||
@ -156,7 +158,7 @@ Type ``string``
|
||||
Default ``"\u0000-\u001f\u007f"`` (ASCII control characters)
|
||||
Description Set of characters to remove from generated path names.
|
||||
|
||||
Note: In a set with 2 or more characters, ``[]^-\`` need to be
|
||||
Note: In a string with 2 or more characters, ``[]^-\`` need to be
|
||||
escaped with backslashes, e.g. ``"\\[\\]"``
|
||||
=========== =====
|
||||
|
||||
|
@ -690,6 +690,9 @@ class PathFormat():
|
||||
def _build_cleanfunc(chars, repl):
|
||||
if not chars:
|
||||
return lambda x: x
|
||||
elif isinstance(chars, dict):
|
||||
def func(x, table=str.maketrans(chars)):
|
||||
return x.translate(table)
|
||||
elif len(chars) == 1:
|
||||
def func(x, c=chars, r=repl):
|
||||
return x.replace(c, r)
|
||||
|
Loading…
Reference in New Issue
Block a user