MM and SqueezeBox Script

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

revel
Posts: 3
Joined: Wed Sep 26, 2007 7:24 pm

MM and SqueezeBox Script

Post by revel » Wed Sep 26, 2007 7:25 pm

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.

mdhmdh31
Posts: 25
Joined: Sun Jul 04, 2004 6:54 am

Thanks

Post by mdhmdh31 » Sun Oct 14, 2007 12:14 am

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.

K2
Posts: 4
Joined: Wed Feb 14, 2007 2:15 pm
Location: Quad Cities, IA

Post by K2 » Mon Nov 19, 2007 4:13 pm

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. :D

@Revel... Any luck with the spaces issue you mentioned previously?

rola
Posts: 1
Joined: Wed Jan 02, 2008 11:03 pm
Contact:

Post by rola » Thu Jan 03, 2008 1:45 am

Oh,thanks,I'm a Squeezbox user too. I will try it this night :D

Peke
Posts: 12472
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Post by Peke » Thu Jan 03, 2008 12:15 pm

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.
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

Big_Berny
Posts: 1784
Joined: Mon Nov 28, 2005 11:55 am
Location: Switzerland
Contact:

Post by Big_Berny » Thu Jan 03, 2008 12:31 pm

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
Image
Scripts in use: Genre Finder / Last.fm DJ / Magic Nodes / AutoRateAccurate / Last.FM Node
Skins in use: ZuneSkin SP / Eclipse SP
AutoRateAccurate 3.0.0 (New) - Rates all your songs in less than 5 seconds!
About me: icoaching - internet | marketing | design

Peke
Posts: 12472
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Post by Peke » Thu Jan 03, 2008 1:26 pm

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.
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

Baz
Posts: 8
Joined: Mon Mar 12, 2007 9:16 am
Location: Southampton U.K.

Post by Baz » Fri Jan 04, 2008 11:42 am

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 :D 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. :)
Barry Goddard

Image

Baz
Posts: 8
Joined: Mon Mar 12, 2007 9:16 am
Location: Southampton U.K.

Post by Baz » Fri Jan 04, 2008 5:25 pm

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. :)
Barry Goddard

Image

Big_Berny
Posts: 1784
Joined: Mon Nov 28, 2005 11:55 am
Location: Switzerland
Contact:

Post by Big_Berny » Fri Jan 04, 2008 6:15 pm

Thx, Peke! :)
Had not enough time to really check the code. :)
Image
Scripts in use: Genre Finder / Last.fm DJ / Magic Nodes / AutoRateAccurate / Last.FM Node
Skins in use: ZuneSkin SP / Eclipse SP
AutoRateAccurate 3.0.0 (New) - Rates all your songs in less than 5 seconds!
About me: icoaching - internet | marketing | design

Peke
Posts: 12472
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Post by Peke » Sat Jan 05, 2008 12:43 am

This one looks nicer each update.

Good call Buz about using Escape. That is actually how Internet Explorer handles URLs
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

BuckNaked
Posts: 23
Joined: Fri Aug 11, 2006 4:13 pm

Post by BuckNaked » Thu Jan 10, 2008 3:29 pm

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.)

Baz
Posts: 8
Joined: Mon Mar 12, 2007 9:16 am
Location: Southampton U.K.

Post by Baz » Fri Jan 11, 2008 2:46 pm

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 :oops: 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 :D
Barry Goddard

Image

Peke
Posts: 12472
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Post by Peke » Sun Jan 13, 2008 3:58 am

@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.
Best regards,
Pavle
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add SCREENSHOTS to forum

wolfzell
Posts: 155
Joined: Fri Apr 23, 2004 8:42 am
Location: Germany

Post by wolfzell » Sun Jan 13, 2008 7:56 am

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

Post Reply