Reading Information from iTunes AAC Files

If you read the last lab and thought about how ID3 metadata is imported into a QuickTime movie’s UserData, you might well expect that the same thing would be true of AAC files created by iTunes: .m4a files for songs “ripped” by the user and .m4p files sold by the iTunes Music Store. In fact, because these files use an MPEG-4 file format that is itself based on QuickTime, you might think that using the same user data scheme would be a slam dunk.

But...you’d be wrong.

These AAC files do put the metadata in the user data, but they do so in a way that resists straightforward retrieval via QuickTime. Fortunately, it’s not too hard to get the values out with some parsing.

Note

Buckle up, this one is rough.

How do I do that?

For once, theory needs to come before code—you need to see the format to understand how to parse it. Here’s a /usr/bin/hexdump of an iTunes Music Store AAC file from my collection, Toto Dies.m4p:

0000b010 00 3d 5f 3c 00 3d 7d 5e 00 3d 9a fb 00 03 18 da |.=_<.=}^.=......| 0000b020 75 64 74 61 00 03 18 d2 6d 65 74 61 00 00 00 00 |udta....meta....| 0000b030 00 00 00 22 68 64 6c 72 00 00 00 00 00 00 00 00 |..."hdlr........| 0000b040 6d 64 69 72 61 70 70 6c 00 00 00 00 00 00 00 00 |mdirappl........| 0000b050 00 00 00 03 11 9b 69 6c 73 74 00 00 00 21 a9 6e |......ilst...!.n| 0000b060 61 6d 00 00 00 19 64 61 74 61 00 00 00 01 00 00 |am....data......| 0000b070 00 00 54 6f 74 6f 20 44 69 65 73 00 00 00 24 a9 |..Toto Dies...$.| 0000b080 ...

Get QuickTime for Java: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.