With about 11,000 MP3 files, I need to keep them organized – making sure the metadata is correct and arranging them into a logical folder structure. My first problem was that I had a single folder with hundreds of MP3s files that I purchased from Amazon but I wanted them all to be placed into folders depending on the Album Artist.
Fortunately this was made simple by a great library called TagLib#. The compile the library from the TagLib# source on github. Or, more simply just download precompiled binaries from here.
Below is the IronPython code I used to get this done. It isn’t particularly robust, but it did the job for me in just a few seconds.
folder = r"X:\music"
files= System.IO.Directory.GetFiles( folder, "*mp3" )
def fixname(s) :
s = s.replace("\"","-")
for f in files :
with TagLib.File.Create(f) as tagfile:
artists = tagfile.Tag.AlbumArtists
if (len(artists)<1) : continue
artist_folder = System.IO.Path.Combine(folder, fixname(artist) )
if (not System.IO.Directory.Exists(artist_folder)) :
dest_filename = System.IO.Path.Combine(artist_folder, System.IO.Path.GetFileName(f))
System.IO.File.Move( f, dest_filename )