Page 1 of 4
MM and SqueezeBox Script
Posted: Wed Sep 26, 2007 7:25 pm
by revel
I was too poor to buy an Airport express so I came up with this, as I already had a PC connected to my stereo.
I created a script that basically plays whatever song is currently playing in MM on a Squeezbox OR SoftSqeeze running on a PC(which I am using). It does this via the Slimserver CLI (telnet command line) with a scriptable free telnet .dll you have to install called w3Sockets.
I just created it tonight, let me know if it works for anyone else.
telnet dll (w3sockets):
http://www.dimac.net/default3.asp?M=Fre ... sstart.asp
slimserver:
http://www.slimdevices.com/su_downloads.html
softsqeeze:
http://softsqueeze.sourceforge.net/
Code: Select all
' MediaMonkey Script
' NAME: SqueezeBox Controller
' Author: Todd Nemeth /revel
' Date first started: 09/26/2007
' INSTALL: Copy to Scripts\Auto\
' REQUIREMENTS:
'- You need w3Sockets installed and registered from here:
'http://www.dimac.net/default3.asp?M=FreeDownloads/'Menu.asp&P=FreeDownloads/FreeDownloadsstart.asp
'-You will also need SlimServer installed and running.
Sub OnStartup
Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
End Sub
Sub Event_OnPlay
Set objCurSong = SDB.Player.CurrentSong
strPath = objCurSong.Path
'MsgBox strPath
strPlayerCmd = "playlist play " & strPath
'MsgBox strPlayerCmd
Dim oSocket
Set oSocket = CreateObject("Socket.TCP")
oSocket.DoTelnetEmulation = True
oSocket.TelnetEmulation = "TTY"
oSocket.Host = "localhost:9090"
oSocket.Open
oSocket.SendLine strPlayerCmd
oSocket.Close
End Sub
Sub Event_OnStop
strPlayerCmd = "stop"
Dim oSocket
Set oSocket = CreateObject("Socket.TCP")
oSocket.DoTelnetEmulation = True
oSocket.TelnetEmulation = "TTY"
oSocket.Host = "localhost:9090"
oSocket.Open
oSocket.SendLine strPlayerCmd
oSocket.Close
End Sub
Sub Event_OnShutdown
strPlayerCmd = "stop"
Dim oSocket
Set oSocket = CreateObject("Socket.TCP")
oSocket.DoTelnetEmulation = True
oSocket.TelnetEmulation = "TTY"
oSocket.Host = "localhost:9090"
oSocket.Open
oSocket.SendLine strPlayerCmd
oSocket.Close
End Sub
Sub Event_OnPause
strPlayerCmd = "pause"
Dim oSocket
Set oSocket = CreateObject("Socket.TCP")
oSocket.DoTelnetEmulation = True
oSocket.TelnetEmulation = "TTY"
oSocket.Host = "localhost:9090"
oSocket.Open
oSocket.SendLine strPlayerCmd
oSocket.Close
End Sub
EDIT: Just noticed that its having issues with spaces in file names. I'll work on it.
Thanks
Posted: Sun Oct 14, 2007 12:14 am
by mdhmdh31
Thanks. I hope you're able to fix the issue with spaces. This is a great capability. I'm a SqueezeBox user / fan as well.
Posted: Mon Nov 19, 2007 4:13 pm
by K2
After much looking around I finally bit and bought a Squeezebox (very excited) and can't wait for it arrival! I'm happy to play with your script once I get it.
@Revel... Any luck with the spaces issue you mentioned previously?
Posted: Thu Jan 03, 2008 1:45 am
by rola
Oh,thanks,I'm a Squeezbox user too. I will try it this night

Posted: Thu Jan 03, 2008 12:15 pm
by Peke
I'm not familiar with Device itself, but have you tried to use "Some text with Spaces" as example it is used as &chr(34) in VBScript if you wanna try.
Posted: Thu Jan 03, 2008 12:31 pm
by Big_Berny
I think Peke is right although I don't have the Squeezbox here neither. Try this version, maybe it works: (Just changed what Peke suggested)
Code: Select all
' MediaMonkey Script
' NAME: SqueezeBox Controller
' Author: Todd Nemeth /revel
' Date first started: 09/26/2007
' INSTALL: Copy to Scripts\Auto\
' REQUIREMENTS:
'- You need w3Sockets installed and registered from here:
'http://www.dimac.net/default3.asp?M=FreeDownloads/'Menu.asp&P=FreeDownloads/FreeDownloadsstart.asp
'-You will also need SlimServer installed and running.
Sub OnStartup
Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
End Sub
Sub Event_OnPlay
Set objCurSong = SDB.Player.CurrentSong
strPath = objCurSong.Path
'MsgBox strPath
strPlayerCmd = "playlist play " & chr(34) & strPath & chr(34)
'MsgBox strPlayerCmd
Dim oSocket
Set oSocket = CreateObject("Socket.TCP")
oSocket.DoTelnetEmulation = True
oSocket.TelnetEmulation = "TTY"
oSocket.Host = "localhost:9090"
oSocket.Open
oSocket.SendLine strPlayerCmd
oSocket.Close
End Sub
Sub Event_OnStop
strPlayerCmd = "stop"
Dim oSocket
Set oSocket = CreateObject("Socket.TCP")
oSocket.DoTelnetEmulation = True
oSocket.TelnetEmulation = "TTY"
oSocket.Host = "localhost:9090"
oSocket.Open
oSocket.SendLine strPlayerCmd
oSocket.Close
End Sub
Sub Event_OnShutdown
strPlayerCmd = "stop"
Dim oSocket
Set oSocket = CreateObject("Socket.TCP")
oSocket.DoTelnetEmulation = True
oSocket.TelnetEmulation = "TTY"
oSocket.Host = "localhost:9090"
oSocket.Open
oSocket.SendLine strPlayerCmd
oSocket.Close
End Sub
Sub Event_OnPause
strPlayerCmd = "pause"
Dim oSocket
Set oSocket = CreateObject("Socket.TCP")
oSocket.DoTelnetEmulation = True
oSocket.TelnetEmulation = "TTY"
oSocket.Host = "localhost:9090"
oSocket.Open
oSocket.SendLine strPlayerCmd
oSocket.Close
End Sub
Posted: Thu Jan 03, 2008 1:26 pm
by Peke
Ok Let me Optimize A little
Code: Select all
' MediaMonkey Script
' NAME: SqueezeBox Controller
' Author: Todd Nemeth /revel
' Date first started: 09/26/2007
' INSTALL: Copy to Scripts\Auto\
' REQUIREMENTS:
'- You need w3Sockets installed and registered from here:
'http://www.dimac.net/default3.asp?M=FreeDownloads/'Menu.asp&P=FreeDownloads/FreeDownloadsstart.asp
'-You will also need SlimServer installed and running.
Explicit Public SqueezeBoxSocket
Sub OnStartup
Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
InitSqueezeBox
End Sub
Sub InitSqueezeBox
Set SqueezeBoxSocket = CreateObject("Socket.TCP")
SqueezeBoxSocket.DoTelnetEmulation = True
SqueezeBoxSocket.TelnetEmulation = "TTY"
SqueezeBoxSocket.Host = "localhost:9090"
SqueezeBoxSocket.Open
End Sub
Sub CloseSqueezeBox
SqueezeBoxSocket.Close
End Sub
Sub SendSqueezeBoxCmd(strPlayerCmd)
SqueezeBoxSocket.SendLine strPlayerCmd
End Sub
Sub Event_OnPlay
Call SendSqueezeBoxCmd("playlist play " & chr(34) & SDB.Player.CurrentSong.Path & chr(34))
'MsgBox strPlayerCmd
End Sub
Sub Event_OnStop
Call SendSqueezeBoxCmd("stop")
End Sub
Sub Event_OnShutdown
Call SendSqueezeBoxCmd("stop")
CloseSqueezeBox
End Sub
Sub Event_OnPause
Call SendSqueezeBoxCmd("pause")
End Sub
I didn't Add Check for Status but it should be easy to add.
Posted: Fri Jan 04, 2008 11:42 am
by Baz
Hi All,
I've had a play with Peke's version of the script and initially found that it was still failing to play tracks with spaces etc in them. After some time scratching my head and geting nowhere I looked up the help facility for the Slimserver Command Line Interface which comes with the slimserver installation. And found the following quote usefull :-
Beware that the server expects parameters to be encoded using percent-style escaping (see below); " and \ are not supported as in shell-like environments.
After alittle more digging around being a complete dunce in vbs I finaly found a reference to the Escape function. and changed the Event_OnPlay Subroutine to :-
Code: Select all
Sub Event_OnPlay
Call SendSqueezeBoxCmd("playlist play " & Escape(SDB.Player.CurrentSong.Path) )
End Sub
I also had to change the following line to use the actual ip address of the pc that slimserver is running on rather than reference localhost.
Code: Select all
SqueezeBoxSocket.Host = "localhost:9090"
This might be an issue with the way my pc is configured on my wireless network.
I am currently listening to some tracks using this script on my squeezebox ( with the sound on my pc turned off ) and am mighty chuffed

however I have a couple of observations to make :-
- Firstly because of the time lag between the track playing on MediaMonkey and on Squezebox when one track ends on MediaMonkey and a new one starts, the track being played on the squeezebox is cut off before it completes
- Secondly because both Slimserver and MediaMonkey are set up to Scrobble the tracks to LastFm I am now getting duplicate Scrobbles. So I will have to remember to disable Scrobbling on one of them.
The first Issue can I'm sure be handled by using the 'Playlist Play' command only if the status of the Slimserver is Stoped and the 'Playlist Add' command thereafter.
As I'm not a vbs programmer I may not be the best or quickest to progress the script further.
Hope this is usefull.

Posted: Fri Jan 04, 2008 5:25 pm
by Baz
Hi Again.
Afraid I just couldn't handle the end of my tracks being cut off so I did a bit more head scratching and I came up with a new version of the Event_OnPlay subroutine that fixes that little issue. The new version of the subroutine is below.
Code: Select all
Sub Event_OnPlay
'
'Check State of Slimserver playlist if mode is stoped then use playlist play
'otherwise use playlist add
'
Dim strRetVal, strModeQry
strModeQry = "mode ?"
SqueezeBoxSocket.SendLine strModeQry
strRetVal = SqueezeBoxSocket.GetLine
'MsgBox strRetVal
If InStr(1,strRetval,"mode stop") > 0 Then
Call SendSqueezeBoxCmd("playlist play " & Escape(SDB.Player.CurrentSong.Path))
Else
Call SendSqueezeBoxCmd("playlist add " & Escape(SDB.Player.CurrentSong.Path))
End If
'
'need to retrieve retuned line from the last play so that next time I
'check the mode I dont retrieve it in stead of the mode returrn line
'
strRetVal = SqueezeBoxSocket.GetLine
End Sub
I hope this is of use in developing the script further.
Good Luck.

Posted: Fri Jan 04, 2008 6:15 pm
by Big_Berny
Thx, Peke!

Had not enough time to really check the code.

Posted: Sat Jan 05, 2008 12:43 am
by Peke
This one looks nicer each update.
Good call Buz about using
Escape. That is actually how Internet Explorer handles URLs
Posted: Thu Jan 10, 2008 3:29 pm
by BuckNaked
I would love to be able to use this, but I am getting the following error during startup:
Error #1002 - Microsoft VBscript compilation error
Syntax error
Explicit Public SqueezeBoxSocket
..Any idea what causes this?
Am using Peke's version of the script + the latest Baz OnPlay edit, WinXP SP2, MM3.x (latest beta as of today), SqueezeCenter 7.x.
(Also got the same error using SlimServer 6.5 btw.)
Posted: Fri Jan 11, 2008 2:46 pm
by Baz
BuckNaked wrote:I would love to be able to use this, but I am getting the following error during startup:
Error #1002 - Microsoft VBscript compilation error
Syntax error
Explicit Public SqueezeBoxSocket
..Any idea what causes this?
Am using Peke's version of the script + the latest Baz OnPlay edit, WinXP SP2, MM3.x (latest beta as of today), SqueezeCenter 7.x.
(Also got the same error using SlimServer 6.5 btw.)
Oops, sorry BuckNaked it looks like I forgot to mention one of the ammendments I made to Peke's version

I also replaced the line that you are gettting the error on with :-
Code: Select all
Option Explicit
Public SqueezeBoxSocket
The full script Im using then becomes :-
Code: Select all
' MediaMonkey Script
' NAME: SqueezeBox Controller
' Author: Todd Nemeth /revel
' Date first started: 09/26/2007
' INSTALL: Copy to Scripts\Auto\
' REQUIREMENTS:
'- You need w3Sockets installed and registered from here:
'http://www.dimac.net/default3.asp?M=FreeDownloads/'Menu.asp&P=FreeDownloads/FreeDownloadsstart.asp
'-You will also need SlimServer installed and running.
Option Explicit
Public SqueezeBoxSocket
Sub OnStartup
Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
InitSqueezeBox
End Sub
Sub InitSqueezeBox
Set SqueezeBoxSocket = CreateObject("Socket.TCP")
SqueezeBoxSocket.DoTelnetEmulation = True
SqueezeBoxSocket.TelnetEmulation = "TTY"
SqueezeBoxSocket.Host = "localhost:9090"
SqueezeBoxSocket.Open
End Sub
Sub CloseSqueezeBox
SqueezeBoxSocket.Close
End Sub
Sub SendSqueezeBoxCmd(strPlayerCmd)
' MsgBox strPlayerCmd
SqueezeBoxSocket.SendLine strPlayerCmd
End Sub
Sub Event_OnPlay
'
'Check State of Slimserver playlist if mode is stoped then use playlist play
'otherwise use playlist add
'
Dim strRetVal, strModeQry
strModeQry = "mode ?"
SqueezeBoxSocket.SendLine strModeQry
strRetVal = SqueezeBoxSocket.GetLine
'MsgBox strRetVal
If InStr(1,strRetval,"mode stop") > 0 Then
Call SendSqueezeBoxCmd("playlist play " & Escape(SDB.Player.CurrentSong.Path) )
Else
Call SendSqueezeBoxCmd("playlist add " & Escape(SDB.Player.CurrentSong.Path) )
End If
'
'need to retrieve retuned line from the last play so that next time I check the mode I dont retrieve it
'in stead of the mode returrn line
'
strRetVal = SqueezeBoxSocket.GetLine
End Sub
Sub Event_OnStop
Call SendSqueezeBoxCmd("stop")
End Sub
Sub Event_OnShutdown
Call SendSqueezeBoxCmd("stop")
CloseSqueezeBox
End Sub
Sub Event_OnPause
Call SendSqueezeBoxCmd("pause")
End Sub
Hope you have more luck with this. Remember I had to use the full ip address for my slimserver rather than localhost. Perhaps you will have to also.
The script still has an issue with timeouts every so often. I hope to investigate that shortly.
Good Luck

Posted: Sun Jan 13, 2008 3:58 am
by Peke
@Baz
You can also make check for Track Status by checking IS first Letter of Path "?" an it it is check if track is Cached and if it is Send Cached Path Instead.
Posted: Sun Jan 13, 2008 7:56 am
by wolfzell
Just discovered this thread. Thank you all for your work going into this script. PLEASE make this work! Controlling the playlist of my Squeezeboxes from MediaMonkey is what I am missing most in my setup here...
bye
Wolfgang