Custom Action to Reorganize a Music Library using Tag Information

This post is not a direct request for help but more of a How-To. I felt the need to do this post given the number of times I've seen people request help related to moving files from one directory structure to another using existing tag information. Most of the posts I read didn't appear complete. I'm not saying that this solution is the end-all for everybody but I believe it provides the basis whereby others can modify for their own particular use. However, before moving forward, let me start with this shameless plug.

I've been a big fan of Mp3tag for many years. It's saved me countless hours tagging and organizing all of my music files (both FLAC and MP3). I've donated to Florian in the past and will again soon, especially after this 3.00 release. I encourage everybody to do the same because Florian and his team do outstanding work and the user community is the best. It costs money to host this site, for purchasing development tools and to receive such excellent support so please donate.

This is my contribution for moving all the files contained within one folder/directory structure to another and reorganized based upon music file tag information. However, before discussing this specific solution, let me provide some background information.

ASSUMPTIONS:

  • The music files of interest are contained within the following working directory: C:\Users\Scott\Music\Working
  • All of the music files in the working directory, including any sub-folders within it, are properly named and tagged.
  • In addition to being properly named and tagged, music files in sub-folders may include cover art (e.g. folder.jpg).

GOALS:

  • I want to re-organize the music files in my working directory into a new destination directory as follows: C:\Users\Scott\Music\_Reorganized\Album Artist\[Year] Album\filename.ext
  • I don't want to use the built-in Convert Filename - Tag functionality. Instead, I want to create an action group.
  • I chose an action group so that (1) it'll work for any working directory, and (2) allows adding other actions at a later date.

Yeah, I know, that was a lot of information to digest. The good news is that the solution is actually fairly simple. So let's go through the steps I performed to achieve the goals stated above.

STEPS:

  1. Using the Action menu, I created a New action group called: Reorganize Music Library (WARNING - Moves && Deletes files)
  2. I then created a New action as follows:
    Action Type: Format value
    Field: _DIRECTORY
    Format String: $cutRight(%_workingpath%,$add($len(%_workingdir%),1))\_Reorganized\%albumartist%\'['%srcyear%']' %album%\
  • Please note that I have a user-defined tag called SRCYEAR (i.e. %srcyear%) where I store the Year when a specific Album from a specific Album Artist was released. You may need to modify this tag for your given situation.
  1. Finally, save this Action in the Action Group.

USAGE:
To reorganize the music files in the working directory:

  • If you're not already in the correct working directory, from the menu select File -> Change Directory. In the pop-up dialogue box, make sure (1) the Sub-directories checkbox is checked then (2) select the working directory: C:\Users\Scott\Music\Working
  • After a moment, all of the music files should become visible on the screen.
  • On the keyboard, select all music files using the shortcut: [CTRL] [A]
  • From the menu, select Actions -> Reorganize Music Library (WARNING - Moves & Deletes files)
  • After a moment, the "Writing tag data" pop-up window will disappear
  • DO NOT CLOSE Mp3tag, yet.
  • Your reorganized files should be located here: C:\Users\Scott\Music\_Reorganized

NOTES:

  1. If the reorganized files in the new directory are not what you are expecting, go back to Mp3tag and from the keyboard, use the shortcut [CTRL] [Z] to undo the action.
  2. After executing this script, all music files in the working directory that share the same Album Artist, Year and Album tag data will be relocated into a common destination directory. Therefore, any duplicate music, cover art or other file(s) from the original working directory will require a manual confirmation to overwrite EACH duplicate that's identified in the destination directory. Be cautious when using this script on directories containing a large quantity of files.
  3. The working directory will have empty folders that need to be removed manually. That's one of the Actions I will add to the Action Group at a later date.
  4. I had to do some "trickery" to get the destination directory to work correctly. In short, %_workingpath% is the full path to the Mp3tag working directory and $cutRight(%_workingpath%,$add($len(%_workingdir%),1)) puts me in the directory above.

Well, that's my solution for reorganizing directories based upon the tag information. Admittedly, this may not be the most elegant solution but it appears to be working properly from the testing I've run on it thus far. Feel free to use or modify what I provided but remember, you assume all risks;)

I've been very busy at work so I'm pressed for time. If anybody can enhance this action group to automatically remove empty directories from the working directory, you would have my gratitude!

I realized that this post only works with music files that have already been organized into sub-directories (e.g. by Artist). If your songs are not already organized in this manner, the change listed below will organize your music files regardless if they're in sub-directories or not.

As before, this Action assumes that all the tags in the music files are valid. This should serve as a good starting point for organizing your music files. I have a more sophisticated version that includes enhanced error checking and will post it here if sufficient interest is expressed.

There are 2 things I'd like to note:

The format string

only describes the path-part. If you really want to move a file to a new folder and you modify the _FILENAME for that, you also need to add a part that describes the actual filename., e.g.
$cutRight(%_workingpath%,$add($len(%_workingdir%),1))\_Reorganize\%albumartist%\'['%srcyear%']' %album%\%_filename%

There is a standard tag field that has the same role as the user-defined tag field

that you use:

ORIGYEAR.
As not all players support user-defined fields (and just as few support all standard tag-fields) it may still be a good idea to cling to the standard.
For all other users I would recommend to use the field
YEAR.

Thank you for pointing out my error in the Format String. I was in a hurry and accidentally posted this rather than saving it as a draft. Additionally, being a newbie with scripting, I appreciate any feedback that improves my skills.

For MacOS and linux/BSD users:
This solution did not work for me on MacOS due to permission issues, but what did work is something like this:

Format Tag Field _FILENAME to
../_reorganized/%albumartist% - %album%/%track% %artist% - %title%

It seemed like mp3tag was unable to obtain the %_workingdir% or %_workingpath% string values.

If the denied permissions have their origin in the bookmarks, see this thread:

Because i'm lac on double files i use the folow:
M:\MUZIEK\$left($regexp(%artist%,^()\s'('.+')'$,$2,1),1)$left($regexp(%artist%,^()\s'('.+')'$,$2,1),1)$left($regexp(%artist%,^()\s'('.+')'$,$2,1),1)\%artist%\%artist% - %title%

you can change M:\MUZIEK\ to your needs.

And all my music have the alphabet like Maps AAA, BBB, CCC... then ARTIST folders with ARTIST - TITLE.mp3

Instead of writing your first letter producing $left command 3 times (to get - for example LLL - ), you could just wrap it into 1 $repeat as this:
$repeat($left($regexp(%artist%,^()\s'('.+')'$,$2,1),1),3)\%artist%\%artist% - %title%

From the documentation:
image