I was in need of a script that could send any possible selection of tracks to Winamp (or another music program) fast.
Searching the forum I didn't found any script that could do that so I built my own.
It also contains code you can use to easily export a track selection list to a specified M3U file as playlist.
Hopefully some of you find this handy.
Cheers
Steegy
Code: Select all
'==========================================================================
'
' MediaMonkey Script
'
' NAME: ExportM3UAndPlayInWinamp v1.0
' DESCRIPTION:
' Exports selected tracks (tracks and full nodes) to a temporary M3U playlist
' and then plays or enqueues that playlist in Winamp (or some other program).
' It basically does the same thing as the SendToWinamp script but it also works
' for larger selections (fixed Winamp crashing).
'
' You can use the sub ExportM3U(mySongList, myExportPath) in your own scripts
' since I haven't seen any such (useful) script on the forum that works.
' Please mention where you got it from, if you use it.
'
' Buttons are added for "Play in Winamp" and "Enqueue in Winamp" in the context menu's
' (tracks, nodes, now playing) and to the standard toolbar.
'
' AUTHOR: Steegy aka RC
' DATE : 22.11.2005
'
' NOTE: Based on FurAnt's M3U Export script and Kyle White's SendToWinamp script.
'
' By adding a file dialog, you can easily change this script to export the selected
' tracks to a file that you specify using a "save as" dialog.
'
' INSTALL:
' - If wanted, change defaults in the "Variable Configuration" sections of this file
' - Copy script to MM directory scripts\auto
'
'==========================================================================
Dim WinampEXE, tempM3UPath, lcPlayInWinamp, lcAddInWinamp, lcExportingToM3U, lcNothingToSend
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Variable Configuration: Change this if necessary
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
WinampEXE = Chr(34)&"c:\Program Files\Winamp\Winamp.exe"&Chr(34)
tempM3UPath = "c:\\mmExportM3UTemp.m3u"
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Variable Configuration: Localise this if necessary
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' Dutch Localisation ;)
'lcPlayInWinamp = "Afspelen in Winamp"
'lcAddInWinamp = "Toevoegen in Winamp"
'lcExportingToM3U = "Exporteren naar M3U ..."
'lcNothingToSend = "Er is niets geselecteerd om naar Winamp te verzenden."
lcPlayInWinamp = "Play in Winamp"
lcAddInWinamp = "Enqueue in Winamp"
lcExportingToM3U = "Exporting to M3U file ..."
lcNothingToSend = "There are no songs to send."
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Here's the code
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
Sub onStartUp
SDB.UI.AddMenuItemSep SDB.UI.Menu_Pop_TrackList,0,0
Dim POPSWinamp
Set POPSWinamp = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_TrackList,0,0)
POPSWinamp.Caption = lcPlayInWinamp
POPSWinamp.OnClickFunc = "kwPlayWinamp"
POPSWinamp.UseScript = Script.ScriptPath
POPSWinamp.IconIndex = 13
Dim POPSPreview
Set POPSPreview = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_TrackList,0,0)
POPSPreview.Caption = lcAddInWinamp
POPSPreview.OnClickFunc = "kwEnqueueWinamp"
POPSPreview.UseScript = Script.ScriptPath
POPSPreview.IconIndex = 24
SDB.UI.AddMenuItemSep SDB.UI.Menu_Pop_NP,0,0
Dim POPSWinamp2
Set POPSWinamp2 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_NP,0,0)
POPSWinamp2.Caption = lcPlayInWinamp
POPSWinamp2.OnClickFunc = "kwPlayWinamp"
POPSWinamp2.UseScript = Script.ScriptPath
POPSWinamp2.IconIndex = 13
Dim POPSPreview2
Set POPSPreview2 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_NP,0,0)
POPSPreview2.Caption = lcAddInWinamp
POPSPreview2.OnClickFunc = "kwEnqueueWinamp"
POPSPreview2.UseScript = Script.ScriptPath
POPSPreview2.IconIndex = 24
SDB.UI.AddMenuItemSep SDB.UI.Menu_Pop_Tree,0,0
Dim POPSWinamp3
Set POPSWinamp3 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,0,0)
POPSWinamp3.Caption = lcPlayInWinamp
POPSWinamp3.OnClickFunc = "kwPlayWinamp"
POPSWinamp3.UseScript = Script.ScriptPath
POPSWinamp3.IconIndex = 13
Dim POPSPreview3
Set POPSPreview3 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,0,0)
POPSPreview3.Caption = lcAddInWinamp
POPSPreview3.OnClickFunc = "kwEnqueueWinamp"
POPSPreview3.UseScript = Script.ScriptPath
POPSPreview3.IconIndex = 24
SDB.UI.AddMenuItemSep SDB.UI.Menu_TbStandard,0,0
Dim POPSWinamp4
Set POPSWinamp4 = SDB.UI.AddMenuItem(SDB.UI.Menu_TbStandard,0,0)
POPSWinamp4.Caption = lcPlayInWinamp
POPSWinamp4.OnClickFunc = "kwPlayWinamp"
POPSWinamp4.UseScript = Script.ScriptPath
POPSWinamp4.IconIndex = 13
Dim POPSPreview4
Set POPSPreview4 = SDB.UI.AddMenuItem(SDB.UI.Menu_TbStandard,0,0)
POPSPreview4.Caption = lcAddInWinamp
POPSPreview4.OnClickFunc = "kwEnqueueWinamp"
POPSPreview4.UseScript = Script.ScriptPath
POPSPreview4.IconIndex = 24
End Sub
Sub ExportM3U(mySongList, myExportPath)
Dim fOut
Set fOut = SDB.Tools.FileSystem.CreateTextFile(myExportPath, True)
fOut.WriteLine "#EXTM3U"
Dim Progress
Set Progress = SDB.Progress
Progress.Text = lcExportingToM3U
Progress.MaxValue = mySongList.count
Dim i, mySong, mySongLength
For i=0 to mySongList.count-1
Set mySong = mySongList.Item(i)
mySongLength = mySong.SongLength
if mySongLength > 0 then
mySongLength = CStr(Round(mySongLength/1000))
else
mySongLength = ""
end if
fOut.WriteLine "#EXTINF:" & mySongLength & "," & mySong.ArtistName & " - " & mySong.Title
fOut.WriteLine mySong.Path
Progress.Value = i+1
Next
fOut.Close
Set Progress = Nothing
End Sub
Sub kwPlayWinamp(arg)
kwRunCommand("")
End Sub
Sub kwEnqueueWinamp(arg)
kwRunCommand("/ADD")
End Sub
Function kwRunCommand(inCommand)
Dim WShell, Result, Command, list
Set list = SDB.SelectedSongList
If list.count = 0 Then
Set list = SDB.AllVisibleSongList
If list.count = 0 Then
Result = SDB.MessageBox(lcNothingToSend, mtError, Array(mbOK))
Exit Function
End If
End If
ExportM3U list, tempM3UPath
Command = WinampEXE & " " & inCommand & " " & tempM3UPath
Set WShell = CreateObject("WScript.Shell")
Result = WShell.Run(Command, 0, 0)
End Function