-
-
Notifications
You must be signed in to change notification settings - Fork 975
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 format a string metadata? #318
Comments
There is now a format method to replace replace a (sub)string with another (95b1e4c). There are in general at least two "problems" with this approach, but hey, it works.
|
And before I forget: f-strings look really nice, but they can't be used here. They must be placed in the actual source code and have to be read and evaluated by a Python interpreter to work. Storing them in config files is therefore out of the question, but being able to do stuff like |
It works like a charm, @mikf. Thank you. 👍 |
Okay, just to get this straight..
This means that I cannot use something like this |
You cannot use but you can use them across multiple different fields, albeit only one per, and even put the standard format specifiers at the end: |
Okay, thanks. That's what I assumed, just wanted to be sure. Also, I just realized that my example does not really make a lot of sense. Adding a whitespace with |
@mikf Is it possible to make it to where all of the following extensions are converted to jpg? |
Possible, but rather cumbersome. Since 90e4c64, it is possible to use multiple replacement operations among other things, so you could theoretically use I'll probably add an option that allows replacing/renaming filename extensions in a better way. |
@mikf Thanks for the tip. I have one more thing I want to do, this time with titles. Additionally, I sometimes notice the title in the filename is truncated, presumably to avoid long filenames, but my system is configured for long path support, is there any way to override that? |
@ImportTaste You don't need to backslash escape There is also a general character replacement option: gallery-dl/docs/gallery-dl-example.conf Lines 154 to 165 in 7003e61
|
Oh, I missed that, thank you. Is there any way to get it to stop truncating the title? I have long paths enabled so I don't really need them shortened. |
File or directory names generally don't get truncated. There are a some exceptions in the default format strings for For example filenames for Reddit default to |
Thanks once again, that was very helpful. |
@mikf Is there a 'trim' option? Sometimes titles have leading spaces or trailing spaces that I'd like to be rid of. |
Not yet, but that should be quite easy to implement. |
@mikf Does extension-map have to be defined for every extractor? |
Like with all/most generic extractor options, you can set a general value and/or a specific value for certain extractors. And if it isn't set or For example {
"extractor": {
"extension-map": {"a": "b"},
"danbooru": {
"extension-map": {"c": "d"}
},
"pixiv": {
"extension-map": null
}
}
} will use the default for Pixiv, |
FYI: @mikf Okay, now that filename has an object with Python expressions to check against, my earlier example in here combining Let's see, the idea is to combine both of these somehow: Okay, maybe something like this: {
"title == ''" : "{id}.{extension}",
"" : "{title:R /_/}{id}.{extension}"
} Would this work? (Assuming you can check that a Although I just realized there may be another way to address this. Because if |
@Hrxn it is possible to combine these "special" formatting options since 90e4c64 (v1.13.0), i.e.
I'd rather do
As long as this nothing is an empty string and not |
Good to know, thanks! Oh well, checking this again is probably not much of slowdown anyway, I assume..
I see. So it's best to use
Yeah, that's what I meant. I tried that with an example - after writing this comment, whoops - and it is indeed working like that. |
I'm trying to format a metadata string, with:
Unsuccessfully, I tried the python f-string methods:
{title.lower().replace(' ', '_')}
Example:
My command:
$ gallery-dl --config=./my_config.json --simulate https://www.flickr.com/photos/mellbin/7085146945/
My
my_config.json
:My terminal output:
My desired output (lowercase + replaced blankspaces to underlines):
The text was updated successfully, but these errors were encountered: