aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/formatter.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2024-09-07 18:33:25 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2024-09-07 18:33:25 -0400
commit05335f2b4f60f6948edc96c71a7ef1c3ca71c9b3 (patch)
tree2c455afb2e2fcd51788500ce8a3455a1ef659b0e /gallery_dl/formatter.py
parentc45c7a86c313075d1fbd5803e7efdda680b27cd7 (diff)
parent1f3ffe32342852fd9ea9e7704022488f3a1222bd (diff)
Update upstream source from tag 'upstream/1.27.4'
Update to upstream version '1.27.4' with Debian dir 9c7b608ab0b9fa99a0cd692418a8f3965bf3d1c3
Diffstat (limited to 'gallery_dl/formatter.py')
-rw-r--r--gallery_dl/formatter.py18
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,