diff options
| author | 2024-09-07 18:33:19 -0400 | |
|---|---|---|
| committer | 2024-09-07 18:33:19 -0400 | |
| commit | 1f3ffe32342852fd9ea9e7704022488f3a1222bd (patch) | |
| tree | cb255a091b73e96840de0f6f44b36dff1acab4b9 /gallery_dl/formatter.py | |
| parent | b5e56c51e491b41f9eb6a895459c185788a377e5 (diff) | |
New upstream version 1.27.4.upstream/1.27.4
Diffstat (limited to 'gallery_dl/formatter.py')
| -rw-r--r-- | gallery_dl/formatter.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/gallery_dl/formatter.py b/gallery_dl/formatter.py index ec1c926..f197e5d 100644 --- a/gallery_dl/formatter.py +++ b/gallery_dl/formatter.py @@ -325,6 +325,23 @@ def _parse_slice(format_spec, default): return apply_slice +def _parse_arithmetic(format_spec, default): + op, _, format_spec = format_spec.partition(_SEPARATOR) + fmt = _build_format_func(format_spec, default) + + value = int(op[2:]) + op = op[1] + + if op == "+": + return lambda obj: fmt(obj + value) + if op == "-": + return lambda obj: fmt(obj - value) + if op == "*": + return lambda obj: fmt(obj * value) + + return fmt + + def _parse_conversion(format_spec, default): conversions, _, format_spec = format_spec.partition(_SEPARATOR) convs = [_CONVERSIONS[c] for c in conversions[1:]] @@ -480,6 +497,7 @@ _CONVERSIONS = { _FORMAT_SPECIFIERS = { "?": _parse_optional, "[": _parse_slice, + "A": _parse_arithmetic, "C": _parse_conversion, "D": _parse_datetime, "J": _parse_join, |
