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

[actions] support multiple actions per pattern

This commit is contained in:
Mike Fährmann 2024-06-30 02:06:09 +02:00
parent 8219a78b8d
commit f41a5065b2
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 38 additions and 11 deletions

View File

@ -936,23 +936,31 @@ Description
extractor.*.actions
-------------------
Type
* ``object`` (`pattern` -> `action`)
* ``list`` of ``lists`` with 2 ``strings`` as elements
* ``object`` (`pattern` -> `action(s)`)
* ``list`` of ``lists`` with `pattern` -> `action(s)` pairs as elements
Example
.. code:: json
{
"error" : "status |= 1",
"info:Logging in as .+" : "level = debug",
"warning:(?i)unable to .+": "exit 127",
"info:Logging in as .+" : "level = debug"
"error" : [
"status |= 1",
"exec notify.sh 'gdl error'",
"abort"
]
}
.. code:: json
[
["error" , "status |= 1" ],
["info:Logging in as .+" , "level = debug"],
["warning:(?i)unable to .+", "exit 127" ],
["info:Logging in as .+" , "level = debug"]
["error" , [
"status |= 1",
"exec notify.sh 'gdl error'",
"abort"
]]
]
Description
@ -968,6 +976,9 @@ Description
``action`` is parsed as action type
followed by (optional) arguments.
It is possible to specify more than one ``action`` per ``pattern``
by providing them as a ``list``: ``["<action1>", "<action2>", …]``
Supported Action Types:
``status``:
@ -982,9 +993,9 @@ Description
``level``:
| Modify severity level of the current logging message.
| Can be one of ``debug``, ``info``, ``warning``, ``error`` or an integer value.
``print``
``print``:
Write argument to stdout.
``exec``
``exec``:
Run a shell command.
``abort``:
Stop the current extractor run.
@ -993,7 +1004,8 @@ Description
``restart``:
Restart the current extractor run.
``wait``:
Stop execution until Enter is pressed.
| Sleep for a given Duration_ or
| wait until Enter is pressed when no argument was given.
``exit``:
Exit the program with the given argument as exit status.

View File

@ -27,9 +27,17 @@ def parse(actionspec):
for event, spec in actionspec:
level, _, pattern = event.partition(":")
type, _, args = spec.partition(" ")
search = re.compile(pattern).search if pattern else util.true
action = (search, ACTIONS[type](args))
if isinstance(spec, str):
type, _, args = spec.partition(" ")
action = (search, ACTIONS[type](args))
else:
action_list = []
for s in spec:
type, _, args = s.partition(" ")
action_list.append(ACTIONS[type](args))
action = (search, _chain_actions(action_list))
level = level.strip()
if not level or level == "*":
@ -50,6 +58,13 @@ def _level_to_int(level):
return int(level)
def _chain_actions(actions):
def _chain(args):
for action in actions:
action(args)
return _chain
def action_print(opts):
def _print(_):
print(opts)