' Music Tagger
' Written by Dan Wheeler
' 3/22/04
'
' Purpose/Description:
' Due to the unusual way Windows Media Player (and consequently Media Center)
' allows you to browse and listen to music I found it necessary to write a
' script that gives me a little more control over my collection's metadata.
' Most people already organize their music by GENRE-ARTIST-ALBUM-SONG using a
' folder structure. This script makes sure each song's metadata matches it's
' place in the folder structure. This is something that could be run nightly or
' weekly to make sure any changes you make to the file/folder structure are
' also applied to the metadata.
'
' After running this script you will need to ask Windows Media Player to go
' out and find all your music again. This is tedious and I am currently looking
' for ways to write directly to the Windows Media Player WMDB file or automate
' the re-discovery process. You may find that it is easiest to delete the
' Windows Media library database file which is usually located here:
' C:\Documents and Settings\yournamehere\Local Settings\Application Data\Microsoft\Media Player
' then open media player and re-discover all your music files.
'
' How it works:
' This script will enumerate through a folder specified below (strPath)
' and search for GENRE folders that start with an underscore. (ie "Rock")
' It will then search through each GENRE folder looking for ARTISTS.
' Next it look through each ARTIST folder and look for SONGS that dont
' belong to any particular ALBUM. Next it will look for ALBUM subfolders
' in the ARTIST folder and find SONGS.
'
' EXAMPLE:
'
' 70s (GENRE / folder)
' Led Zeppelin (ARTIST / folder)
' Rain Song (SONG / file)
' In Through the Out Door (ALBUM / folder)
' Kashmir (SONG / file)
'
' Rain song will be tagged like so:
'
' GENRE: 70s
' ARTIST: Led Zeppelin
' ALBUMARTIST: Led Zeppelin (this is used by Media Center when viewing albums)
' ALBUM: Led Zeppelin - Various
'
' Kashmir will be tagged like so:
' GENRE: 70s
' ARTIST: Led Zeppelin
' ALBUMARTIST: Led Zeppelin (this is used by Media Center when viewing albums)
' ALBUM: Led Zeppelin - In Through the Out Door
'
' This script requires METADATAEDIT.EXE which can be found in the Windows Media Format SDK
on error resume next
'************************************************************************
' VARIABLES
'************************************************************************
' Search for music here. Should contain "genre" subfolders
strPath = "d:\music"
'************************************************************************
' CREATE OBJECTS
'************************************************************************
set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
'************************************************************************
' CREATE LOG FILE
'************************************************************************
objFSO.CreateTextFile("MusicTagger.log")
set objTSO = objFSO.OpenTextFile("MusicTagger.log",2)
'************************************************************************
' RUNTIME VARIABLES
'************************************************************************
'************************************************************************
' FUNCTIONS
'************************************************************************
function funcWriteTag(Genre,Artist,Album,Title,FilePath)
wscript.echo "-----------------------------------------------------------------------------"
wscript.echo "Genre: " & Genre
wscript.echo "Artist/Band: " & Artist
wscript.echo "Album: " & Album
wscript.echo "Title: " & Title
wscript.echo "Date Accessed: " & FilePath.DateLastAccessed
'echo's commands to screen
'wscript.echo "metadataedit.exe """& FilePath &""" set 0 WM/Genre 1 """& Genre &""""
'wscript.echo "metadataedit.exe """& FilePath &""" set 0 Author 1 """& Artist &""""
'wscript.echo "metadataedit.exe """& FilePath &""" set 0 WM/AlbumArtist 1 """& Artist &""""
'wscript.echo "metadataedit.exe """& FilePath &""" set 0 WM/AlbumTitle 1 """& Album &""""
'echo's Genre/Artist/Album/Song info to log file
objTSO.WriteLine("-----------------------------------------------------------------------------")
objTSO.WriteLine("Genre: " & Genre)
objTSO.WriteLine("Artist/Band: " & Artist)
objTSO.WriteLine("Album: " & Album)
objTSO.WriteLine("Title: " & Title)
objTSO.WriteLine("Date Accessed: " & FilePath.DateLastAccessed)
'echo's commands to log file
objTSO.WriteLine("Command Run: metadataedit.exe """& FilePath &""" set 0 WM/Genre 1 """& Genre &"""")
objTSO.WriteLine("Command Run: metadataedit.exe """& FilePath &""" set 0 Author 1 """& Artist &"""")
objTSO.WriteLine("Command Run: metadataedit.exe """& FilePath &""" set 0 WM/AlbumArtist 1 """& Artist &"""")
objTSO.WriteLine("Command Run: metadataedit.exe """& FilePath &""" set 0 WM/AlbumTitle 1 """& Album &"""")
'wscript.echo "File is fresh - modify it"
objShell.Run("metadataedit.exe """& FilePath &""" set 0 WM/Genre 1 """& Genre &""""),0,True
objShell.Run("metadataedit.exe """& FilePath &""" set 0 Author 1 """& Artist &""""),0,True
objShell.Run("metadataedit.exe """& FilePath &""" set 0 WM/AlbumArtist 1 """& Artist &""""),0,True
objShell.Run("metadataedit.exe """& FilePath &""" set 0 WM/AlbumTitle 1 """& Album &""""),0,True
'end if
end function
'************************************************************************
' FILE/FOLDER ENUMERATION
'************************************************************************
' ENUMERATE GENRES
set oRootFolder = objFSO.GetFolder(strPath)
if err.number <> 0 then
strPath = InputBox(UCase(strPath) &" is not a valid path. Where would you like Music Tagger to search for music?","Path to Music Files (i.e. D:\Music)",UCase(strPath), 100, 100)
set oRootFolder = objFSO.GetFolder(strPath)
err.clear
end if
For Each GenreFolder in oRootFolder.SubFolders
' DEFINE THE GENRE
strGenre = GenreFolder.name
' ENUMERATE ARTISTS
For Each ArtistFolder in GenreFolder.SubFolders
strArtist = ArtistFolder.name
' ENUMERATE SONGS IN ROOT ARTIST FOLDER WITH NO PARTICULAR ALBUM
For Each VariousFile in ArtistFolder.files
If VariousFile.Attributes AND 32 Then
strVariousAlbum = ArtistFolder.Name & " - Various"
strExtension = right(UCase(VariousFile.Name),3)
if strExtension = "WMA" or strExtension = "MP3" then
funcWriteTag strGenre,strArtist,strVariousAlbum,VariousFile.name,VariousFile
' turns off the archive bit
Wscript.Echo "Turning off archive bit for "& VariousFile.Name
VariousFile.Attributes = 0
end if
else
wscript.echo "-----------------------------------------------------------------------------"
wscript.echo "Skipping "& VariousFile.Name &". Archive bit not set."
end if
Next
' ENUMERATE ALBUMS
For Each AlbumFolder in ArtistFolder.SubFolders
' ENUMERATE SONGS THAT BELONG TO A SPECIFIC ALBUM
For Each AlbumFile in AlbumFolder.files
If AlbumFile.Attributes AND 32 Then
strAlbum = ArtistFolder.Name &" - "& AlbumFolder.name
strExtension = right(UCase(AlbumFile.Name),3)
if strExtension = "WMA" or strExtension = "MP3" then
funcWriteTag strGenre,strArtist,strAlbum,AlbumFile.name,AlbumFile
' turns off the archive bit
Wscript.Echo "Turning off archive bit for "& AlbumFile.Name
AlbumFile.Attributes = 0
end if
else
wscript.echo "-----------------------------------------------------------------------------"
wscript.echo "Skipping "& AlbumFile.Name &". Archive bit not set/"
end if
Next
Next
Next
if err.number <> 0 then
wscript.echo "Music Tagger Error: " & err.description
err.clear
end if
Next
objTSO.close