tinytag icon indicating copy to clipboard operation
tinytag copied to clipboard

Ability to get all images

Open aw-was-here opened this issue 2 years ago • 4 comments

I would like the ability to get all of the images in a file. Currently, I think tinytag is coded to just pull the cover image or maybe it is the first image it comes across. Ideally, I'd like to have each image and its location (e.g., cover, insert, etc) accessible.

Thanks!

aw-was-here avatar Nov 02 '23 17:11 aw-was-here

What would the ideal API for this look like? I'm thinking something similar to the extra dict could work here, with standardized keys and image data as the value, but are we missing any important information this way? Is there anything else than the image and its description that's important to retain?

mathiascode avatar Nov 03 '23 13:11 mathiascode

I can't think of any other info that would be useful that would be in the purview of TinyTag. e.g., image size, image type, etc, are better handled by something like Pillow and would need to be handled by the downstream caller anyway.

aw-was-here avatar Nov 04 '23 16:11 aw-was-here

Here's a quick stab at a dictionary structure. Would be accessed as such: tag.images["front_cover"]["image_data"]

mime_type and picture_type are included because ID3 provides them, but I haven't looked into what other formats do.

tag.images:

  • other
  • icon
  • other_icon
  • front_cover
    • image_data
    • description
    • mime_type
    • picture_type
  • back_cover
  • leaflet
  • media
  • lead_artist
  • artist
  • conductor
  • band
  • composer
  • lyricist
  • recording_location
  • during_recording
  • during_performance
  • video
  • bright_colored_fish
  • illustration
  • band_logo
  • publisher_logo

mathiascode avatar Feb 26 '24 18:02 mathiascode

mime_type and picture_type are included because ID3 provides them, but I haven't looked into what other formats do.

I wonder how reliable those fields actually are. In my particular case I'll likely just pass the raw data to pillow to convert to a known format.

aw-was-here avatar Feb 27 '24 03:02 aw-was-here

PR for testing: https://github.com/devsnd/tinytag/pull/202

I changed my mind and used classes instead of dictionaries. Allows you to easily access images as such:

image = tag.images.front_cover
data = image.data
description = image.description

tag.get_image() remains as a way to get something that most likely resembles a cover image (sometimes it's stored in other instead of front_cover).

I wonder how reliable those fields actually are. In my particular case I'll likely just pass the raw data to pillow to convert to a known format.

I haven't had time to look into them, so I left them out for now. The format allows us to easily expose them in the future though, if necessary.

mathiascode avatar Feb 29 '24 18:02 mathiascode

The image MIME type is now available under tag.images.front_cover.mime_type.

mathiascode avatar Mar 01 '24 20:03 mathiascode

I didn't think about the case where multiple images of the same kind can exist, so the API has been changed. You can check the README.md file for more details, but it essentially boils down to:

  • tag.images.any to get any image available, prioritizing the cover art. tag.images.any.data to get the image as bytes.
  • 'images' attributes now contain lists of images. If you want to e.g. get a list of leaflet images, you can do so with tag.images.leaflet. To get the first leaflet image, tag.images.leaflet[0].
  • More uncommon image types were moved to tag.images.extra. If you want to get e.g. a list of artist images, tag.images.extra.get('artist').

mathiascode avatar Mar 02 '24 22:03 mathiascode

OK I'll try to make some time today/tomorrow to play around with this feature and see how it works out in my workflow. Thanks again!

aw-was-here avatar Mar 02 '24 22:03 aw-was-here

Sorry @mathiascode I got distracted with some family stuff. This one is back on my radar and I'll try it out.

aw-was-here avatar Mar 13 '24 17:03 aw-was-here

The new code seems to be working ok for me with some quick, preliminary tests. Got a track with 9 front_cover images and I'm getting the proper data for all 9.

Great job! Thanks!

aw-was-here avatar Mar 15 '24 01:03 aw-was-here