PDA

View Full Version : Control SlimServer _from_ iTunes



Anton F. van der Kraaij
2004-10-02, 02:42
Hi everyone,

I am trying to control the slimserver from iTunes: i.e., to play the
currently playing song in iTunes on my SqueezeBox. I have looked
through the archives, but not seen such an option or plugin. Does
anybody know how to do such a thing or am I overlooking the obvious
here?

Help is appreciated,

Thanks a lot,

Greetings, Anton.

Oscar Marsh
2004-10-02, 04:09
On 2 Oct 2004, at 10:42 am, Anton F. van der Kraaij wrote:

> Hi everyone,
>
> I am trying to control the slimserver from iTunes: i.e., to play the
> currently playing song in iTunes on my SqueezeBox. I have looked
> through the archives, but not seen such an option or plugin. Does
> anybody know how to do such a thing or am I overlooking the obvious
> here?
>
> Help is appreciated,
>
> Thanks a lot,
>
> Greetings, Anton.

Hi Anton

What OS are you using? It would be trivial with a little research for
me to work out an AppleScript which would go a short way towards doing
what you want. If you're on Windows, sorry :^)

Oscar Marsh
--
jabber: ojmarsh (AT) amessage (DOT) at

Anton F. van der Kraaij
2004-10-02, 04:16
Hi Oscar,

I am using SlimServer on MacOS. Would it be easy to do such a thing in
AppleScript? I dont use AppleScript very often I am afraid, so your
help would be greatly appreciated.

Greetings,

Anton.

Oscar Marsh
2004-10-02, 05:48
> Hi Oscar,
>
> I am using SlimServer on MacOS. Would it be easy to do such a thing in
> AppleScript? I dont use AppleScript very often I am afraid, so your
> help would be greatly appreciated.
>
> Greetings,
>
> Anton.

I'm working on a script that takes the tracks from the currently
showing playlist in iTunes, adds them to the active playlist on
SlimServer, and plays it. I'm having problems using curl, can anyone
help? wget handles this URL correctly when quoted:
"http://10.0.1.2:9000/status.html?p0=playlist&p1=add&p2=/Volumes/
SmartDisk 120 GB/Music/Aphex Twin/drukqs/02 vord hosbn.mp3"
curl doesn't do the action.

Meanwhile, Anton, see here:
http://lists.slimdevices.com/archives/discuss/2003-December/022031.html
for a similar script which was written last year for a similar purpose.

Oscar Marsh
--
jabber: ojmarsh (AT) amessage (DOT) at

Anton F. van der Kraaij
2004-10-02, 07:13
Hi Oscar,

the script you mentioned indeed works and does something similar. It
however adds whole albums etc.. and thus is not always an exact replica
of what iTunes is playing. I took a look at the script and as far as I
can understand what I need is something similar and very smal:

1. Check what the path to the filename is that is currently playing
2. if different from previous filename, stop current song on slimserver
and start new song.

(And this in this idle loop) I dont know how to ask the filename of the
currently playing song. How do I do this?

> "http://10.0.1.2:9000/status.html?p0=playlist&p1=add&p2=/Volumes/
> SmartDisk 120 GB/Music/Aphex Twin/drukqs/02 vord hosbn.mp3"

In regards to your question, I think for curl you need to replace the
'/' with '%2f' and the spaces in a filename with '%20'

If I do the following in a terminal, the slimserver starts playing,
using curl:

curl
"http://127.0.0.1:9000/status.html?
p0=playlist&p1=play&p2=%2fVolumes%2fMMEDIA%2fmp3%2fEnya%2ftest.mp3"

hope this helps.

Greetings, Anton.

Oscar Marsh
2004-10-02, 09:06
> Hi Oscar,

Hiya

> the script you mentioned indeed works and does something similar. It
> however adds whole albums etc.. and thus is not always an exact
> replica of what iTunes is playing. I took a look at the script and as
> far as I can understand what I need is something similar and very
> smal:
>
> 1. Check what the path to the filename is that is currently playing
> 2. if different from previous filename, stop current song on
> slimserver and start new song.
>
> (And this in this idle loop) I dont know how to ask the filename of
> the currently playing song. How do I do this?

Well, my script doesn't monitor what's playing because I don't like
stay-open scripts. Instead, you would build a playlist in iTunes then
run the script from your iTunes scripts menu, and it will clear the
Slim playlist, add the contents of the iTunes playlist, and play it. If
you want to get the path of the current song you need something like
the following in your script:

set theLoc to POSIX path of (location of current track)

this gives you a UNIX-style path.

>
>> "http://10.0.1.2:9000/status.html?p0=playlist&p1=add&p2=/Volumes/
>> SmartDisk 120 GB/Music/Aphex Twin/drukqs/02 vord hosbn.mp3"
>
> In regards to your question, I think for curl you need to replace the
> '/' with '%2f' and the spaces in a filename with '%20'

Oh no, I was dreading you'd say that! Find and replace is not something
I find easy to do in scripts.

Oscar Marsh
--
jabber: ojmarsh (AT) amessage (DOT) at

Anton F. van der Kraaij
2004-10-02, 09:12
Hi Everyone,

Well I think I have a solution for my problem. This applescript will
check if a song is playing in iTunes. If that is the case, it will play
it in the SlimServer. There is a check made for special symbols in
filenames. My guess is that some symbols are not fully supported yet
(it works for my library so far). Save it as an application and don't
forget to tick the 'stay open' checkbox. Probably still bugs or
features missing, but it is a start :-)

Hope this helps. Oscar, thanks for your help and the link to the old
post.

Greetings,

Anton.

-- Begin of Script
-- iSlimServer: Control SlimServer from iTunes
-- Plays whatever song is currently playing in iTunes on the SlimServer
-- Copyright Anton F. van der Kraaij 2004
-- Thanks to a script by Barry Brown for inspiration and help from
Oscar Marsch
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- INSTRUCTIONS:
-- Set your variables server_address and server_port to your situation
-- Save this script as an application, making sure to click 'stay open'

global server_address, server_port, current_file_track

set server_address to "127.0.0.1" -- This is the slimserver's address
set server_port to "9000" -- This is the slimserver's port

set current_file_track to ""

on idle
try
tell application "Finder"
if (get name of every process) contains "iTunes" then set okflag to
true
end tell
if okflag then
-- iTunes is running. Check if it is playing a song.
tell application "iTunes"
if player state is paused or player state is stopped then
-- iTunes is not playing. Stop slimserver.
do shell script ("curl \"http://" & server_address & ":" &
server_port & "/status.html?p0=stop\"")
set okflag to false
return 10
end if
end tell
end if
if okflag then
tell application "iTunes"
if class of current track is file track then
try
copy current track's location to file_path_of_track
on error errText
display dialog errText buttons {"Cancel"} with icon 0
end try
end if -- not a file track
-- return file_path_of_track
if (current_file_track is not file_path_of_track) then
-- File in iTunes is different than file on SlimServer.
-- Thus update variable
set current_file_track to file_path_of_track

-- convert mac path to unix path for use in URL with curl (be
careful with special characters here)
set mac_path to (file_path_of_track as text)
set root to (offset of ":" in mac_path)
set rootdisk to (characters 1 thru (root - 1) of mac_path)
tell application "Finder"
if (disk (rootdisk as string) is the startup disk) then
set unixpath to "%2f" & (characters (root + 1) thru end of
mac_path)
else
set unixpath to "%2fVolumes:" & mac_path
end if
end tell
set chars to every character of unixpath
repeat with i from 2 to length of chars
if item i of chars as text is equal to "/" then
set item i of chars to ":"
else if item i of chars as text is equal to ":" then
set item i of chars to "%2f"
else if item i of chars as text is equal to "\"" then
set item i of chars to "\\" & "\""
else if item i of chars as text is equal to "*" then
set item i of chars to "\\*"
else if item i of chars as text is equal to "?" then
set item i of chars to "\\?"
else if item i of chars as text is equal to " " then
set item i of chars to "%20"
else if item i of chars as text is equal to "+" then
set item i of chars to "%2b"
else if item i of chars as text is equal to "&" then
set item i of chars to "%26"
else if item i of chars as text is equal to "\\" then
set item i of chars to "\\\\"
end if
end repeat
set filetoplay to every item of chars as string
-- end conversion
-- Tell slimserver to stop current song and play the song
currently playing in iTunes
do shell script ("curl \"http://" & server_address & ":" &
server_port & "/status.html?p0=stop\"")
do shell script ("curl \"http://" & server_address & ":" &
server_port & "/status.html?p0=playlist&p1=play&p2=" & filetoplay &
"\"")
end if
end tell
end if
end try
return 10
end idle
-- end of script

Anton F. van der Kraaij
2004-10-02, 09:16
Hi,

> Oh no, I was dreading you'd say that! Find and replace is not
> something I find easy to do in scripts.
>

I found something that solves your problem. See the script I just sent.
I haven't figured out how to do functions in Scripts, so the script was
one big piece of text :-(

Greetings,
Anton.

Oscar Marsh
2004-10-02, 11:03
On 2 Oct 2004, at 5:12 pm, Anton F. van der Kraaij wrote:

> This applescript will check if a song is playing in iTunes. If that is
> the case, it will play it in the SlimServer. There is a check made for
> special symbols in filenames.

Anton, great job on this script, and especially the character-changing
routine!

Oscar Marsh
--
jabber: ojmarsh (AT) amessage (DOT) at

Jonathan Greene
2004-10-02, 11:50
WOW! -- This totally rocks!

I just updated my server to 5.3.1 and am hoping that a long standing
issue I have with my Slim losing contact with iTunes won't creep back
now that I can control my Slimp3 from iTunes. This is a fantastic
script! There's a small delay between players which is just fine for
me since they are in the same room and I'll just mute the computer
while jamming on the stereo.

Thanks Anton!



On Oct 2, 2004, at 12:12 PM, Anton F. van der Kraaij wrote:

> Hi Everyone,
>
> Well I think I have a solution for my problem. This applescript will
> check if a song is playing in iTunes. If that is the case, it will
> play it in the SlimServer. There is a check made for special symbols
> in filenames. My guess is that some symbols are not fully supported
> yet (it works for my library so far). Save it as an application and
> don't forget to tick the 'stay open' checkbox. Probably still bugs or
> features missing, but it is a start :-)
>
> Hope this helps. Oscar, thanks for your help and the link to the old
> post.
>
> Greetings,
>
> Anton.
>
> -- Begin of Script
> -- iSlimServer: Control SlimServer from iTunes
> -- Plays whatever song is currently playing in iTunes on the SlimServer
> -- Copyright Anton F. van der Kraaij 2004
> -- Thanks to a script by Barry Brown for inspiration and help from
> Oscar Marsch
> --
> -- This program is free software; you can redistribute it and/or modify
> -- it under the terms of the GNU General Public License as published by
> -- the Free Software Foundation; either version 2 of the License, or
> -- (at your option) any later version.
> --
> -- This program is distributed in the hope that it will be useful,
> -- but WITHOUT ANY WARRANTY; without even the implied warranty of
> -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> -- GNU General Public License for more details.
> --
> -- INSTRUCTIONS:
> -- Set your variables server_address and server_port to your situation
> -- Save this script as an application, making sure to click 'stay open'
>
> global server_address, server_port, current_file_track
>
> set server_address to "127.0.0.1" -- This is the slimserver's address
> set server_port to "9000" -- This is the slimserver's port
>
> set current_file_track to ""
>
> on idle
> try
> tell application "Finder"
> if (get name of every process) contains "iTunes" then set okflag to
> true
> end tell
> if okflag then
> -- iTunes is running. Check if it is playing a song.
> tell application "iTunes"
> if player state is paused or player state is stopped then
> -- iTunes is not playing. Stop slimserver.
> do shell script ("curl \"http://" & server_address & ":" &
> server_port & "/status.html?p0=stop\"")
> set okflag to false
> return 10
> end if
> end tell
> end if
> if okflag then
> tell application "iTunes"
> if class of current track is file track then
> try
> copy current track's location to file_path_of_track
> on error errText
> display dialog errText buttons {"Cancel"} with icon 0
> end try
> end if -- not a file track
> -- return file_path_of_track
> if (current_file_track is not file_path_of_track) then
> -- File in iTunes is different than file on SlimServer.
> -- Thus update variable
> set current_file_track to file_path_of_track
>
> -- convert mac path to unix path for use in URL with curl (be
> careful with special characters here)
> set mac_path to (file_path_of_track as text)
> set root to (offset of ":" in mac_path)
> set rootdisk to (characters 1 thru (root - 1) of mac_path)
> tell application "Finder"
> if (disk (rootdisk as string) is the startup disk) then
> set unixpath to "%2f" & (characters (root + 1) thru end of
> mac_path)
> else
> set unixpath to "%2fVolumes:" & mac_path
> end if
> end tell
> set chars to every character of unixpath
> repeat with i from 2 to length of chars
> if item i of chars as text is equal to "/" then
> set item i of chars to ":"
> else if item i of chars as text is equal to ":" then
> set item i of chars to "%2f"
> else if item i of chars as text is equal to "\"" then
> set item i of chars to "\\" & "\""
> else if item i of chars as text is equal to "*" then
> set item i of chars to "\\*"
> else if item i of chars as text is equal to "?" then
> set item i of chars to "\\?"
> else if item i of chars as text is equal to " " then
> set item i of chars to "%20"
> else if item i of chars as text is equal to "+" then
> set item i of chars to "%2b"
> else if item i of chars as text is equal to "&" then
> set item i of chars to "%26"
> else if item i of chars as text is equal to "\\" then
> set item i of chars to "\\\\"
> end if
> end repeat
> set filetoplay to every item of chars as string
> -- end conversion
> -- Tell slimserver to stop current song and play the song
> currently playing in iTunes
> do shell script ("curl \"http://" & server_address & ":" &
> server_port & "/status.html?p0=stop\"")
> do shell script ("curl \"http://" & server_address & ":" &
> server_port & "/status.html?p0=playlist&p1=play&p2=" & filetoplay &
> "\"")
> end if
> end tell
> end if
> end try
> return 10
> end idle
> -- end of script
>
>

Torgeir Veimo
2004-10-02, 12:27
On Sat, 2004-10-02 at 14:50 -0400, Jonathan Greene wrote:
> WOW! -- This totally rocks!

Is there any way of getting the same functionality on windows?

--
Torgeir Veimo <torgeir (AT) pobox (DOT) com>

Oscar Marsh
2004-10-02, 13:11
Here's mine:

--Play this playlist on Slim.scpt
--Instructions: Build a playlist in iTunes. Provided your iTunes music
library and SlimServer use the same root folder, activating this script
will populate the SlimServer's active playlist with the contents of
your iTunes playlist and begin playing it.
--Written by Oscar Marsh 2004
--Use and modify freely. email jigsaw250 (AT) yahoo (DOT) co.uk for help
set server_address to "127.0.0.1" -- Address of your SlimServer
set server_port to "9000" -- Port of your SlimServer
set slimclearURL to "\"http://" & server_address & ":" & server_port &
"/status.html?p0=playlist&p1=clear\""
set slimplayURL to "\"http://" & server_address & ":" & server_port &
"/status.html?p0=play\""
do shell script "curl " & slimclearURL
tell application "iTunes"
set thisPlaylist to (get a reference to view of front window)
repeat with i from 1 to (count of tracks of thisPlaylist)
set thisTrack to (a reference to track i of thisPlaylist)
try
set theLoc to thisTrack's location as string
set PosixLoc to POSIX path of theLoc
set chars to every character of PosixLoc
repeat with i from 2 to length of chars
if item i of chars as text is equal to ":" then
set item i of chars to "%2f"
else if item i of chars as text is equal to "\"" then
set item i of chars to "\\" & "\""
else if item i of chars as text is equal to "*" then
set item i of chars to "\\*"
else if item i of chars as text is equal to "?" then
set item i of chars to "\\?"
else if item i of chars as text is equal to " " then
set item i of chars to "%20"
else if item i of chars as text is equal to "+" then
set item i of chars to "%2b"
else if item i of chars as text is equal to "&" then
set item i of chars to "%26"
else if item i of chars as text is equal to "\\" then
set item i of chars to "\\\\"
end if
end repeat
set filetoplay to every item of chars as string
set slimaddURL to "\"http://" & server_address & ":" & server_port &
"/status.html?p0=playlist&p1=add&p2=" & filetoplay & "\"" as string
do shell script ("curl " & slimaddURL)
end try
end repeat
do shell script "curl " & slimplayURL
end tell

Oscar Marsh
--
jabber: ojmarsh (AT) amessage (DOT) at

Bradley Mohr
2004-10-02, 17:54
Here's an AppleScript I've been using for a while that adds the
currently selected tracks in iTunes to the current playlist or
alternately replaces the playlist with the selected tracks. It's
written for a single player, does little error checking, etc., but it
works for me! It's also available here:

<ftp://ftp.bradandkathy.com/SlimPlay.zip>.

-Brad


-- SlimPlay
-- by Brad Mohr, bmohr (AT) seanet (DOT) com
-- 22 January 2003
-- This script is absolutely free and may be used by anyone for any
purpose.

-- Known Limitations:
-- Currently only supports a single SLIMP3 or Squeezebox.
-- Very little error checking

-- edit these properties to match your setup.
property serverURL : "10.0.0.1" -- URL or IP address of the SlimServer
property serverPort : "9000" -- server port number, default is 9000
property slimpAddress : "10.0.0.2" -- URL or IP address of the SliMP3

tell application "iTunes"
set these_tracks to the selection of browser window 1
if these_tracks is {} then error "No tracks are selected in the front
window."

set should_play to false

display dialog "What would you like to do with these tracks?" buttons
{"Play", "Append"} default button 2
if the button returned of the result is "Play" then set should_play to
true

set is_first_file to true

repeat with a_track in these_tracks
set carbon_filepath to the location of a_track
set track_title to the name of a_track

-- encode_text doesn't handle unicode right, but the finder can
return a properly
-- escaped path for any file, so we'll let it do the heavy lifting
tell application "Finder" to set filepath to URL of carbon_filepath
set escaped_path to encode_text(filepath, true, false) of me
if should_play then
if is_first_file then
playlist_play_track(escaped_path) of me
set is_first_file to false
else
playlist_append_track(escaped_path) of me
end if
else
playlist_append_track(escaped_path) of me
end if
end repeat

if should_play then
begin_playing() of me
end if
end tell


-- encode_text
-- taken from some Apple sample code.
-- doesn't work right WRT unicode characters, so we only use this to do
a final massage after getting a URL from the Finder
-- (see above)
on encode_text(this_text, encode_URL_A, encode_URL_B)
set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
set the URL_B_chars to "().-_:"
set the acceptable_characters to the standard_characters
if encode_URL_A is false then
set the acceptable_characters to the acceptable_characters & the
URL_A_chars
if encode_URL_B is false then
set the acceptable_characters to the acceptable_characters & the
URL_B_chars
set the encoded_text to ""
repeat with this_char in this_text
if this_char is in the acceptable_characters then
set the encoded_text to (the encoded_text & this_char)
else
set the encoded_text to (the encoded_text & encode_char(this_char))
as string
end if
end repeat
return the encoded_text
end encode_text

-- this sub-routine is used to encode a character
-- sample code from Apple
-- (doesn't work right for utf8)
on encode_char(this_char)
set the ASCII_num to (the ASCII number this_char)
set the hex_list to
{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C",
"D", "E", "F"}
set x to item ((ASCII_num div 16) + 1) of the hex_list
set y to item ((ASCII_num mod 16) + 1) of the hex_list
return ("%" & x & y) as string
end encode_char


-- append the new track to the playlist
on playlist_append_track(escapedTrackPath)
-- we use curl here because the URL Access stuff chokes on long URLs
set curl_command to "/usr/bin/curl 'http://" & serverURL & ":" &
serverPort & "/status?p0=playlist&p1=append&p2=" & escapedTrackPath &
"'"
do shell script curl_command
end playlist_append_track


-- replace the existing playlist with the new track
on playlist_play_track(escapedTrackPath)
-- we use curl here because the URL Access stuff chokes on long URLs
set curl_command to "/usr/bin/curl 'http://" & serverURL & ":" &
serverPort & "/status?p0=playlist&p1=play&p2=" & escapedTrackPath & "'"
do shell script curl_command
end playlist_play_track


-- tell the default (or only) server to begin playing
on begin_playing()
-- we use curl here because the URL Access stuff chokes on long URLs
set curl_command to "/usr/bin/curl 'http://" & serverURL & ":" &
serverPort & "/status?p0=play'"
do shell script curl_command
end begin_playing


--
Brad Mohr
bmohr (AT) seanet (DOT) com

Oscar Marsh
2004-10-02, 18:40
> Here's mine:

I should point out that large playlists hang iTunes for some time while
the repeat routine works on them.

Oscar Marsh
--
jabber: ojmarsh (AT) amessage (DOT) at

SeanRmsy
2006-02-04, 18:22
Will this Script work with Slim2 devices as well?

braaamer
2006-03-02, 10:24
Hi Anton,

I'll definitely try out your script. I am considering getting a Squeezebox 3 as I think it is a cool device with great sound - so they say.

While one can of course access SlimServer through the remote on the Squeezebox, I think in certain situations it is easier to select the music that is streamed to the box from the computer (Mac in my case). However, I do not like the web interface of SlimServer too much, hence, I was looking for a way to use the iTunes front end with its handy music searching, browsing and playlist mgmt features to control what is being streamed from SlimServer to the Squeezebox.

Am I understanding correct, that your script is exactly solving my problem?

Thanks and cheers,
Erik

Sune
2007-02-03, 10:19
Hi all,

Almost since I got my Squeezebox back in September 2006, I've been looking for a way to control it directly from iTunes.

I found these old instructions in how to control a SlimServer from iTunes on a Mac (finally). And after fiddling a bit around with Anton's version, it seems that it works as expected.

The end result. I can finally make whatever I click on in iTunes play on my Squeezebox. Hurray!

BUT...it's not all happy-slappy-snappy, cause there is one issue. iTunes is always a bit ahead of the SlimServer. Whenever the script checks, it may notice that a new song is playing, and then it starts playing that one. The thing is...then I miss the end to the previous song.

Can it be avoided? It's soooo close, and my wife would love me for being able to control the Squeezebox from any of our portable Mac's.

HELP!

Sune - Denmark

P.S. If I get it to work flawlessly, I can easily host the final script-as-an-application (incl the appropiate credits for the original makers etc), so that other's won't have to dig around like I've been doing. If that happens, how do I get it on the 3rd party software pages?

peter
2007-02-04, 02:21
Sune wrote:
> Hi all,
>
> Almost since I got my Squeezebox back in September 2006, I've been
> looking for a way to control it directly from iTunes.
>
> I found these old instructions in how to control a SlimServer from
> iTunes on a Mac (finally). And after fiddling a bit around with Anton's
> version, it seems that it works as expected.
>
> The end result. I can finally make whatever I click on in iTunes play
> on my Squeezebox. Hurray!
>
> BUT...it's not all happy-slappy-snappy, cause there is one issue.
> iTunes is always a bit ahead of the SlimServer. Whenever the script
> checks, it may notice that a new song is playing, and then it starts
> playing that one. The thing is...then I miss the end to the previous
> song.
>
> Can it be avoided? It's soooo close, and my wife would love me for
> being able to control the Squeezebox from any of our portable Mac's.
>
Surely your 'portable macs' have webbrowsers?
You do know about the Slimserver web interface, I hope?

http://address.of.slimserver:9000

Regards,
Peter

Sune
2007-02-04, 14:03
Hi there,

iTunes can do sooo much more compared to the web interface and this is the interface most newcomers to the squeezebox will be used to...

So getting this to work is both of personal interest and, I personally believe, one of the keys to make the Squeezebox even more succesful (at least for Mac users).

Using AppleScript it seems to be possible to make a solution that would make the Squeezebox 100% iTunes integratable, at least on the Mac. And that would be the door to selling this thing to Apple-fans worldwide - because the Squeezebox is so much more cool than the "AirTunes-and-AirPortExpress" solution that Apple offers.

So...any input to my problem?

/S.

P.S. An alternative to scripting would be to make the SlimServer interact with iTunes by grapping the "AirPort Express" sound stream. But then..it's probably better to have the SlimServer to do the actual file-decoding etc.

Craig
2007-02-04, 17:10
On Sat, 2004-10-02 at 14:50 -0400, Jonathan Greene wrote:
> WOW! -- This totally rocks!

Is there any way of getting the same functionality on windows?

--
Torgeir Veimo <torgeir (AT) pobox (DOT) com>

My app MC2Slim does what you want with J River Media Center which is far superior to ITunes.

you end up with a great windows front end for your squeezebox

Craig

James
2007-02-05, 00:30
You could try commenting out the call to the 'begin_playing' playing function from Anton's script. Then any new tracks will be appended to the SlimServer playlist but not played immediately.
Unfortunately that would mean that if you do skip a track half way through in iTunes, SlimServer will carry on playing the old track.

I can't think how you could support both types of behaviour at the same time!

James

BTW, I wrote a windows version of this concept a long time ago, but I don't know why it's missing from this thread! It's called 'follow iTunes' and can be found on my web site http://www.jamescraig.co.uk/SlimServer

Sune
2007-02-05, 09:47
OK, I'll try changing the script as suggested.

As for Craig's comment - not very useful for me as a Mac-user, but probably great for Windows pplz :-P

Thanks for your support, anyways. I will revert with my progress.

I guess the ideal script will do as suggested by James, with an option to skip ahead somehow....hmm...gotta think.

/Sune

Kaitsu
2007-02-07, 04:40
I found these old instructions in how to control a SlimServer from iTunes on a Mac (finally). And after fiddling a bit around with Anton's version, it seems that it works as expected.

What did you do to the Anton script? I couldn't get it work. Or can you send the working script?

reeve_mike
2007-02-18, 12:08
What did you do to the Anton script? I couldn't get it work. Or can you send the working script?

Did you get the script working? If so, please could you post the fix ...? THANKS!

Kaitsu
2007-02-19, 05:46
Did you get the script working? If so, please could you post the fix ...? THANKS!

No I didn't. Could somebody post the working script?

kensanata
2008-03-21, 11:15
Here's an AppleScript I've been using for a while that adds the currently selected tracks in iTunes to the current playlist or alternately replaces the playlist with the selected tracks. It's written for a single player, does little error checking, etc., but it works for me!

I discovered that I liked Bradley Mohr's solution the best. It took me some fiddling to get it to work with SlimCenter 7, however. Instead of curl and the CGI interface I'm now using echo and nc to talk to the server.

Using netcat, it no longer requires you to fiddle with the security parameters (nor do you need to figure out what the cauth parameter is all about).

You can get it from here:
http://www.emacswiki.org/alex/2008-03-21_Send_iTunes_Tracks_To_SqueezeBox

Sune
2008-03-21, 14:31
This is REALLY EXCELLENT!!!

And it works right out of the box :-) I can now use iTunes on a remote Mac to choose what I wanna hear. I am sure I can even convince my lovely wife to use this. NICE!!!! I'll probably make it a script instead of an application, but it's really, really nicely done. I like the fact that I can choose wether I want to play the selction immediatley or just append it to the playlist :-D

You shoul add this to the "3rd party apps" immediately as this is where newcomers they will look for stuff.

Thank you!

Sune

P.S. Added this as a bonus-tip to my small thing about the SqueezeCenter 7 which I posted today at mediamac.dk: http://mediamac.comon.dk/index.php/news/show/id=18994

kensanata
2008-03-21, 16:02
I'll probably make it a script instead of an application, but it's really, really nicely done.

Thanks. This is my first experience with AppleScript and it would not have been possible without Bradley Mohr's script to start with. In order to get it to work as an iTunes script, I had to do a little change, and I've updated by make accordingly. Just in case you want to try this as well. :)

Sune
2008-03-22, 04:07
Hi there,

You've done a good job. The new version works as expected. If you wanna play more with this, it should be possible to do the following w/o too much hassle:

Use the AppleScript kit to build a small user-interface. If I could (but I suck at any kind of programming), I'd do this myself. What I would like is the following:

A floating window containing two buttoms:
- A play buttom
- A "+" buttom

The floating window should preferrably open whenever I launch iTunes (I can actually make this myself...that's a simple piece of scripting), and it should remember it's position from time to time (think this is standard behaviour).

Then
- pressing "Play" in this window would send selection to play immediately.
- Pressing + would add to the playlist.

To see what I mean try look up http://www.versiontracker.com/dyn/moreinfo/macosx/19324 . This little piece of freeware launches iTunes when it is launched on it's own, and provides a floating window which integrates nicely with iTunes.

Well, this was just an idea - the current implementation works out nicely!

Thanks

Sune

P.S. A bonus feature would be a "Play+" buttom. When clicked, it would send the currently selected track + the following X tracks BELOW the currently selected track, in case only one track is selected (basically allowing me to search for something in iTunes, then click on the first hit and activate the "Play+" buttom for sending X tracks to the player, without having to make a selection first...). You could either make X a number that we can adjust ourselves OR just fix it to a value of, say, 30 tracks or less (if there is less than 30 tracks, ofcourse).

kensanata
2008-03-22, 09:59
The problem I have right now is that the same script doesn't seem to work correctly when run as a script within iTunes! Does it work for you? I was trying to add some checks such as "check that we're actually running on version 7" and stuff like that. "do shell script" seems to return the empty string within iTunes. What a bummer.

I'm experimenting with having the "do shell script" being part of a 'tell application "Finder"'...

Sune
2008-03-22, 16:06
Hi there,

Your script worked for me w/o any problems. I only played directly, I didn't append. One thing, however. If my Mac connect the SC 7 server, then iTunes hangs. For how long, I have yet to find out. Not a big issue - force-quit still works :-)

/Sune

fredgoodman
2012-12-08, 10:29
This is probably not of the most general interest these days, but it is useful to me.

I tried the script of Alex Schroeder, but it did not run for me (on OS X Lion, LMS 7.7 & iTunes 10.7). I got it to run by changing the path specification from file_id URL to POSIX path. I also had to restore code from Brad Mohr's earlier script for translating the POSIX path into "escaped" form.

I also put in the possibility of specifying the player rather than controlling only the default player.

I have tested it a few times, also running it from the iTunes script menu, and specifying different players. Seems to work OK now.

I won't be able to help with details of its operation as I don't actually understand anything about applescript programming!

Here is the script:


--SlimPlay
-- minor modifications of work of Alex Schroeder by F. Goodman
--December 2012
-- SlimPlay
-- by Alex Schroeder, kensanata@gmail.com
-- March 2008
-- by Brad Mohr, bmohr (AT) seanet (DOT) com
-- 22 January 2003
-- This script is absolutely free and may be used by anyone for any purpose.

-- Known Limitations:
-- Currently only supports a single Squeezebox.
-- Very little error checking

-- edit these properties to match your setup.
property squeezecenter_host : "localhost" -- URL or IP address of the SlimServer
property squeezecenter_port : "9090" -- server port number for the command line interface, default is 9090
property player_id : " " -- MAC address of desired player; leave blank to use default or only player


tell application "iTunes"
set these_tracks to the selection of browser window 1
if these_tracks is {} then error "No tracks are selected in the front window."

set should_play to false

display dialog "What would you like to do with these tracks?" buttons {"Play", "Append", "Cancel"} default button 2
if the button returned of the result is not "Cancel" then
if the button returned of the result is "Play" then set should_play to true

set is_first_file to true

repeat with a_track in these_tracks
set carbon_filepath to the location of a_track
set track_title to the name of a_track

tell application "Finder" to set filepath to POSIX path of carbon_filepath
set escaped_path to encode_text(filepath, true, false) of me
if should_play then
if is_first_file then
playlist_play_track(escaped_path) of me
set is_first_file to false
else
playlist_append_track(escaped_path) of me
end if
else
playlist_append_track(escaped_path) of me
end if
end repeat

if should_play then
begin_playing() of me
end if
end if
end tell

on encode_text(this_text, encode_URL_A, encode_URL_B)
set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
set the URL_B_chars to "().-_:"
set the acceptable_characters to the standard_characters
if encode_URL_A is false then
set the acceptable_characters to the acceptable_characters & the URL_A_chars
if encode_URL_B is false then
set the acceptable_characters to the acceptable_characters & the URL_B_chars
set the encoded_text to ""
repeat with this_char in this_text
if this_char is in the acceptable_characters then
set the encoded_text to (the encoded_text & this_char)
else
set the encoded_text to (the encoded_text & encode_char(this_char)) as string
end if
end repeat
return the encoded_text
end encode_text

-- this sub-routine is used to encode a character
-- sample code from Apple
-- (doesn't work right for utf8)
on encode_char(this_char)
set the ASCII_num to (the ASCII number this_char)
set the hex_list to
{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
set x to item ((ASCII_num div 16) + 1) of the hex_list
set y to item ((ASCII_num mod 16) + 1) of the hex_list
return ("%" & x & y) as string
end encode_char

-- append the new track to the playlist
on playlist_append_track(escapedTrackPath)
send_command("playlist add " & escapedTrackPath)
end playlist_append_track


-- replace the existing playlist with the new track
on playlist_play_track(escapedTrackPath)
send_command("playlist play " & escapedTrackPath)
end playlist_play_track


-- tell the default (or only) server to begin playing
on begin_playing()
send_command("play")
end begin_playing

on send_command(command)
tell application "Finder"
set shell_command to "echo '" & player_id & command & "\\nexit' | /usr/bin/nc " & squeezecenter_host & " " & squeezecenter_port & "; exit 0"
-- display dialog shell_command buttons {"Ok"}
set result to do shell script shell_command
-- display dialog result buttons {"Ok"}
end tell
end send_command

fredgoodman
2012-12-10, 14:19
I made a new variant on the script that I previously posted. The new versions allows arbitrary unicode in paths (so it's good for tracks with titles containing accented characters, etc.).

I posted the new script to a new thread, http://forums.slimdevices.com/showthread.php?97523-Sending-tracks-from-iTunes-to-Squeezebox-(mac-only-uses-applescript)