Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When {date} contains a "T" gallery-dl errors #6921

Closed
Twi-Hard opened this issue Feb 2, 2025 · 2 comments
Closed

When {date} contains a "T" gallery-dl errors #6921

Twi-Hard opened this issue Feb 2, 2025 · 2 comments

Comments

@Twi-Hard
Copy link

Twi-Hard commented Feb 2, 2025

I'm switching to using this for the boorus:

"directory":
[
    "{_env[domain]}",
    "images",
    "{date:%Y}",
    "{date:%m}",
    "{date:%d}"
]

A couple of the boorus have a "T" in the dates like this:

%Y-%m-%dT%H:%M:%S

All the other boorus use this which works fine:

%Y-%m-%d %H:%M:%S

I get this error when I try to download something with one of those boorus:

Traceback (most recent call last):
  File "/home/mane/.venv/default/lib/python3.12/site-packages/gallery_dl/path.py", line 271, in build_directory
    segment = fmt(kwdict).strip()
              ^^^^^^^^^^^
  File "/home/mane/.venv/default/lib/python3.12/site-packages/gallery_dl/formatter.py", line 172, in wrap
    return fmt(kwdict[key] if key in kwdict else self.default)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mane/.venv/default/lib/python3.12/site-packages/gallery_dl/formatter.py", line 458, in wrap
    return format(obj, format_spec)
           ^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Invalid format specifier '%Y' for object of type 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mane/.venv/default/lib/python3.12/site-packages/gallery_dl/job.py", line 153, in run
    self.dispatch(msg)
  File "/home/mane/.venv/default/lib/python3.12/site-packages/gallery_dl/job.py", line 201, in dispatch
    self.handle_directory(msg[1])
  File "/home/mane/.venv/default/lib/python3.12/site-packages/gallery_dl/job.py", line 380, in handle_directory
    self.initialize(kwdict)
  File "/home/mane/.venv/default/lib/python3.12/site-packages/gallery_dl/job.py", line 544, in initialize
    pathfmt.set_directory(kwdict)
  File "/home/mane/.venv/default/lib/python3.12/site-packages/gallery_dl/path.py", line 188, in set_directory
    segments = self.build_directory(kwdict)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mane/.venv/default/lib/python3.12/site-packages/gallery_dl/path.py", line 279, in build_directory
    raise exception.DirectoryFormatError(exc)
gallery_dl.exception.DirectoryFormatError: Applying directory format string failed (ValueError: Invalid format specifier '%Y' for object of type 'str')

It errors even if I set the date-format to %Y-%m-%dT%H:%M:%S

I've tried both of these:

"format-date": "%Y-%m-%d %H:%M:%S",
"format-date": "%Y-%m-%dT%H:%M:%S",

The boorus this happens with are ponerpics.org and manebooru.art

Does anybody know what can be done to fix this?

mikf added a commit that referenced this issue Feb 2, 2025
Some instances do not include a UTC offset or 'Z' in their datetime
values, e.g. 2024-03-14T13:46:46 compared to 2024-03-14T13:46:46Z
@mikf
Copy link
Owner

mikf commented Feb 2, 2025

Fixed in 4ab9237

The problem was not the T in the middle, but the missing Z at the end of datetime strings such as 2024-03-14T13:46:46. When datetime parsing fails, it uses the input string as date, which in this case contains a T and causes these errors.

"format-date": "%Y-%m-%d %H:%M:%S",

format-date is not a recognized option.

To manually parse datetime strings, you can use the D format specifier:

{created_at:D%Y-%m-%dT%H:%M:%S/}

@Twi-Hard
Copy link
Author

Twi-Hard commented Feb 2, 2025

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants