Updating MP3 tags

Call it spring cleaning, but over the years my music library has gotten out of control in terms of how artist names, album names, song names, album date, etc… is or is not stored or has different variations of spellings. Though I know that there are a few programs out their to help deal with this problem, I thought this would be a good exercise to learn more about updating binary files which I haven’t done before.

Does anyone have a sample project or tutorial that I could review to get started? I am looking to understand best practice and form on the proper way to update binary files. I will be happy to share any concept projects I create as part of my learning process.

thank you in advance.

The key to doing this is to have your hands on the specs for the layout of MP3 files in order to know exactly what bytes you need to read and replace to make your desired updates. Once having the specs first write a little program that does nothing more than read a given MP3 file extracting those fields and displaying them on the screen. Run this against a large number of MP3 files to insure that you have your code correct, reading the proper bytes from the file. When that is accomplished, make copies of several of your MP3 files to a safe location for testing. Now write the code that will actually write the updated information using the POSITION property of the folderitem for the binary stream.

From what I see from the specs an MP3 file appears to have 4 bytes at the very start of the file called the Header content. This doesn’t look like something you would want to mess with.

That is followed by 128 bytes. starting with the characters TAG which is the part of the file you want to update the MPEG Audio Tg IS3V1 section of the file., It contains Title, Artist, Album, Year, Comment, and Genre. Each of these fields contains a fixed number of bytes. So, each field can be pointed to with the POSITION property and then that number of bytes read to obtain the contents of the field. Be sure to account for the fact that that this starts following the 4 byte header. So although the specs say TAG starts at byte 0, it is truly the 5th byte of the file or POSITION=4 since the first byte is POSITION=0

Like I stated, first just write a little program to read in the info and display it. Run this against a good number of MP3 files to be sure you have it down pat. Now, add in the code to update the files seeing as you now know that you are accessing the proper positions in the file. But, be sure to do this with copies of some of you MP3 files. After updating them run them in some app that will display the information as they are being played and verify that your updates are good.

I am referencing the following when giving you the above information regarding the file layout.
MPEG Layout

Reading and writing id3 V1, made for OSX, may also work in Windows.

Download

ID3 v1 is pretty simple
ID3 v2 is less so

ID3 is very common now though

for ID3v2 there are useful command line tools (id3tag, id3info …)

I use it in this LittlePlayer (OSX)

Thank you all for the head start and I apologize for the long delay in response. I have begun the process of creating a reader and then will follow with Harrie’s data flow and Axel’s example project.

This was very helpful… thank you again.