Left and Write
Home MIDI Lyrics Bio Links Contact Guestbook
This Page Courtesy of: Left and Write.com

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 To use the file 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
'------------------------------------------------------------------------------



Talk Back

Be the first to talk back on this story.

Name
Subject
Opinion
Home MIDI Lyrics Bio Links Contact Guestbook
Courtesy of: LeftAndWrite.com