global __configsFile
global __configsReadScript
global config
on _prepare()
set __configsFile to "Macintosh HD:Applications:SqueezePlayScripts:_config:configs.txt"
set __configsReadScript to "Macintosh HD:Applications:SqueezePlayScripts:_config:ReadConfigFile.scpt"
end _prepare
on writeConfig()
set configFile to __configsFile
set config to {volMute:0, volNormal:70, volStep:3, volSpeech:30}
set config to config & {timeStepSmall:5, timeStepMid:10, timeStepLarge:30}
set config to config & {enVoice:"Vicki", deVoice:"Steffi"}
set config to config & {lmsIP:"192.168.178.99 ", lmsHTTPPort:"9000", lmsCLIPort:"9090", lmsJSON:"/jsonrpc.js"}
set config to config & {miniSqueezeMAC:"00:00:00:00:00:01", miniSqueezeMACPercent:"00%3A00%3A00%3A00%3A00%3A01"}
set config to config & {osdMsgShow:true, osdMsgDurShort:1, osdMsgDurMid:3, osdMsgDurLong:6}
set config to config & {lng:"en"}
set config to config & {enSeconds:"seconds", deSeconds:"Sekunden"}
set config to config & {enNxtTrack:"Squeezebox:Next Track", deNxtTrack:"Squeezebox:Nächster Titel"}
set config to config & {enPrvTrack:"Squeezebox:Previous Track", dePrvTrack:"Squeezebox:Vorheriger Titel"}
set config to config & {enVolUp:"Squeezebox:VolumeUp", deVolUp:"Squeezebox:Lauter"}
set config to config & {enVolDown:"Squeezebox:VolumeDown", deVolDown:"Squeezebox:Leiser"}
set config to config & {enVolMute:"Squeezebox:Mute", deVolMute:"Squeezebox:Stumm"}
set config to config & {enVolNorm:"Squeezebox:Volume normalized", deVolNorm:"Squeezebox:Lautstärke normalisiert"}
set config to config & {enVolMuteToggle:"Squeezebox:Mute toggle", deVolMuteToggle:"Squeezebox:Stumm umschalten"}
set config to config & {enPlay:"Squeezebox:Play", deVolMuteToggle:"Squeezebox:Abspielen"}
set config to config & {enPause:"Squeezebox:Pause", dePause:"Squeezebox:Pause"}
set config to config & {enPauseToggle:"Squeezebox:Pause toggle", dePauseToggle:"Squeezebox:Pause umschalten"}
set config to config & {enStop:"Squeezebox:Stop", deStop:"Squeezebox:Stopp"}
set config to config & {enTimeForward:"Squeezebox:Forward", deTimeForward:"Squeezebox:Vorwärts"}
set config to config & {enTimeBackward:"Squeezebox:Backward", deTimeBackward:"Squeezebox:Rückwärts"}
set config to config & {enRndAll:"Squeezebox:Random play", deRndAll:"Squeezebox:Zufällig abspielen"}
set config to config & {enRndTripHop:"Squeezebox:Random play : Trip-Hop", deRndTripHop:"Squeezebox:Zufällig abspielen : Trip-Hop"}
set config to config & {enRndIDM:"Squeezebox:Random play : IDM", deRndIDM:"Squeezebox:Zufällig abspielen : IDM"}
set config to config & {enRndElectronica:"Squeezebox:Random play : Electronica", deRndElectronica:"Squeezebox:Zufällig abspielen : Electronica"}
set config to config & {enRndGoa:"Squeezebox:Random play : Goa", deRndGoa:"Squeezebox:Zufällig abspielen : Goa"}
set config to config & {enRndIndie:"Squeezebox:Random play : Indie", deRndIndie:"Squeezebox:Zufällig abspielen : Indie"}
set config to config & {enRndClassical:"Squeezebox:Random play : Classical", deRndClassical:"Squeezebox:Zufällig abspielen : Klassik"}
set config to config & {enRndPostRock:"Squeezebox:Random play : Post Rock", deRndPostRock:"Squeezebox:Zufällig abspielen : Post Rock"}
set config to config & {enRadio_RadioRSG:"Squeezebox:InternetRadio : Radio RSG", deRadio_RadioRSG:"Squeezebox:Internetradio : Radio RSG"}
set config to config & {enRadio_1Live:"Squeezebox:InternetRadio : 1Live", deRadio_1Live:"Squeezebox:Internetradio : 1Live"}
set config to config & {enRadio_WDR2:"Squeezebox:InternetRadio : WDR2 - Bergisches Land", deRadio_WDR2:"Squeezebox:Internetradio : WDR2 - Bergisches Land"}
set config to config & {enNowPlaying:"Squeezebox:NowPlaying", deNowPlaying:"Squeezebox:Wird abgespielt"}
set config to config & {enSayNowPlaying:"now playing", deSayNowPlaying:"wird abgespielt"}
set fRef to (open for access file configFile with write permission)
try
set eof fRef to 0
write config to fRef
end try
close access fRef
return config as record
end writeConfig
on readConfig()
_prepare()
set configFile to __configsReadScript
set config to run script (configFile as alias)
end readConfig
on sendCLICommand(cmd)
do shell script "echo " & miniSqueezeMACPercent of config & " " & cmd & " | nc " & lmsIP of config & lmsCLIPort of config
end sendCLICommand
on getJSON()
set http to "http://" & lmsIP of config & ":" & lmsHTTPPort of config & lmsJSON of config
set playerIP to miniSqueezeMAC of config
set json_cmd to "status"
set json_par1 to "-"
set json_par2 to "1"
set json_par3 to "tags:al"
do shell script "curl -v -H -X POST -d '{\"id\":1,\"method\":\"slim.request\",\"params\":[\"" & playerIP & "\",[\"" & json_cmd & "\",\"" & json_par1 & "\"," & json_par2 & ",\"" & json_par3 & "\"]]}' " & http
return the result
end getJSON
on filterJSON(key, json)
set s to 0
set e to 0
set res to ""
if key = "artist" then
set s to offset of "artist\"" in json
set e to offset of "album\"" in json
end if
if key = "title" then
set s to offset of "title\"" in json
set e to offset of "artist\"" in json
end if
if key = "volume" then
set s to offset of "volume\"" in json
set e to offset of "player_name\"" in json
end if
set res to (characters (s + ((length of key) + 3)) thru (e - 4) of json) as string
if key = "artist" then set res to normalizeArtist(res)
if key = "volume" then
if length of res = 3 then set res to character 2 of res
end if
return res
end filterJSON
on _normalizeArtist(theArtist)
set res to theArtist
set commaOffset to offset of "," in theArtist
if commaOffset > 0 then
set res to (characters (commaOffset + 2) thru ((commaOffset + (length of theArtist)) - commaOffset) of theArtist) as string
set res to res & " " & (characters 1 thru (commaOffset - 1) of theArtist) as string
end if
return res
end _normalizeArtist
on normalizeArtist(theArtist)
set res to theArtist
set commaOffset to offset of "," in theArtist
if commaOffset > 0 then
set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set delimitedList to every text item of theArtist
set res to item 2 of delimitedList as string
set res to res & " " & item 1 of delimitedList as string
repeat with counter from 3 to length of delimitedList
set res to res & " " & item counter of delimitedList as string
end repeat
set AppleScript's text item delimiters to {","}
set delimitedList to every text item of res
set res to ""
repeat with counter from 1 to length of delimitedList
set res to res & " " & item counter of delimitedList as string
end repeat
set AppleScript's text item delimiters to savedDelimiters
end if
return res
end normalizeArtist
on getText_(key)
-- http://latenightsw.com/freeware/RecordTools/index.html
set str to ""
--set lngKey to get user property "lng" in config
--set lngKey to lngKey & key
--return get user property lngKey in config
return str
end getText_
on getText__(key)
set str to ""
--set myScript to load script "Macintosh HD:Applications:SqueezePlayScripts:_ReturnText.scpt" as alias
--tell myScript to returnText(key)
--set str to the result
return str
end getText__
on getText(key)
set str to "%DUMMY%"
if key = "TimeForward" then set str to enTimeForward of config
if key = "TimeBackward" then set str to enTimeBackward of config
if key = "Seconds" then set str to enSeconds of config
if key = "NxtTrack" then set str to enNxtTrack of config
if key = "PrvTrack" then set str to enPrvTrack of config
if key = "NxtTrack" then set str to enNxtTrack of config
if key = "VolUp" then set str to enVolUp of config
if key = "VolDown" then set str to enVolDown of config
if key = "VolMute" then set str to enVolMute of config
if key = "VolNorm" then set str to enVolNorm of config
if key = "VolMuteToggle" then set str to enVolMuteToggle of configen
if key = "Play" then set str to enPlay of config
if key = "Pause" then set str to enPause of config
if key = "PauseToggle" then set str to enPuaseToggle of config
if key = "Stop" then set str to enStop of config
if key = "RndAll" then set str to enRndAll of config
if key = "RndTripHop" then set str to enRndTripHop of config
if key = "RndIDM" then set str to enRndIDM of config
if key = "RndElectronica" then set str to enRndElectronica of config
if key = "RndGoa" then set str to enRndGoa of config
if key = "RndIndie" then set str to enRndIndie of config
if key = "RndClassical" then set str to enRndClassical of config
if key = "RndPostRock" then set str to enRndPostRock of config
if key = "Radio_RadioRSG" then set str to enRadio_RadioRSG of config
if key = "Radio_1Live" then set str to enRadio_1Live of config
if key = "Radio_WDR2" then set str to enRadio_WDR2 of config
if key = "NowPlaying" then set str to enNowPlaying of config
if key = "SayNowPlaying" then set str to enSayNowPlaying of config
return str
end getText
on displayMsg(msg, dur)
if osdMsgShow of config then tell application "Remote Buddy" to osdmessage display text msg for duration dur
end displayMsg
on sayMsg(msg)
set curVolume to output volume of (get volume settings)
set volume output volume volSpeech of config
if lng of config = "en" then say msg using enVoice of config
if lng of config = "de" then say msg using deVoice of config
set volume output volume curVolume
end sayMsg
-- -------------------------------
on SB_CheckSqueezeslave()
do shell script "ps -ef | grep squeezeslave"
set x to offset of "/Applications/Squeezeslave/squeezeslave" in the result
if x = 0 then
do shell script "/Applications/Squeezeslave/squeezeslave -o2 -R -r10 -M -m10:10:10:10:10:10"
delay 2
SB_Play()
end if
end SB_CheckSqueezeslave
on SB_NextTrack()
readConfig()
displayMsg(getText("NxtTrack"), osdMsgDurMid of config)
sendCLICommand("playlist index +1")
set json to getJSON()
set artist to filterJSON("artist", json)
set title to filterJSON("title", json)
delay (osdMsgDurShort of config)
displayMsg(artist & " - " & title, osdMsgDurLong of config)
end SB_NextTrack
on SB_PreviousTrack()
readConfig()
displayMsg(getText("PrvTrack"), osdMsgDurMid of config)
sendCLICommand("playlist index -1")
set json to getJSON()
set artist to filterJSON("artist", json)
set title to filterJSON("title", json)
delay (osdMsgDurShort of config)
displayMsg(artist & " - " & title, osdMsgDurLong of config)
end SB_PreviousTrack
on SB_VolUp()
readConfig()
set lmsCLICommand to "mixer volume +" & volStep of config
sendCLICommand(lmsCLICommand)
set json to getJSON()
set vol to filterJSON("volume", json)
displayMsg(getText("VolUp") & " (" & vol & "%)", osdMsgDurShort of config)
end SB_VolUp
on SB_VolDown()
readConfig()
set lmsCLICommand to "mixer volume -" & volStep of config
sendCLICommand(lmsCLICommand)
set json to getJSON()
set vol to filterJSON("volume", json)
displayMsg(getText("VolDown") & " (" & vol & "%)", osdMsgDurShort of config)
end SB_VolDown
on SB_VolMute()
readConfig()
set lmsCLICommand to "mixer volume " & volMute of config
sendCLICommand(lmsCLICommand)
set json to getJSON()
set vol to filterJSON("volume", json)
displayMsg(getText("VolMute") & " (" & vol & "%)", osdMsgDurShort of config)
end SB_VolMute
on SB_VolNorm()
readConfig()
set lmsCLICommand to "mixer volume " & volNormal of config
sendCLICommand(lmsCLICommand)
set json to getJSON()
set vol to filterJSON("volume", json)
displayMsg(getText("VolNorm") & " (" & vol & "%)", osdMsgDurShort of config)
end SB_VolNorm
on SB_VolMuteToggle()
readConfig()
sendCLICommand("mixer muting")
set json to getJSON()
set vol to filterJSON("volume", json)
displayMsg(getText("VolMuteToggle"), osdMsgDurShort of config)
end SB_VolMuteToggle
on SB_Play()
readConfig()
sendCLICommand("play")
displayMsg(getText("Play"), osdMsgDurShort of config)
end SB_Play
on SB_Pause()
readConfig()
sendCLICommand("pause 1")
displayMsg(getText("Pause"), osdMsgDurShort of config)
end SB_Pause
on SB_PauseToggle()
readConfig()
sendCLICommand("pause")
displayMsg(getText("PauseToggle"), osdMsgDurShort of config)
end SB_PauseToggle
on SB_Stop()
readConfig()
sendCLICommand("stop")
displayMsg(getText("Stop"), osdMsgDurShort of config)
end SB_Stop
on SB_rndAll()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("randomplay tracks")
displayMsg(getText("RndAll"), osdMsgDurMid of config)
end SB_rndAll
on SB_rndTripHop()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("playlist loadtracks genre.namesearch=Trip-Hop")
displayMsg(getText("RndTripHop"), osdMsgDurMid of config)
end SB_rndTripHop
on SB_rndIDM()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("playlist loadtracks genre.namesearch=IDM")
displayMsg(getText("RndIDM"), osdMsgDurMid of config)
end SB_rndIDM
on SB_rndElectronica()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("playlist loadtracks genre.namesearch=Electronica")
displayMsg(getText("RndElectronica"), osdMsgDurMid of config)
end SB_rndElectronica
on SB_rndGoa()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("playlist loadtracks genre.namesearch=Goa")
displayMsg(getText("RndGoa"), osdMsgDurMid of config)
end SB_rndGoa
on SB_rndIndie()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("playlist loadtracks genre.namesearch=Indie")
displayMsg(getText("RndIndie"), osdMsgDurMid of config)
end SB_rndIndie
on SB_rndClassical()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("playlist loadtracks genre.namesearch=Classical")
displayMsg(getText("RndClassical"), osdMsgDurMid of config)
end SB_rndClassical
on SB_rndPostRock()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("playlist loadtracks genre.namesearch=%22Post%20Rock%22")
displayMsg(getText("RndPostRock"), osdMsgDurMid of config)
end SB_rndPostRock
on SB_Radio_RadioRSG()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("playlist play __playlists/RadioRSG")
displayMsg(getText("Radio_RadioRSG"), osdMsgDurMid of config)
end SB_Radio_RadioRSG
on SB_Radio_1Live()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("playlist play __playlists/1Live")
displayMsg(getText("Radio_1Live"), osdMsgDurMid of config)
end SB_Radio_1Live
on SB_Radio_WDR2()
readConfig()
sendCLICommand("playlist clear")
sendCLICommand("playlist play __playlists/WDR2BergischesLand")
displayMsg(getText("Radio_WDR2"), osdMsgDurMid of config)
end SB_Radio_WDR2
on SB_TimeChange(step)
if step > 0 then
sendCLICommand("time +" & step)
set str to getText("TimeForward")
else
sendCLICommand("time " & step)
set str to getText("TimeBackward")
end if
set str to str & " " & step & " " & getText("Seconds")
displayMsg(str, osdMsgDurMid of config)
end SB_TimeChange
on SB_TimeForwardSmall()
readConfig()
set step to timeStepSmall of config
SB_TimeChange(step)
end SB_TimeForwardSmall
on SB_TimeForwardMid()
readConfig()
set step to timeStepMid of config
SB_TimeChange(step)
end SB_TimeForwardMid
on SB_TimeForwardLarge()
readConfig()
set step to timeStepLarge of config
SB_TimeChange(step)
end SB_TimeForwardLarge
on SB_TimeBackwardSmall()
readConfig()
set step to (timeStepSmall of config) * -1
SB_TimeChange(step)
end SB_TimeBackwardSmall
on SB_TimeBackwardMid()
readConfig()
set step to (timeStepMid of config) * -1
SB_TimeChange(step)
end SB_TimeBackwardMid
on SB_TimeBackwardLarge()
readConfig()
set step to (timeStepLarge of config) * -1
SB_TimeChange(step)
end SB_TimeBackwardLarge
on SB_SayArtistTitle()
readConfig()
set json to getJSON()
set artist to filterJSON("artist", json)
set title to filterJSON("title", json)
displayMsg(getText("NowPlaying"), osdMsgDurMid of config)
sayMsg(getText("SayNowPlaying"))
set artistSay to replace_say_chars(artist)
displayMsg(artist, osdMsgDurLong of config)
sayMsg(artistSay)
displayMsg(artist & " - " & title, osdMsgDurLong of config)
set titleSay to replace_say_chars(title)
sayMsg(titleSay)
end SB_SayArtistTitle
-- --------------------------------
on replace_say_chars(the_text)
set res to replace_chars(the_text, ".", " ")
set res to replace_chars(res, "&", "and")
return res
end replace_say_chars
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars