Friday, December 18, 2009

Set mp3 track names based on filename

A quick and dirty script I used to set mp3 track names based on file name for a given directory. Uses python and the id3v2 tagging tool. I didn't bother with album, artist, genre etc. because you can already use id3v2 to set them en-masse.

#!/usr/bin/env python

import glob
import os.path
import os
import re
import sys

list = glob.glob(os.path.join(sys.argv[1],"*.mp3"))
for thisfile in list:
track = re.sub("^[0-9]+(\s|\.|\-)+","",os.path.basename(thisfile))
track = track.replace(".mp3","")
print("/usr/bin/id3v2 -t \"%s\" \"%s\"" % (track,thisfile))
os.system("/usr/bin/id3v2 -t \"%s\" \"%s\"" % (track,thisfile))

No comments: