Ability to get all images
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!
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?
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.
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
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.
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.
The image MIME type is now available under tag.images.front_cover.mime_type.
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.anyto get any image available, prioritizing the cover art.tag.images.any.datato 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').
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!
Sorry @mathiascode I got distracted with some family stuff. This one is back on my radar and I'll try it out.
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!