Postby gmontag451 » 28 Mar 2019 11:56
This is an old thread, but still very useful! I have made some simple tweaks to MediaManiac's code so that it will properly preserve the original file's naming and .flac extension, as well as update the wav and mp3 file names. Also, if you only want to create wav files, search the code for 3 sections marked with an asterisk and comment out the proper lines. Thanks to MediaManiac for a great script, which I never could have figured out on my own. (There are still some rare characters which will cause the script to fail, so if anyone knows how to use the Replace routine to replace filename characters outside the range accepted by VLC, please let us know!)
'--- Start Code ---
'CHECK YOUR VLC.EXE PATH AND UPDATE THE TWO SECTIONS BELOW!
'On Error Resume Next
Set objArgs = WScript.Arguments
Set objFSo = CreateObject("Scripting.FileSystemObject")
For Each strInputFileName in objArgs
'---------------------------------------------
'added these 2 lines to preserve filename for wav and mp3:
strOrigWavName = Left(strInputFileName,InstrRev(strInputFileName,".")) & "wav"
strOrigMP3Name = Left(strInputFileName,InstrRev(strInputFileName,".")) & "mp3"
'---------------------------------------------
strTempFileName = Left(strInputFileName,InstrRev(strInputFileName,".")) & "tmp"
'Removing special characters from filename (VLC fails id ' or , in filename)
strTempFileName = Replace(strTempFileName,",","-")
strTempFileName = Replace(strTempFileName,"'","^")
strWaveFileName = Left(strTempFileName,InstrRev(strTempFileName,".")) & "wav"
strOutputFileName = Left(strTempFileName,InstrRev(strTempFileName,".")) & "mp3"
objFSO.MoveFile strInputFileName ,strTempFileName
Set objShell = CreateObject("WScript.Shell")
'Stage 1: convert to wav
CommandLine = ""
'CHECK YOUR VLC.EXE PATH AND UPDATE THE LINE BELOW!
CommandLine = CommandLine & """C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"" "
CommandLine = CommandLine & """" & strTempFileName & """ "
'CommandLine = CommandLine & " --intf dummy --aout=audiofile --audiofile-format=s16 --audiofile-channels=2"
CommandLine = CommandLine & " --aout=audiofile --audiofile-format=s16 --audiofile-channels=2"
CommandLine = CommandLine & " --audiofile-file="""
CommandLine = CommandLine & strWaveFileName
CommandLine = CommandLine & """ vlc://quit"
objShell.Run CommandLine,,True
'----------------------------------------------
'Stage 2: Convert to MP3.
'*Comment out Stage 2 to skip mp3 creation:
CommandLine = ""
'CHECK YOUR VLC.EXE PATH AND UPDATE THE LINE BELOW!
CommandLine = CommandLine & """C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"" "
CommandLine = CommandLine & """" & strWaveFileName & """ "
CommandLine = CommandLine & " --sout=#transcode{acodec=mp3,ab=192,vcodec=dummy}:standard"
CommandLine = CommandLine & "{access=file,mux=raw,dst="""
CommandLine = CommandLine & strOutputFileName
CommandLine = CommandLine & """} vlc://quit"
objShell.Run CommandLine,,True
'End of Stage 2.
'----------------------------------------------
'*Must choose between wav and mp3:
'--------------------------------------
'uncomment when creating mp3 file/comment out when creating only wav:
Set Outfile = objFSO.GetFile(strOutputFileName)
'--------------------------------------
'uncomment when creating only wav file/comment out when creating mp3:
'Set Outfile = objFSO.GetFile(strWaveFileName)
'--------------------------------------
'msgbox("File Size: " & Outfile.size )
If Outfile.size <> 0 Then
'Remove below comment marks to auto delete .flac and/or .wav file after .mp3 creation:
'uncomment to delete flac file:
'objFSO.DeleteFile strTempFileName
'uncomment to delete wav file:
'objFSO.DeleteFile strWaveFileName
'--------------------------------------
'This section restores the filename formatting and flac extension.
'If the mp3 section above is commented out, also comment out the mp3 section below
'Restores "'" and "," in tmp filename, changes back to flac:
objFSO.MoveFile strTempFileName, strInputFileName
'Restores "'" and "," in wav filename:
objFSO.MoveFile strWaveFileName, strOrigWavName
'Restores "'" and "," in mp3 filename (*comment out if creating only wav files):
objFSO.MoveFile strOutputFileName, strOrigMP3Name
'--------------------------------------
Else
objFSO.MoveFile strTempFileName, strInputFileName
End If
Next
'--- End Code ---