1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00
Commit Graph

32 Commits

Author SHA1 Message Date
Mike Fährmann
8f50c04af2
[formatter] implement 'X' format specifier (#5770) 2024-06-21 20:56:19 +02:00
Mike Fährmann
1ce5de0290
[formatter] implement 'C' format specifier (#5647)
to apply a conversion after ':' or
to apply multiple conversions

for example {tags:CSl} or {tags:J - /Cl}
to convert list to string and lowercase it
2024-06-05 16:49:29 +02:00
Mike Fährmann
d0cead105b
[formatter] allow dots etc in '…' literals (#5539)
don't parse fields starting with '

this disables the ability to directly apply […] to '…' literals,
but that's not really useful anyway and can still be done with _lit
2024-05-02 17:43:24 +02:00
Mike Fährmann
ddb2edfd32
[formatter] fix local DST datetime offsets for ':O'
'O' would get the *current* local UTC offset and apply it to all
'datetime' objects it gets applied to.
This would result in a wrong offset if the current offset includes
DST and the target 'datetime' does not or vice-versa.

'O' now determines the correct local UTC offset while respecting DST for
each individual 'datetime'.
2024-03-21 20:45:46 +01:00
Mike Fährmann
93a7a89cf6
[formatter] use value of last alternative (#4492)
fixes {fieldname|''} evaluating to the value of 'keywords-default'
instead of an empty string
2023-09-05 17:53:27 +02:00
Mike Fährmann
d8b21a97bf
[formatter] use 'rpartition' for \fM format strings
fixes using absolute module paths like C:\path\module.py on Windows
2023-08-11 22:29:33 +02:00
Mike Fährmann
ce93c460a6
[formatter] implement 'H' conversion (#4164)
to remove HTML tags and unescape HTML entities
2023-06-15 13:07:51 +02:00
Mike Fährmann
69865dcc05
[formatter] implement slicing strings as bytes (#4087)
prefixing a slice '[10:30]' with a lowercase b '[b10:30]' encodes
the string to bytes in filesystem encoding before applying the slice
2023-05-22 18:30:45 +02:00
Mike Fährmann
fe41a2b159
[formatter] support putting keys in quotes
i.e. obj["key"] or obj['key']
as in f-strings
2023-03-21 22:06:54 +01:00
Mike Fährmann
46fdf46f21
[formatter] support loading an f-string from a template file
"\fTF ~/path/to/file.txt"
2023-03-20 22:05:33 +01:00
Mike Fährmann
1a4d4a799b
[formatter] support filesystem paths for \fM 2023-03-20 22:01:33 +01:00
Mike Fährmann
11df3a021d
[formatter] enclose f-strings with """ instead of ''' 2023-03-03 20:03:27 +01:00
Mike Fährmann
5503ac4d5e
replace json.dumps with direct calls to JSONEncoder.encode 2023-02-09 15:51:40 +01:00
pi_allen
64902f518e [docs] Update links and fix field typo 2022-12-26 07:46:41 +01:00
Mike Fährmann
3082544fff
misc fixes
- fix typo (#3399)
- remove double assignment
- [bunkr] update things I forgot in 6b6f886d
- [soundgasm] adjust 'archive_fmt' (#3388)
2022-12-14 13:30:27 +01:00
Mike Fährmann
ca4742200b
use util.NONE as 'keyword-default' default value 2022-12-06 22:27:57 +01:00
Mike Fährmann
42481aed59
[formatter] implement 'S' format specifier (#3266)
to Sort lists
2022-11-21 21:44:42 +01:00
Mike Fährmann
67bad04dda
[formatter] add 'g' conversion to sluGify a string (#2410) 2022-08-26 17:57:17 +02:00
Mike Fährmann
6990ad0ba8
[formatter] do NOT apply :J to strings (#2833) 2022-08-16 16:41:19 +02:00
Mike Fährmann
74865adae5
implement 'format-separator' option (#2737)
a global option, that servers as a workaround for shortcomings due to
lack of a proper format string parser
2022-07-10 13:31:43 +02:00
Mike Fährmann
90ae48c40c
[formatter] implement 'O' format specifier (#2736)
to apply a UTC offset to 'date' values and other datetime objects
2022-07-08 12:51:03 +02:00
Mike Fährmann
04bed1eba3
[formatter] allow for custom "format" functions (#2721) 2022-07-05 12:22:01 +02:00
Mike Fährmann
54525d2e21
[formatter] implement slice operator as format specifier
this allows using a slice operator alongside other (special) format
specifiers like J, to first join list elements to a string and then
trimming that with a slice.

{tags:J, /[:50]}
2022-06-25 16:52:58 +02:00
Mike Fährmann
42525cfe8d
fix '{…!j}' for otherwise non-serializable types (##2624)
like 'datetime'
2022-06-07 17:47:07 +02:00
Mike Fährmann
f3408a9d92
implement string literals in replacement fields
- either {_lit[foo]} or {'foo'}
- useful as alternative for empty metadata fields: {title|'no title'}
- due to using '_string.formatter_field_name_split()' to parse format
  strings, using certain characters will result in an error: [].:!
2022-05-09 23:49:33 +02:00
Mike Fährmann
29db716a63
implement 'datetime_to_timestamp()'
and rename 'to_timestamp()'
to the more descriptive 'datetime_to_timestamp_string()'
2022-03-23 22:36:01 +01:00
Mike Fährmann
cf44aba333
[formatter] allow evaluating f-string literals
by starting a format string with '\fF'.

This was technically already possible with '\fE',
but this makes it a bit more convenient.
2022-03-18 13:31:01 +01:00
Mike Fährmann
3842cdcd8f
[formatter] implement 'D' format specifier
To be able to parse any string into a 'datetime' object
and format it as necessary.

Example:

{created_at:D%Y-%m-%dT%H:%M:%S%z}
->
"2010-01-01 00:00:00"

{created_at:D%Y-%m-%dT%H:%M:%S%z/%b %d %Y %I:%M %p}
->
"Jan 01 2010 12:00 AM"

with 'created_at' == "2010-01-01T01:00:00+0100"
2021-11-20 23:04:34 +01:00
Mike Fährmann
46e17c5e61
support accessing the current local datetime in format strings
{_now}, {_now:%Y-%m-%d}, etc
(#1968)
2021-10-30 21:41:09 +02:00
Mike Fährmann
38193dba46
support accessing environment variables in format strings (#1968)
{_env[HOME]} to get the value of $HOME
every other format string feature is supported as well
2021-10-28 19:18:55 +02:00
Mike Fährmann
0038a8c1a4
implement a way to specify 'extended' format strings
Starting a format string with '\f<Type> ' allows to set a different
format string type than the default. Available ones are

- T: A template file containing the actual format string
     "\fT ~/.templates/booru.txt

- E: An arbitrary Python expression
     "\fE title.upper().replace(' ', '-')"

- M: Name of a Python module followed by a function name inside it.
     This function gets called with the current metadata dict as
     argument and should return a string.
     "\fM my_module:generate_text"

'\f' was chosen since it is highly unlikely that a regular format string
would start with it, but that character could be changed to for example
'\\' or '/' etc.
2021-09-27 19:46:14 +02:00
Mike Fährmann
74145467dd
move 'util.Formatter' into its own 'formatter' module 2021-09-27 02:37:04 +02:00