Okay, so this has nothing to do with federated infrastructure. However, occasionally, I come across something worth preserving so I wanted to make sure I wrote it down. The hat tip here really goes to Antonin Foller (http://www.motobit.com/tips/detpg_list-id3-tags-script/), but I did make some modifications to his code to make it easier for my specific situation.
The goal of this script is to extract the ID3 meta data from my entire MP3 collection so that I can use it to ensure consistency (of artist name and genre mostly) as well as use the information for generating playlists that follow certain prescriptions like those used in formatted radio (ensuring that the same artist isn't played twice in the same hour, etc.). The script contains two sub-procedures and a very generic main procedure.
To run the script, I use the command prompt (cscript) and redirect the output to a txt file.
Sub ListID3TagsFS(Root)Dim SubFolder, File '*** enumerate all files In the folderFor Each File In Root.Files Select Case LCase(Right(File.Name, 4)) Case ".mp3" ListID3TagsFile File End SelectNext
'*** process all subfoldersFor Each SubFolder In Root.SubFolders ListID3TagsFS SubFolderNext
End Sub
Sub ListID3TagsFile(File)'*** Get id3 object To change dataDim id3Set id3 = CreateObject("CDDBControl.CddbID3Tag")
'*** load id3 data from a file, read onlyid3.LoadFromFile File.Path, True '*** print some of id3 tagsWScript.Echo File.Path & chr(9) & id3.LeadArtist & Chr(9) & id3.Title & Chr(9) & id3.Album & Chr(9) & id3.Year & Chr(9) & id3.Genre
'******************************************************************'*** Main Procedure ***'******************************************************************'*** Get Argumentsset oArgs = wscript.argumentssFolder = oArgs(0)
'*** get FileSystemObject To enumerate filesDim oFSSet oFS = CreateObject("Scripting.FileSystemObject")
'*** call ListID3TagsFS Function with a folder objectListID3TagsFS oFS.GetFolder(sFolder)
The output of the script is a single text file (tab delimited) that contains the entire MP3 collection. This can be edited in Excel or Access for consistency and used as an input file for the following script that will individually update each MP3 file (note however, that Excel will add quotes to some of these fields if saved as a text file - tab delimited. I found it better to actually copy the entire spreadsheet and paste it into notepad to get a "clean" text file for input. Once the output file has been cleaned up, the following script can be used to read the information from the output file back into the individual ID3 tags.
On Error Resume Nextset oArgs = wscript.argumentssFolder = oArgs(0)
'*** get FileSystemObject To enumerate filesDim oFSSet oFS = CreateObject("Scripting.FileSystemObject")Set iFile = oFS.OpenTextFile(sFolder, 1)
Do Until iFile.AtEndofStream
LineA = iFile.Readline Values = Split(LineA, Chr(9)) EditID3Tags Values(0), Values(1), Values(2), Values(3)Loop
Sub EditID3Tags(File,Artist,SongTitle,Album)'*** Get id3 object To change dataDim id3Set id3 = CreateObject("CDDBControl.CddbID3Tag")
'*** load id3 data from a file, read onlyid3.LoadFromFile File, True '*** Save the id3 tagsid3.Album = Albumid3.Title = SongTitleid3.LeadArtist = Artist
id3.SaveToFile FileIf Err <> 0 Then wScript.Echo "Error: " & Artist & ": " & SongTitle & "[" & Album & "]" Err.ClearElse wscript.echo "Completed " & Artist & ": " & SongTitle & "[" & Album & "]"End If