PDA

View Full Version : Script: Adding Replay Gain to album folder of FLAC files



toolburn
12-30-2006, 10:25 PM
This is a Windows Explorer shell-integrated method for adding Replay Gain (and album art) to a folder of FLAC files. An option for "Add Replay Gain" will be available when right-clicking folders in Windows Explorer. Selecting this option will add Replay Gain and if available, album art, to the FLAC files in the folder assuming they are of the same album.

Install FLAC 1.1.3 from: http://flac.sourceforge.net (metaflac.exe file is required).
After a default installation, metaflac.exe version 1.1.3 should be in C:\Program Files\FLAC.

Two files are needed for the Replay Gain option first is a reg file to add the option to the context-sensitive (right-click) menu in Windows Explorer, second is the actual vbscript that does the work.

----------------------
ReplayGain2Menu.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\R eplayGain2Menu]
@="Add Replay Gain"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\R eplayGain2Menu\command]
@="cscript //nologo \"J:\\MusicStore\\ReplayGain2Menu.vbs\" \"%L\""
(NOTE: Problem with the forum, remove the space in 'ReplayGain2Menu' text - two places.) You will need to modify the last line to the permanent path where you place the vbscript file. IMPORTANT NOTE: backslashes that are for folders need to be double backslashes between the drive letter and the '.vbs' text.
----------------------

----------------------
ReplayGain2Menu.vbs

Dim objArgs, WshShell, MetaflacPath, MetaflacCommand, FolderPath
Dim FolderPathPic, FileMask, FileSys, FlacFiles, RunCommand, returnVersion

Set objArgs = WScript.Arguments
Set WshShell = WScript.CreateObject("WScript.Shell")

MetaflacPath = """C:\Program Files (x86)\FLAC\metaflac.exe"""
MetaflacCommand = "--add-replay-gain --preserve-modtime"
FolderPath = objArgs(0)
FolderPathPic = FolderPath & "\folder.jpg"
FileMask = "flac"

WScript.Echo "Calculating and adding Replay Gain..."

Set objWshScriptExec = WshShell.Exec(MetaflacPath & " --version")
Set objStdOut = objWshScriptExec.StdOut
returnVersion = objStdOut.ReadAll

If InStr(returnVersion, "metaflac 1.1.3") > 0 Then
Set FileSys = CreateObject("Scripting.FileSystemObject")
If FileSys.FileExists(FolderPathPic) Then
MetaflacCommand = MetaflacCommand & " --import-picture-from=""3|image/jpeg|Cover||" & FolderPathPic & """"
End If
Set FileSys = Nothing
End If

FlacFiles = DumpFileTypeList(FolderPath, FileMask)
RunCommand = MetaflacPath & " " & MetaflacCommand & " " & FlacFiles
WshShell.Run(RunCommand)

Function DumpFileTypeList(folderspec, filetype)
Dim fso, f, f1, fc, s, FileExt
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
FileExt = fso.GetExtensionName(f1)
If FileExt = filetype Then
s = s & """" & FolderPath & "\" & f1.Name & """"
s = s & " "
End If
Next
DumpFileTypeList = s
End Function
----------------------
Place the vbscript file in a permanent location. Modify the MetaflacPath variable if needed.

The vbscript will check for the proper metaflac version (1.1.3) and existence of a folder.jpg in the same folder before including album art.

Hope this helps those with existing FLAC libraries before this becomes unneeded with the new Replay Gain DSP in R12.

-Joe