Lame.vbs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ' lame.vbs WindowsScript wrapper v0.5, 06/15/2001
  2. ' $id$
  3. '
  4. ' *Purpose*
  5. ' Use this WindowsScript to encode WAVs using drag&drop:
  6. ' 0. make sure you have windows script host v5.1 on your system
  7. ' (enter 'cscript' in a DOS-Box and compare version number)
  8. ' 1. adjust the path settings below to fit your needs
  9. ' 2a. put this file somewhere on the desktop
  10. ' 3a. drag one or more wav-files on the icon and watch them being lamed.
  11. '
  12. ' 2b. start->execute, enter "sendto", drag the script or a link to it in
  13. ' sendto window (adjust names and icon as you like)
  14. ' 3b. select wave-file(s) and send it via the send-to menu to LAME!
  15. '
  16. ' You may wish to create copies of this file with different options set.
  17. '
  18. ' If you would like a GUI: try to enable the HTML UI (see below)
  19. '
  20. ' Ralf Kempkens, ralf.kempkens@epost.de
  21. '
  22. '
  23. ' *History*
  24. ' V0.5 * lame.vbs will automatically decode if the file has a .mp3 extension
  25. ' * now explicitly refuses to accept folders
  26. ' V0.4 * creates single .mp3 extensions, now ID3 options in HTML interface
  27. ' V0.3 * fixed bug that prevented lame.exe to be located in a path that
  28. ' contained a space
  29. ' * experimental HTML UI support (disabled by default)
  30. ' V0.2 added multiple file support
  31. ' V0.1 initial release
  32. ' *** change path to your needs ***
  33. path = "D:\Audio\Lame\Lame386\" '!!! must end with a backslash !!!
  34. lame = "lame.exe"
  35. ' *** change default options to your needs ***
  36. opts = "--preset hifi"
  37. ' *** HTML GUI (experimental) ***
  38. useGUI = False
  39. ' it set to True, opens file lameGUI.html residing in the same path as lame.exe
  40. ' to choose options. Please look at the example HTML-file for further information.
  41. ' no changes needed below this line
  42. ' ##########################################################################
  43. Dim wsh, args, infile, fs
  44. title="LAME Script"
  45. ' get input files
  46. Set wsh = WScript.CreateObject("WScript.Shell")
  47. Set args = WScript.Arguments
  48. If args.Count = 0 Then
  49. MsgBox "LAME mp3 encoder/decoder frontend script." & vbCR & _
  50. "Please use drag & drop to specify input files.", vbInformation, title
  51. WScript.Quit
  52. End If
  53. ' check path
  54. Set fso = CreateObject("Scripting.FileSystemObject")
  55. If Not fso.FileExists(path & lame) Then
  56. MsgBox "Could not find LAME!" & vbCR & "(looked for '" & path & lame & "')", vbCritical, title
  57. WScript.Quit
  58. End If
  59. ' start GUI
  60. if useGUI Then
  61. set ie=WScript.CreateObject("InternetExplorer.Application", "ie_")
  62. ie.navigate(path & "lameGUI.html")
  63. do
  64. WScript.Sleep 100
  65. loop until ie.ReadyState=4 'wait for GUI
  66. ie.Width=640
  67. ie.Height=600
  68. ie.Toolbar=false
  69. ie.Statusbar=false
  70. ie.visible=true
  71. 'link to GUI
  72. set document=ie.document
  73. document.forms.lameform.okbutton.onClick=GetRef("okbutton")
  74. 'wait for user pressing ok...
  75. do
  76. WScript.Sleep 300
  77. loop until process
  78. end if
  79. 'process files
  80. For i = 0 To args.Count-1
  81. infile = args(i)
  82. ' check input file
  83. If fso.FolderExists(infile) Then
  84. MsgBox "'" & infile & "' is a folder!" & vbCR & _
  85. title & " only handles proper files.", vbInformation, title
  86. Else
  87. If Not fso.FileExists(infile) Then
  88. MsgBox "Error opening input-file" & vbCR & "'" & infile & "'", vbCritical , title
  89. Else
  90. ' run lame
  91. If(LCase(getExtension(infile))="mp3") Then 'decode
  92. ret = wsh.Run(Chr(34) & path & lame & CHR(34) & " --decode " & _
  93. Chr(34) & infile & Chr(34) & Chr(32) & Chr(34) & _
  94. getBasename(infile) & ".wav" & Chr(34), 1, True)
  95. Else ' encode
  96. ret = wsh.Run(Chr(34) & path & lame & CHR(34) & Chr(32) & opts & Chr(32) & _
  97. Chr(34) & infile & Chr(34) & Chr(32) & Chr(34) & _
  98. getBasename(infile) & ".mp3" & Chr(34), 1, True)
  99. End If
  100. ' diagnostics
  101. Select Case ret
  102. Case (0) 'okeydokey
  103. Case (-1)
  104. MsgBox "LAME aborted by user!", vbExclamation, title
  105. Case (1)
  106. MsgBox "Error returned by LAME!" & vbCR & "(Check LAME options and input file formats.)" & vbCR & "Used Options: " & opts, vbCritical, title
  107. Case Else
  108. MsgBox "Received unknown LAME return-code: " & ret, vbCritical, title
  109. End Select
  110. End If
  111. End If
  112. Next
  113. WScript.Quit
  114. ' *******************************************************************
  115. ' utility functions
  116. Function getBasename(filespec)
  117. Dim fso
  118. Set fso = CreateObject("Scripting.FileSystemObject")
  119. Set f = fso.GetFile(filespec)
  120. getBasename = f.ParentFolder & "\" & fso.GetBaseName(filespec)
  121. End Function
  122. Function getExtension(filespec)
  123. Dim fso
  124. Set fso = CreateObject("Scripting.FileSystemObject")
  125. Set f = fso.GetFile(filespec)
  126. getExtension = fso.GetExtensionName(filespec)
  127. End Function
  128. ' *******************************************************************
  129. ' manage link to IE HTML-interface
  130. sub okbutton
  131. 'process inputs
  132. opts=document.all.lameoptions.Value
  133. ie.Quit
  134. MsgBox "LAME options:" & vbCR & opts, vbInformation, title
  135. end sub
  136. sub ie_onQuit
  137. process=True
  138. end sub
  139. 'eof