2

I have a few thousand MP3 files nested in folders which I would like to bulk rename.

The files currently have the following naming convention:

"tracknumber_artistname_-_songname_MP3COLLECTION.mp3"

For example:

"01_Michael_Jackson_-_Wanna_Be_Startin'_Something_MP3COLLECTION.mp3"

However, I would like to reorganise these files by moving the artist name after the song name, removing the cruft at the end and by replacing all underscores with spaces, resulting in the above convention and example resulting like this:

"tracknumber songname - artistname.mp3"
"01 Wanna Be Startin' Something - Michael Jackson.mp3"

I have Bulk File renamer which gives options for Regex, but I don't know how to go about this. Any suggestions? I'm also open to using different tools or even methods if Bulk File Rename isn't the best option.

Note: I originally posted this at StackExchange, but I was advised to post this here instead due to being off topic over there.

2 Answers 2

1

In Windows? I don't know "Bulk File Renamer". I would use Total Commander's "Multi Rename" tool. Better yet, I'd probably work with perl or awk from a Cygwin terminal for a more comprehensive script solution. That would go too far for here though. Just from a regex perspective, this works for me in TC with your filename (but only if files do not contain extra "-" or "." in the artist or song title fields), should probably work in any regex-supporting bulk rename tool without too much trouble because I don't think I used any fancy advanced RegEx stuff, like posix character classes (":digit:" and such)...

If you're using TC, you want to tick the "[E]" and the "RegEx" checkboxes, and untick the other three, in the Search & Replace part of the Multi-Rename tool. I tested this whole thing in TC myself, so please appreciate the time I took for you :) If you use another tool and it does not work, search its RegEx-related help for "backreferences" as some tools tend to use different standards for RegEx bacrefs. (It's the $1 $2 $3 etc. in my code below that refers to something in parenthesis in the search.)

NOTE If you're gonna bulk-rename, please, for the love of God, make a backup of your entire collection first. You never know. I'm not responsible, blah blah.

FIRST: make the separator in {tracknr}_{artist} "_-_" instead of the current "_". Because "_-_" seems like a useful separator that would not often accidentally appear in any normal text. Also, let's snuff out the "_{MP3COLLECTION}" part right here.

search for:   (([0-9]+)_)(.*)_(.*)(\..*)
replace with: $2_-_$3$5

Note: this assumes that you are including the file extension in the renaming process, and makes sure you retain that extension, in case you also have .ogg files or whatever. If your tool is not including the extension in the renaming process, remove the last "(\..*)" from the search, and the last $5 from the replace.

Your name now looks like: 1_-_Michael_Jackson_-_Wanna_Be_Startin'_Something.mp3

SECOND: now replace the first occurence of "_._" by " " and the second by " - ":

search for:   (.*?)_-_(.*?)_-_(.*)(\..*)
replace with: $1 $2 - $3$4

Note: Again, if your tool is not including the file extension in the process, remove the last "(\..*)" from the search and the last $4 from the replace.

Your name now looks like: 1 Michael_Jackson - Wanna_Be_Startin'_Something.mp3

THIRD AND LAST: Simply replace "_" by " ".

Your name now looks like: 1 Michael Jackson - Wanna Be Startin' Something.mp3

Good luck!

/edit: quite some precision required to make sure all these underscores are correctly displayed in this post :)

/edit 2: Afterthought. You may also want to pad the track numbers below 10 (i.e. 0-9) with a 0, so you get 01, 02, ..., 09, 10, 11 etc.. this makes sorting much easier and hugely increases chances for things like phones or MP3 players to play your tracks in the correct order. For that:

Search for:   (^[0-9] )
Replace with: 0$1
2
  • This looks like an excellent way of doing this. I'll try this tonight and will let you know. I've installed TC on my machine here, but haven't got access to the files I need to change except via FTP, and I don't want to chew up my bandwidth with such a menial task. I should add that the existing filenames are presently all two-digit padded, so I don't expect I should have to add the padding, unless something in the earlier regex has been configured to remove it, but I couldn't (albeit with my limited knowledge) see anything which seemed to suggest that.
    – LincM
    Jan 19, 2015 at 22:32
  • All my regex here is compatible with 0-padded names and will leave them intact. (([0-9]+)_) : search for ((one or more digits) followed by underscore).
    – SadBunny
    Jan 19, 2015 at 22:44
0

My first instinct is to not try to write a program or script to do this, but to use a ready-made mp3 renaming program to do it for you. There are different ones available (of varying quality) for different OS's.

Or if you're gung-ho on the renaming idea, you could use gnu tools (available in linux/unix/mac, or Cygwin) like sed or awk, or tr & cut & variables in a bash script... you'll need a standard way to separate out the fields (song, artist, track) in your filenames, if you're using a variable number of spaces in between them, with no set field separator, that would be tricky.

Here's a very very quick preliminary awk line that separates the incoming string (after _ have been translated into spaces) and prints them out in a different order, you'll have to figure out keeping the "tracknumber" at the start yourself:

$ jackstring="tracknumber_artistname-songname_MP3COLLECTION.mp3"

$ echo $jackstring 
tracknumber_artistname-songname_MP3COLLECTION.mp3

$ echo "$jackstring"|tr -s "_" " "|awk -F'[-.]' '{printf "%s-%s.%s\n", $2,$1,$3 }' 
songname MP3COLLECTION-tracknumber artistname.mp3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .