MP3 Tagging Scripts

I’ve had a need for the past couple years of an easy and flexible mp3 tagging application. I’ve downloaded and tried out several programs and they don't always do what I want them to do. So, I found a handy DLL that has the id3 tag features already built in and I wrote a couple scripts.

The first thing you’ll need is the DLL, you can find it here, it’s called CBBDControl.dll. Now, there’s several files with this same name, and only one of them works right. So if you download a cddbcontrol.dll and register it and the script gets an “ActiveX Can’t Create Object” error, then you have the wrong DLL. Either that or you're running 64 bit Windows. I have not been able to get this to run on my 64bit machine, but it works fine on my 32bit ones.

 

Update: That page is sometimes down, so you can download the DLL here.

 

This page has information on the methods and the properties of the DLL.

The next thing you need is a script. You can, of course, write your own. Or you can use one of the ones I’ve made.

Not everyone names files the same, but the id3 tags are (or should be) universal. Therefore, this script simply takes a look at the id3 tag and names the file in the format I want it.

' Names an mp3 file based on the contents of the id3 tag.

Dim id3 'As New CddbID3Tag
Set id3 = CreateObject("CDDBControl.CddbID3Tag")

ProcessFiles
Sub ProcessFiles()
    c = 1
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(".")  
    Set fc = f.Files 
    For Each f1 in fc
        If LCase(Right(f1.name,4)) = ".mp3" Then
            id3.LoadFromFile f1.name, False
            
            ' This will fix any mp3s that have the track number format
            ' of x/y instead of just x or 0x
            c = id3.trackposition
            If InStr(c, "/") <> 0 then
                c = Split(c,"/")(0)
                id3.trackposition = c
                id3.SaveToFile f1.name
            End If
            
            ' uncomment this to pad track numbers with leading 0
            if c < 10 then c = "0" & c

            ' Uncomment one of the naming methods below, or add your own

            ' Name the file 01 - artist - title.mp3
            'If f1.name <> Left(c & " - " & id3.leadartist & " - " & id3.title,190) & ".mp3" Then
            '    f1.name =  Left(c & " - " & id3.leadartist & " - " & id3.title,190) & ".mp3"
            'End If

            ' Name the file 01 - title.mp3
            If f1.name <> Left(c & " - " & id3.title,190) & ".mp3" Then
				newname = id3.title
				newname = Replace(newname, "/", "_")
				newname = Replace(newname, "\", "_")
				newname = Replace(newname, "*", "_")
				newname = Replace(newname, "&", "_")
				newname = Replace(newname, ".", "_")
				newname = Replace(newname, "?", "_")
				newname = Replace(newname, ".", "_")
				newname = Replace(newname, ":", "_")
				'wscript.echo "Old: " & f1.name
                'wscript.echo Left(c & " - " & newname,190) & ".mp3"
                f1.name =  Left(c & " - " & newname,190) & ".mp3"
            End If

        End If
    Next
    Set fso = nothing
    Set f = nothing
    Set fc = nothing
End Sub

And another script that does just the opposite:
‘ This script will tag mp3s based on the folders they are in
‘ This assumes the following format:
‘ \Artist Name\Album Name\01 – song title.mp3
‘ You can, of course, modify the script to assume your preferred sorting method.
Dim id3 ‘As New CddbID3Tag
Set id3 = CreateObject(”CDDBControl.CddbID3Tag”)
ProcessFiles
Sub ProcessFiles()
	Set fso = CreateObject(”Scripting.FileSystemObject”)
	Set f = fso.GetFolder(”.”)
	Set ff = fso.GetFolder(”..”)
	artist = ff.name
	album = f.name
	Set fc = f.Files
	For Each f1 in fc
		If LCase(Right(f1.name,4)) = “.mp3? Then
			id3.LoadFromFile f1.name, False
			track = split(f1.name, ” – “)(0)
			‘wscript.echo track
			title = split(f1.name, ” – “)(1)
			‘wscript.echo title
			id3.leadartist = artist
			id3.album = album
			id3.trackposition = track
			id3.title = title
			id3.SaveToFile f1.name
		End If
	Next
	Set ff = nothing
	Set fso = nothing
	Set f = nothing
	Set fc = nothing
End Sub

Feel free to use these scripts as you wish. If you post them on your website, please be sure to link back here.



Back to Article Index

blog comments powered by Disqus