1

I'm trying to extract all the available meta-data from mp3 files (amongst others) using the AVKit framework.

I first get the "common" metadata with something like:

    let asset = AVAsset(url: URL(fileURLWithPath: path))
    for item in asset.commonMetadata {
        if let commonKey = item.commonKey {
            if let storageKey = stringValueKeys[commonKey] {

and that works fine.

Note that I look up a storageKey stored in the stringValueKeys hash to determine whether I'm interested in this item and then to store it into an internal database for caching.

Then I process id3 tags separately (they are not returned by asset.commonKey) using:

        for item in asset.metadata(forFormat: .id3Metadata) {

        if let key = item.key as? AVMetadataKey {
            if let storageKey = stringValueKeys[key] {

I can retrieve the data correctly, but the keys that are returned do not match up with those defined by the framework!?

item.key contains the 3 letter keys as defined by the ID3 standard (e.g. TT1, TAL, but AVMetadataKey defines 4 letter keys, e.g. AVMetadataKey.id3MetadataKeyAlbumTitle = TALB.

I can't find a way of translating between the 4 and the 3 letter codes.

Any help would be greatly appreciated.

Frank R.
  • 2,328
  • 1
  • 24
  • 44

1 Answers1

1

There are two versions of tags: ID3 2.2's 3 byte tags, and 2.3+'s 4 byte tags. The constants declared in AVMetadataKey are the 4 byte tags.

If you're seeing the 3 byte tags as the key, then it must be a file tagged with the 21-year-old v2.2 tags and AVAsset is giving them to you as-is, so you'll just need to do the conversion yourself. There aren't that many tags, so you can easily make a conversion list yourself.

seth
  • 1,647
  • 1
  • 12
  • 20