I’ve been using this utility since I wrote it 6 years ago, and this afternoon, I cleaned up the code base in order to release it. It’s a simple command-line music file organizer. It takes a list of files or directories as program arguments, inspects the tags of all the enclosed music files, and then determines which directories need to be created and what the music file name should be. Plenty of GUI tools do this already, many of which are very customizable, but I have yet to see a command-line utility as simple as this that gets the job done.

The general ingestion routine for acquiring music on the Interwebs is I load it up in Picard or EasyTag or another command line utility to adjust the tags, and then run:

$ organizemusic ~/Downloads/some-silly-m4a-directory

And presto, all the music is moved into the right place.

It takes care of translating difficult non ASCII character into correct transliterations using libicu and uses KDE Scott Wheeler’s taglib for the audio file tag reading.

Get it while it’s hot! You can browse the source here, look at the readme here, or clone and build it like this:

zx2c4@Dell ~ $ git clone http://git.zx2c4.com/music-file-organizer
Cloning into 'music-file-organizer'...
zx2c4@Dell ~ $ cd music-file-organizer/
zx2c4@Dell ~/music-file-organizer $ make
g++ -O3 -pipe -fomit-frame-pointer -march=native -I/usr/include/taglib    -ltag -licui18n -licuuc -licudata    readmusictags.cpp AudioFile.cpp AudioFile.h   -o readmusictags
g++ -O3 -pipe -fomit-frame-pointer -march=native -I/usr/include/taglib    -ltag -licui18n -licuuc -licudata    organizemusic.cpp AudioFile.cpp AudioFile.h   -o organizemusic
August 20, 2012 · [Print]

19 Comments to “Simple Command-line Music File Organizer”

  1. a few says:

    1) this uses GNU make instead of a free version of make or POSIX make. unfortunate, but common.

    2) this build only works with gcc, not clang.

    3) the default build is completely and utterly undebuggable, does -fomit-frame-pointer actually give you a speed increase here?

    4) you don’t use a terminal database the color escape codes, instead you hard code one specific set of escape codes which may not even be correct

    5) curious if you tested your program on a BSD (or a mac)

    • > 1) this uses GNU make instead of a free version of make or POSIX make. unfortunate, but common.

      I really couldn’t care less about this.

      > 2) this build only works with gcc, not clang.

      Send me patches.

      > 3) the default build is completely and utterly undebuggable, does -fomit-frame-pointer actually give you a speed increase here?

      Yes. The default build is a release build. If you want a debug build, just run CXXFLAGS=”-g” make instead. You’ll notice I use the ?= operator.

      > 4) you don’t use a terminal database the color escape codes, instead you hard code one specific set of escape codes which may not even be correct

      Correctamundo. Do I care? No. Is this a problem for you? If so, send patches.

      > 5) curious if you tested your program on a BSD (or a mac)

      No, I don’t care about the Macintosh. And, I don’t do music organization on any of my OpenBSD installs. Test yourself and send patches?

    • Jan says:

      Interesting how you say “this uses GNU make instead of a free version of make”. Isn’t GNU Make free (as in freedom and as in price) enough for you? xD

  2. afdosd says:

    The transliteration puts me of. It seems to make this impractical for anything that isn’t american music

    • Jason says:

      Actually, the transliteration is there specifically for music that isn’t american. Many file systems choke on odd characters, and so this cleans it up while still keeping the sounds of the letters that it replaces.

      • afdosd says:

        I never had any problem with my anime and j-pop music and japanese filenames over various different filesystems. Even on my 6 years old mobile player with the even older FAT32 it works just fine.

        I know its your program and I don’t want to tell you what to do, but in my opinion its time to step it up, its the 21st century already and we should assume everything worth using is unicode aware by now

        • Jason says:

          I have faced significant problems, especially with the cyrillic alphabet.

          Your tone is rather ridiculous — “I don’t want to tell you what to do” — “step it up” — because the transliteration actually requires additional code, which means not having transliteration doesn’t mean “step[ing] it up”, but rather, trivially removing or modifying a line of code in the program.

          Here, I’ll even give you a quick way of doing it:

          Replace this:

          Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:^ASCII:] Remove; [\\:;*?\"|\\\\] Remove

          With this:

          [\\:;*?\"|\\\\] Remove

          Now please, get off my lawn.

  3. eliasp says:

    If you’re looking for a CLI tool to do this, there’s the really powerful, but yet simple to use ‘beets’:

    http://beets.radbox.org/

    • Jason says:

      Looks extremely nice and powerful, though a little bloated. I’ll have to give it a try though. One thing I’m always skeptical about these auto-taggers is that the metadata in the cloud isn’t always perfect — release dates of CDs instead of original record release dates, etc, and so I’m not a fan of the auto-correction, preferring to manually review everything. But maybe beets has a good way to handle this too; I’m not sure. In any case, thanks for the suggestion.

  4. Ryan Rix says:

    Thanks Jason, this is very nice and easy to use.

  5. Darrin says:

    Check out “Timid” mode (the -t option). No changes made until you tell Beets to apply them.

  6. Martin C. says:

    Hey, a logfile would be very handy :)

  7. Alex Rossie says:

    Swish,
    Very useful for turning my iTunes “consolidated” (urgh) library back to something with sane file structure and nomenclature.

  8. Pablo says:

    Hey, if you do the tagging with Picard, why not also use the “move files” option it has[1]? I’ve been using it for years and it works like a charm.

    [1] http://wiki.musicbrainz.org/MusicBrainz_Picard/Documentation/Options#Moving_files

  9. please unblock this! i don’t have a way to listen to music except for this!

  10. Caleb says:

    I can’t compile without the file icu-i18n.pc, which I haven’t been able to find in the Ubuntu repositories or anywhere accessible online. Is it easy to remove this dependency / is there an easy way to obtain this icu-i18n.pc file?

Leave a Reply