Squeezebox

Posted on
Wed Feb 29, 2012 1:01 pm
Londonmark offline
Posts: 509
Joined: Feb 29, 2012

Squeezebox

Is there an updated version of the Slimserver attachment script? I've completely failed to make it work - I've entered details of my players and their IP addresses where I think I am supposed to but still get an error message saying that the player nickname or IP address is not recognised. Bizarrely I occasionally manage to get the status variables to show what's playing, although it seems entirely random as to when that happens.

Any guidance?

Posted on
Tue Aug 14, 2012 5:30 pm
pgershon offline
Posts: 509
Joined: Jul 10, 2004

Re: Squeezebox

Where did the script go? I cannot find a script or plugin

Posted on
Tue Aug 14, 2012 9:11 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Squeezebox

Here's the attachment script I've been using, works fine. I do use the players MAC address instead of it's IP.

Code: Select all
-- SlimServer control attachment
--
-- This script provides functions for easily controlling SlimDevices
-- SLIMP3 or Squeezebox from Indigo Execute AppleScript actions.
--
-- Author:   Andrew Turner (software at highearthorbit dot com)
-- Changes:   Paul Roomberg (paul at pasaro dot nl)
--         Nick Sosnicki - 30 Oct 2006 - v1.2
--            -tested on Indigo 2.0b8, SlimServer 6.5.0
--            -added error trapping to shell scripts
--            -set the curl connect timeout to 5 seconds
--               and the curl transaction time limit to
--               10 seconds (these can be increased if needed)
--            - added option to ping server and Squeezebox to
--               see if they are there before sending commands
--            -added support for multiple Squeezeboxes through
--               a nick name/IP address definition; this requires
--               an extra parm for each command
--            -to support multiple Squeezebox status, multiple
--               status variables are used; these will be created
--               automatically if needed
--            -changed slim server display function to allow
--               dynamic control of the time to display
--         Matt Bendiksen - 1 Jan 2007 - v1.2.1
--            -general cleanup, bug fixes, and added to base
--               Indigo 2.0 install
--
-- __Attachment Functions__ Can be called from within Indigo Execute AppleScript actions,
-- or any _tell app "IndigoServer"_ block. If the squeezebox nickname is blank, the first
-- one defined in the map will be used.
--
--   SlimServerDisplay("Line 1", "Line 2", seconds to display, "Squeeze Nickname")
--   SlimServerVolume(volume, "Squeeze Nickname")
--      volume: 0-100
--   SlimServerPlaySong("Song Name", "Squeeze Nickname")
--   SlimServerSkipFwd("Squeeze Nickname")
--   SlimServerSkipRew("Squeeze Nickname")
--   SlimServerPower(On or Off, "Squeeze Nickname")
--      On or Off: 0 is off, 1 is on
--   SlimServerCommand("Command","Squeeze Nickname")
--      available commands: "play", "pause", "stop", "sleep"
--
--   Status variable are named "SlimStatus" and the Squeezebox's nick name
--      for example, "SlimStatusupBath1" and "SlimStatusupBath2"

property slimIP : "192.168.1.80" -- slimserver IP address
property slimPort : "9000" -- slimserver web port

-- Map of Squeezebox nicknames and their IP addresses. MAC addresses
-- can be used instead, but you must set pingSqueeze to false (the ping
-- test cannot be used with MAC addresses). Add a new pair for every
-- Squeezebox you want to control.
property squeezeMap : {¬
   {"Kitchen_Radio", "00:04:20:26:e4:25"} ¬
      }

property pingSlim : false --if true, ping slimserver before commands
property pingSqueeze : false --if true, ping squeezebox before commands

property slimResponseText : ""

using terms from application "IndigoServer"
   on SlimServerCommand(theCommand, squeezeNick)
      SendToSlimServer(theCommand, 0, 0, 0, squeezeNick)
   end SlimServerCommand
   
   on SlimServerDisplay(displayString1, displayString2, displaySeconds, squeezeNick)
      set lineOne to _searchReplaceText(" ", "%20", displayString1)
      set lineTwo to _searchReplaceText(" ", "%20", displayString2)
      SendToSlimServer("display", lineOne, lineTwo, displaySeconds, squeezeNick)
   end SlimServerDisplay
   
   on SlimServerVolume(volume, squeezeNick)
      SendToSlimServer("mixer", "volume", volume, 0, squeezeNick)
   end SlimServerVolume
   
   on SlimServerPlaySong(songName, squeezeNick)
      SendToSlimServer("playlist", "play", songName, 0, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerPlaySong
   
   
   on SlimServerPlayFavorite(favorite, squeezeNick)
      SendToSlimServer("favorites", "playlist", "play", "item_id:" & favorite, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerPlayFavorite
   
   
   on SlimServerSkipFwd(squeezeNick)
      SendToSlimServer("button", "jump_fwd", 1, 0, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerSkipFwd
   
   on SlimServerSkipRew(squeezeNick)
      SendToSlimServer("button", "jump_rew", 0, 0, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerSkipRew
   
   on SlimServerPower(onOff, squeezeNick)
      SendToSlimServer("power", onOff, 0, 0, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerPower
   
   on SlimServerGetStatus(squeezeNick)
      SendToSlimServer("status", 0, 0, 0, squeezeNick)
      GetSlimStatus(squeezeNick)
   end SlimServerGetStatus
   
   on SlimServerLog(logString)
      tell application "IndigoServer"
         log logString using type "SlimServer"
      end tell
   end SlimServerLog
   
   on GetSlimStatus(squeezeNick)
      if squeezeNick is "" then
         set squeezeNick to item 1 of item 1 of squeezeMap
      end if
      tell application "IndigoServer"
         -- if a status variable pair does not exisit for this Squeeze's nick name, create it
         set statusVar1 to "SlimStatus" & squeezeNick & "1"
         set statusVar2 to "SlimStatus" & squeezeNick & "2"
         if not (variable statusVar1 exists) then
            make new variable with properties {name:statusVar1, value:first paragraph of slimResponseText}
         else
            set value of variable statusVar1 to the first paragraph of slimResponseText
         end if
         if not (variable statusVar2 exists) then
            make new variable with properties {name:statusVar2, value:last paragraph of slimResponseText}
         else
            set value of variable statusVar2 to the last paragraph of slimResponseText
         end if
      end tell
   end GetSlimStatus
   
   on SendToSlimServer(p0, p1, p2, p3, squeezeNick)
      -- explicitly set variable
      set squeezeIP to "00:04:20:26:e4:25"
      --lookup IP for squeeze box nickname if provided, else use first entry
      (*      if squeezeNick is "" then
         set squeezeIP to item 2 of item 1 of squeezeMap
      else
         set squeezeIP to ""
         repeat with mapEntry in squeezeMap
            if item 1 of mapEntry is squeezeNick then
               set squeezeIP to item 2 of mapEntry
               exit repeat
            end if
         end repeat
      end if
      if squeezeIP is "" then
         SlimServerLog("Squeezebox nickname " & squeezeNick & " or IP address is not defined")
         return
      end if
*)
      set pingSucess to true
      if pingSlim then --try to ping slimserver
         if not PingAddress(slimIP) then
            set pingSucess to false
            set slimResponseText to "SlimServer at " & slimIP & " not reachable"
            SlimServerLog("SlimServer at " & slimIP & " not reachable")
         end if
      end if
      if pingSqueeze then --try to ping squeezebox
         if not PingAddress(squeezeIP) then
            set pingSucess to false
            set slimResponseText to "Squeezebox at " & squeezeIP & " not reachable"
            SlimServerLog("Squeezebox at " & squeezeIP & " not reachable")
         end if
      end if
      if pingSucess then
         set h to "http://" & slimIP & ":" & slimPort & "/status.txt"
         set d to h & "?p0=" & p0
         if p1 is not equal to 0 then set d to d & "&p1=" & p1
         if p2 is not equal to 0 then set d to d & "&p2=" & p2
         if p3 is not equal to 0 then set d to d & "&p3=" & p3
         set d to d & "&player=" & squeezeIP
         try
            set slimResponseText to DoShellScript("curl --connect-timeout 5 --max-time 10 --get -d --url \"" & d & "\" ")
         on error errStatement number errNum
            set slimResponseText to "Connection error (CURL): " & errNum
            SlimServerLog("Connection error (CURL) with SlimServer at " & slimIP & "; error number: " & errNum)
         end try
      end if
   end SendToSlimServer
end using terms from

-- Pings given address and returns true if there were no errors, false if there were errors
on PingAddress(IPAddress)
   set errTest to true
   try
      set ping_result to DoShellScript("ping -o -q -n -t 3  " & IPAddress)
   on error errStatement number errNum
      set errTest to false
   end try
   return errTest
end PingAddress

-- Glue for shell scripts to ensure correct environmental vars are used
on DoShellScript(scriptStr)
   tell application "Finder" to set returnVal to do shell script scriptStr
   return returnVal
end DoShellScript

(*
   _searchReplaceText(searchTerm, replaceTerm, theText)
   Replaces a string found in a text by another string.
   This handle supports lists of search/replace terms.

   Parameters:
      searchTerm: the text to search for
      replaceTerm: the text to use as replacement
      theText: the text to search/replace

   Examples:
      _searchReplaceText("foo", "bar", "You are a foo") --> "You are a bar"
      _searchReplaceText({"foo", " a "}, {"bar", " one "}, "You are a foo") --> "You are one bar"
*)
to _searchReplaceText(searchTerm, replaceTerm, theText)
   set searchTerm to searchTerm as list
   set replaceTerm to replaceTerm as list
   set theText to theText as text
   
   set oldTID to AppleScript's text item delimiters
   repeat with i from 1 to count searchTerm
      set AppleScript's text item delimiters to searchTerm's item i
      set theText to theText's text items
      set AppleScript's text item delimiters to replaceTerm's item i
      set theText to theText as text
   end repeat
   set AppleScript's text item delimiters to oldTID
   return theText
end _searchReplaceText


Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 21 guests

cron