This is old code and quite a ‘hack’. It worked for my purposes so development unfortunately stopped after the task was completed.

On my linux server I had a directory of unsorted music files. I like my music to be organised by folders, for example:

%artist%\%album%\*.mp3 – Death\Scream Bloody Gore\

So I began writing a simple C++ program to read the artist and album tags from the files, create and move the files into the correct structure.

This is a relatively simple task and I know C++ is not the best choice of language but I thought I would continue and see how the development of C++ within Linux would fair. Mainly from a libraries point of view and an IDE.

Trying to find an IDE which would do code auto completion was a task which proved difficult. KDevelop seemed bloated and unusable. I settled on using a simple code editor called codeblocks. Simple, effective and easy to use.

Next task was to either write a library to read tags from the files or find a suitable library.

http://developer.kde.org/~wheeler/taglib.html

Was my choice, a simple generic interface for multiple music files. Quite nice.

So I set about writing the file, here are my results:

mp3_sorter.zip

The archive contains 3 files, the .cpp file, a simple Readme file and an sh build command.

To build the mp3_sorter.cpp might require you to change the include paths at the top of the file.

Below is the command used to build, note the taglib-config part, it automatically adds the includes and linker options for taglib.

g++ mp3_sorter.cpp -Wno-deprecated `taglib-config –cflags –libs` -o mp3_sorter

Tags: , , , , , ,
One Response to “Linux MP3 ID3 Tag Sorting Script”
  1. asphixmx says:

    Hi, thanks for your program! I must say I am a newbie but I could install the tag library, compile your program and I am using it :) Thanks a lot. Just one thing… since I have some files with foreign characters (in spanish, like the ñ and á é í ó ú), the program doesn’t work when they are present. I am trying to develop a bash script doing the same as your C program:

    #!/bin/bash
    TITLE=”`id3tool “$1″ | grep ‘^Song Title:’ | awk ‘{ for (i=3;i<=NF;i++) { printf $i } }’`”
    ARTIST=”`id3tool “$1″ | grep ‘^Artist:’ | awk ‘{ for (i=2;i<=NF;i++) { printf $i } }’`”
    ALBUM=”`id3tool “$1″ | grep ‘^Album:’ | awk ‘{ for (i=2;i<=NF;i++) { printf $i; } }’`”
    GENRE=” `id3tool “$1″ | grep ‘^Genre:’ | awk ‘{ for (i=2;i<=NF;i++) { printf $i } }’`”

    install -D “$1″ /home/asphix/Public/prueba/”$ARTIST”/”$ALBUM”/”$ARTIST – $TITLE”.mp3

    I have some issues, the ARTIST and ALBUM lacks of spaces ( ” ” ) and in GENRE it includes some kind of funny characters after the GENRE. I am trying to solve those issues. Any help is apreciated.
    Sorry for my bad english
    Thanks again!

Leave a Reply