1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-24 03:32:33 +01:00
Commit Graph

7 Commits

Author SHA1 Message Date
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