Artwork from NSMetadataItem

I need to convert the NSData object from an NSMetadataItem object into a picture. The keyword is “artwork” and I can see the data as a MemoryBlock, but can’t figure out how to make that final conversion. Any clues?

This is what the data looks like:

The first part is a binary plist and then jpeg data at first glance.

That is, it looks like it’s a binary plist file with a child containing the image data in a jpeg data blob.

What did you do with NSMetadataItem to get that plist data?
Should the methods there not give you the NSData object of the JPEG directly?

Are you sure this isn’t an NSDictionary? Perhaps you’ve called valuesForAttributes (returns an NSDictionary) instead of valueForAttribute (returns am object)

Isn’t a plist an XML document?

I’ve implemented in MacOSLib both AVAsset and AVMetaDataItem. I create the AVAsset from the file, then get the metadata formats through availableMetadataFormats. For the first format (just to keep it simple), I get an array of AVMetadataItems using metadataForFormat.

For each AVMetadataItem in the array, I get the key (as string) and commonValue (as string). This works. If the key =“artwork”, I pull the dataValue (NSData). It’s that object that I posted above, and where I am stuck.

In this case, it’s a binary plist (bplist00). While it is a type of XML, it’s converted to binary to use less space.

@Kem Tekinay - It appears to be a JPEG, but there are elements of the first segment that do not match the JFIF spec. Scan through the rest of the data and see if you find the following sequence:

'FF', 'D8', 'FF', 'E0', <2 bytes to be skipped>, "JFIF", '00'

First I should mention that @Justin Elliott was right, it’s a plist, and I was able to extract its parts by converting it, ultimately, to a Dictionary. I’ll do it differently before I’m done, but for now I have four keys, data, identifier, picturetype, and MIME.

Tim, the data part starts with exactly those bytes, although, interestingly, picturetype is “other”. Now what?

(Keep in mind that I can’t use plugins for this.)

WAIT!! I had tried Picture.GetData and it didn’t work. BUT I forgot that I has hex-encoded the data for readability. I HAVE ARTWORK!!

Thanks to all for the help.