For the hate of APE tags

APE tags are yet another method of tagging media files with metadata. Ever wondered how your MP3 player knows the title and the artist of a song? Well it is through the use of tags implanted within the file, making sure the player does not try to play the information. The three most popular MP3 tag types are:

  1. ID3v1 – the original tagging format form 1993 using a fixed field block with a title, artist and album. All in iso-8859-1, so you probably could still correctly spell Röyksopp and Sigur Rós, but you will have problems adding the artist 峰厚介 – 市川秀男 – 日野元彦 – 植松孝夫 – 池田芳夫 – 稲葉国光 playing track ジンジャーブレッド・ボーイ, both due to the characters used and the 30 character limit in each field.
  2. ID3v2 – came in 1998 with the solution of using flexible and definable fields and allowing the tag to be places at the start of the file. The flexibility allowed apps to keep any kind of information they liked within the file. Everything from the maximum volume of the track to album artwork.
  3. APE – was implemented in parallel with ID3v2 and solves the same issues and the format is even more versatile.

ID3v2 is the most common tag format in MP3 files “in the wild” and most taggers will add an ID3v1 tag from the ID3v2 tag data just to cover both bases. APE, although not as common due to its flexibility, is the preferred tag format in many applications. Rhythmbox for example looks for an APE tag, then an ID3v2 and at a last resort tries an ID3v1. The problem is that most Linux tagging tools, and players which allow you to edit the tags, only write ID3 tags. This creates a bizarre situation where you change the tag of a song in Rhythmbox, the value in the field changes, the ID3 tag is updated in the file, Rhythmbox notices an updated file, it re-reads the file APE tags, changes the field back to it’s original value.

How to kill APE tags?

This is something I have struggled over for several years. There are pieces of Linux software which can edit APE tags, but I found these get confused by the presence of an ID3 tag. For ages, I would remove the ID3 tag from a file, remove the APE tag, then re-insert the ID3 information. This was both clumsy and dangerous as my hacky shell scripts would often do disastrous things with tags that have escaping characters (If you are in a band, release a song named \” rm -Rf *; ).

The pain lasted until the other day, when I looked around and found py-ApeTag. Wow, it just works (that’s my favourite type of working). It removes the APE tags even when obscured by other tags and worked even in cases where I gave up trying to use other software to remove the tag and went by hand with hexedit to damaging the field names so they would not conflict. Applied it to my entire music collection without a single fault. Thank you Jeremy Evans!

How to use

To install, as root, download my altered version of the py-ApeTag module to some bin directory and make it executable.

wget -O/usr/bin/ApeTag
chmod a+x /usr/bin/ApeTag

To run, execute ApeTag with the filenames of the files you wish to view the APE tag of.

ApeTag *.mp3

Now that you can see the tags, you can remove them. You can apply this to files with no tag and it will not touch them.

ApeTag --delete *.mp3

To apply to all files in your library.

find -name \*.mp3  -exec ApeTag {} \;
    • James Livingston
    • November 26th, 2009

    Strictly speaking Rhythmbox doesn’t “prefer” APE tags, it’s just a quirk of the implementation that, due the ordering of the data in the file, APE tags get recognised after ID3v2 tags and so “win” if the same tag is in both.

    In practice, that means Rhythmbox “prefers” APE tags though.

    • RDuke15
    • December 8th, 2009

    Looks like a nice script, but a first test shows a couple of very simple fixes would make it much more usable:

    – exit with a non-0 return value on errors
    (currently, it always exists successfully; try running “ApeTag nosuchfile && echo ApeTag finished happily with return code $?”)

    – print errors to STDERR, not to STDOUT.
    (currently, it prints everything to STDOUT, and nothing to STDERR. So it’s not quite possible to redirect the output, while still seeing the errors)

  1. I’ve just stumbled upon this very problem while re-tagging some songs with easytag while rhythmbox and nautilus kept displaying the old tags. And I’ve recalled this post, googled it up and yay – it works! Thanks for sharing.

    • evoka
    • February 25th, 2010

    Thank you so much !!

    • Jeff
    • April 11th, 2010

    I ran the script on one of the albums that I’m having problems with. In particular, this album has a problem with the genre tag reverting back to the original tag. The script said that there was no APE tag information, but I stilled continued on and ran “find -name \*.mp3 -exec ApeTag {} \;” in the directory of that album. It doesn’t seem to have fixed the problem with tags for me. Any ideas?

    • Sometimes there are multiple id3 tags in a file. Try deleting the id3 tags using kid3 and see if you can see the Ape tag then. Sometimes the multiple id3 tags hide the ape tag, sometimes they conflict.

  2. Thank you for posting this, I really appreciate it. I was ready to give up. It took me hours before I identified the cause of this annoying problem and found your post.

    • Josh
    • May 31st, 2010

    Thanks, mate – I was screaming in frustration at Rhythmbox splitting an artist into two artists (one with “of”, one with “Of”) despite me editing the tags every way I could. I opened an mp3 in a hex editor and found an APE tag at the end. I used MusicBrainz Picard to strip the APE tags off – I use it for tagging stuff normally, anyway; this one album had somehow been skipped over.

    • Martin
    • December 8th, 2010

    Good thing! I’ve come across this because after editing tags in easytag and then trying to ReplayGain my songs in foobar2000 (wunning greatly under wine) the old and unchanges tags reappeared. It took me a while of pulling my hair out until I’ve realized the existence of APE tags in addition to the ID3v2.4-Tags that I had just reworked.

    So while your script is super for extinguishing APE tags from a whole library, here’s a short and mouse-driven fix: Load your files or folders in foobar2000, select them altogether, right-click on them and choose “Tagging”->”MP3 Tag Types”. Then uncheck everything except the ID3v2-Option and hit “Update Files”. This instantly updates the files, leaving only the sane ID3-Tags.

  3. Today I got the same problem using Rhythmbox. So I opened the problematic file with a text editor, and found the string “APETAGEX”. After deleting the APE tag by your script, the problem disappeared. Thanks for the great script.

    I found Totem is also confused by the APE tags. Maybe GStreamer itself has this annoying bug.

    • goths
    • May 11th, 2014

    I have long been annoyed about not visible tags. Id3v2 cant see that APE. Unfortunately eyed3 not remove everything. So I have found your script and it works really good. Thanks for that;-)

  1. No trackbacks yet.

This blog is kept spam free by WP-SpamFree.