Fixing Incorrect Types in Apple Music

Recently, I’ve been going through my Music collection and doing cleanup. I’ve been using iTunes and now the hot mess of Apple Music since the very beginning. Throughout the years, various tracks have randomly disappeared, or gotten corrupted in some way. I’m not entirely sure why, though I think it might have something to do with the iTunes Match service. Still, its benefits outweigh any problems I have had. I like having access to all the CDs that I ripped from my collection available to me without having to pre-load them on my phone or other device.

In cleaning up the track names, and fixing missing bits of data, I have been using MusicBrainz Picard, which is an indispensable utility for tagging your music. But on occasional, seemingly random tracks that had once been MP3, but then either converted or downloaded from the iTunes Match service, the file name ends with .m4a, but the data inside is still actually MP3 data. Apple Music does not like the files to be name incorrectly. Picard doesn’t care, and will properly fix the tags, but I get an error with Music when I try to refresh the data.

So I starting thinking about how I could check to find all the incorrectly named files, and correct them to their proper extension. There are two ways you can quickly find out what is in the file, regardless of how it is names. There is the standard unix command, file, which will give you a one line synopsis of the data. There is also the open source tool, mediainfo, that will give you far more details. I have the command line version of mediainfo on my machine, so that is what I used. You could trivially adapt this little script to use file instead.

Open up your favorite terminal program, and change directories into your music library and then execute this (compound) one liner:

find . -type f -iname "*.m4a" | while read LINE
    CHECK=$( mediainfo "$LINE" | grep "Layer 3" )
    if [ "$CHECK" ]
        echo "$LINE"
        mv "$LINE" "${LINE%.m4a}.mp3"

This will walk through your library and find all the AAC files (ending in .m4a), and check to make sure they are actually AAC and not a mis-named MP3. If it finds that it is an MP3 (searching for “Layer 3”), then it will print the line, and move the offending file to the same name, but with .mp3 as the extension. Once you have done this, you will want to refresh the tracks in Music.

Leave a Comment