gallery-dl icon indicating copy to clipboard operation
gallery-dl copied to clipboard

[patreon] get per-image metadata

Open lectrode opened this issue 2 years ago • 1 comments

I would like to grab metadata for individual images in each post on patreon. Like the following (as found with -K):

images[N]['file_name']
images[N]['metadata']['dimensions']['h']
images[N]['metadata']['dimensions']['w']

However I can't seem to figure out how to get the current image N. {num} seems like it should work, but it doesn't, as images[{num}]['file_name'] returns None. Not only that, but it is the wrong value per image as well (the array index starts with 0, but {num} starts at 1).

Manually putting images[0]['file_name'] and images[1]['file_name'] works for getting the first 2 filenames, but ideally this would not be statically defined in the content format string.

For future reference, I'd also like to know how to output all values for an array. Something akin to the following:

images[*]['file_name']

content format is currently as follows (not doing what i'd like it to do):

"content-format"  : "resolution: {images[{num}]['metadata']['dimensions']['w']}x{images[{num}]['metadata']['dimensions']['h']}\nfilename: {images[{num}]['file_name']}\n\n"

Current example output:

resolution: NonexNone
filename: None

lectrode avatar Jul 08 '23 18:07 lectrode

I have the same issue. I think the trouble is that you need a nested substitution. For example, for

{images[{num}]['file_name']}

it needs to know to substitute {num} before {images...} and that doesn't work out of the box. There's probably a way to make it work, but I don't know enough about gallery-dl/Python string formatting.

As a temporary hack, I edited the start of the build_filename function in path.py:

    def build_filename(self, kwdict):
        """Apply 'kwdict' to filename format string"""

        if "num" in kwdict :
            num = kwdict['num'] - 1
            image_info = kwdict['images'][num]['display']
            kwdict['xyz'] = f"{image_info['width']}x{image_info['height']}"

Then used {xyz} in my filename format string in the config file.

fsharpn00b avatar Jun 04 '25 16:06 fsharpn00b