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

How to combine two conversions? !S and !l for instance. #5647

Closed
KonoVitoDa opened this issue May 27, 2024 · 6 comments
Closed

How to combine two conversions? !S and !l for instance. #5647

KonoVitoDa opened this issue May 27, 2024 · 6 comments

Comments

@KonoVitoDa
Copy link

I want to convert a list of {tags} into a string and also convert it to lowercase (Sankaku now capitalizes the first letter by default). But I saw in the documentation that I can't combine two specifiers, so is there a way to do it another way?

@Hrxn
Copy link
Contributor

Hrxn commented May 27, 2024

By using special formatting with a Python expression, i.e. the format string in your config must start like this: "\fE .."

Example:

"\fE ', '.join(t for t in tags).strip().lower()"

@mikf
Copy link
Owner

mikf commented May 27, 2024

Or, again, with an f-string, which usually makes accessing all other values easier than a Python expression.

\fF … {', '.join(tags).strip().lower()} …

@KonoVitoDa
Copy link
Author

KonoVitoDa commented May 31, 2024

Or, again, with an f-string, which usually makes accessing all other values easier than a Python expression.

\fF … {', '.join(tags).strip().lower()} …

This worked, thanks!
But how to evaluate a value, like ?// does? I've tried:

\fF {'[' + ', '.join(tags_artist).strip().lower() + '] ' if tags_artist else ''

Which results in:

> gallery-dl https://chan.sankakucomplex.com/en/posts/porq4epNwa7
[sankaku][error] FilenameFormatError: Applying filename format string failed (NameError: name 'tags_artist' is not defined)

And is it possible to end a f-string, so that \fFonly applies to the first keyword (tags_artist in this example)?

@mikf
Copy link
Owner

mikf commented May 31, 2024

But how to evaluate a value, like ?// does? I've tried:

\fF {'[' + ', '.join(tags_artist).strip().lower() + '] ' if tags_artist else ''

Access potentially undefined variables with locals().get("…")

\fF {'[' + ', '.join(tags_artist).strip().lower() + '] ' if locals().get("tags_artist") else ''

And is it possible to end a f-string, so that \fFonly applies to the first keyword (tags_artist in this example)?

Nope

mikf added a commit that referenced this issue Jun 5, 2024
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
@mikf
Copy link
Owner

mikf commented Jun 5, 2024

Added a C format specifier that allows to use multiple conversions in regular format strings (1ce5de0).

@KonoVitoDa
Copy link
Author

Added a C format specifier that allows to use multiple conversions in regular format strings (1ce5de0).

Nice, thanks!

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

3 participants