How To Easily Generate Your Own WinAmp M3U Playlists
| Author: | Brian Dill |
|
| Created: | 2003-02-11 |
| Updated: | 2003-02-11 |
| Show Until: | 2003-04-30 |
Have you ever wanted a quick and easy way to generate WinAmp playlists? We now you can.
To setup the file
- Copy the code below and paste it into Notepad.
- Save it as "Generate WinAmp M3U.vbs" anywhere on your hard drive.
- Copy a shortcut of that file to your Send To folder. This is usually located at: C:\Documents and Settings\<user name>\Send To.
- Set your desired values in the area of the vbs file that says "CONFIGURE THESE VARIABLES".
To use the file
- Use WinExplorer to select files and/or folders
- Right click
- Select "Send To", then "Generate WinAmp M3U.vbs"
- Wha-la, you have a new WinAmp M3U playlist in your desired folder.
The code is pretty well documented, so you should be able to follow along and make any modifications that you wish.
============================== (snip below this line) ==============================
'///////////////////////////////////////////////////////////////////////////////
'// Sends selected files to and creates an M3U playlist
'// Ver: 1.0
'// Auth: Brian Dill
'// Date: 2003-02-10
'///////////////////////////////////////////////////////////////////////////////
Option Explicit
Dim FSO, sNameOfPlaylistFile, sPlaylistDir, iTotalFiles
'===============================================================================
'/// CONFIGURE THESE VARIABLES ///
'===============================================================================
'// Desired directory of your playlist files.
sPlaylistDir = "D:\Audio\MP3_Srv\_playlists"
'===============================================================================
'// Begin main execution.
Set FSO = createobject("Scripting.FileSystemObject")
VerifyArgsExist
sNameOfPlaylistFile = InputBox("Enter desired name of playlist file. " _
+ "Do not include extension.", "Enter name", "New Playlist")
WriteM3UFile GetFileNames
MsgBox iTotalFiles & " files added to: " & vbCrLf & vbCrLf & GenerateFileName _
,vbInformation, "Script Complete"
Set FSO = nothing
'// End of execution.
'------------------------------------------------------------------------------
'// MAIN SUBS / FUNCTIONS //
'------------------------------------------------------------------------------
'// Desc: Outputs the results to a text file.
Sub WriteM3UFile(s)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim f
Dim strOutputFile
strOutputFile = GenerateFileName
Set f = FSO.OpenTextFile(strOutputFile, ForWriting, True)
f.Write s
f.Close
End Sub
'------------------------------------------------------------------------------
'// Desc: Loops through the files/folders dropped onto the vbs file.
'// If it is a folder, it grabs all files in that folder, but
'// does not recurse.
Function GetFileNames()
Dim i, CurrObj, oFolder, colFiles, f, sResult
For i = 0 to WScript.Arguments.Length - 1
'// Fixes the Windows bug which swaps the first and last items in a selection.
If i = 0 Then
CurrObj = WScript.Arguments(WScript.Arguments.Length - 1)
ElseIf i = WScript.Arguments.Length - 1 Then
CurrObj = WScript.Arguments(0)
Else
CurrObj = WScript.Arguments(i)
End If
If FSO.FolderExists(CurrObj) Then
'// Get all files in that folder.
Set oFolder = FSO.GetFolder(CurrObj)
Set colFiles = oFolder.Files
For each f in colFiles
If IsValidFileType(f.name) Then
sResult = sResult + f.path + vbCrLf
iTotalFiles = iTotalFiles + 1
End If
Next
Else
'// Get that file
If FSO.FileExists(CurrObj) Then
Set f = FSO.Getfile(CurrObj)
If IsValidFileType(f.name) Then
sResult = sResult + f.path + vbCrLf
iTotalFiles = iTotalFiles + 1
End If
End If
End If
Next
GetFileNames = sResult
End Function
'------------------------------------------------------------------------------
'// SUPPORTING SUBS / FUNCTIONS //
'------------------------------------------------------------------------------
'// Desc: Verifies that files/folders were dragged/dropped onto the vbs file.
Sub VerifyArgsExist()
If WScript.Arguments.Length = 0 Then
MsgBox "No files or folders were dropped onto the script." _
+ vbCrLf & vbCrLf + "Script terminated.", vbExclamation _
, "Script Terminated"
WScript.Quit
End If
End Sub
'------------------------------------------------------------------------------
'// Desc: Gets the file extension.
Function GetFileExt(s)
Dim iLastDot
iLastDot = InStrRev(s, ".")
If iLastDot = 0 Then
GetFileExt = ""
Else
GetFileExt = Mid(s, iLastDot + 1)
End If
End Function
'------------------------------------------------------------------------------
'// Desc: Returns the current date in the ISO standard format.
Function GetISODate()
Dim sMonth, sDay
sMonth = Month(Now())
sDay = Day(Now())
If sMonth < 10 Then sMonth = "0" & sMonth
If sDay < 10 Then sDay = "0" & sDay
GetISODate = Year(Now()) & "-" & sMonth & "-" & sDay
End Function
'------------------------------------------------------------------------------
'// Desc: Determines if the file is a valid WinAmp supported file.
Function IsValidFileType(f)
If LCase(GetFileExt(f)) = "mp3" _
Or LCase(GetFileExt(f)) = "wav" _
Or LCase (GetfileExt(f)) = "mid" Then
IsValidFileType = True
Else
IsValidFileType = False
End If
End Function
'------------------------------------------------------------------------------
'// Desc: Simple concatenation of path and filename of output M3U file.
Function GenerateFileName()
GenerateFileName = sPlaylistDir + "\" + sNameOfPlaylistFile + "_" _
+ GetISODate + ".m3u"
End Function
'------------------------------------------------------------------------------