PDA

View Full Version : play file automatically



lrossouw
2006-08-11, 02:16
I want something that I can run from the windows command line (or other program) that uses command line to play a file automatically.

Let me explain it literally. I have a podcast download program that lets me run a command with the path to the just completed podcast file automatically once the download is complete. Now I want this command to send the file to the squeezebox for playing.

I understand that you can start a file playing with telnet but how do you do it automatically via a command line parameter?

Cheers
Louis

ps: i can write basic bat files and VBA but that is about it. not much of a programmer i'm afraid.

lrossouw
2006-08-14, 16:03
any ideas on this?

Pale Blue Ego
2006-08-14, 23:31
I think you'll find everything you need in the slimserver documentation. Access it from the main slimserver page:

Home | Technical Information | Command Line Interface

lrossouw
2006-08-15, 00:27
hi thanks

i did find the cli/telnet instructions before i typed my original request but what i dont know is how to automate the lot. i have never written a telnet script thingy.

i want to run a command from another program of the form "myfile.bat c:\mysong.mp3" (i.e. the path is a parameter) and the squeezebox must play a song.

not sure if it should be .bat or something else...

regards
louis

mherger
2006-08-15, 00:43
> i did find the cli/telnet instructions before i typed my original
> request but what i dont know is how to automate the lot. i have never
> written a telnet script thingy.

There was once a little tool called sstime which was meant to time CLI
performance, but which can be used to run a couple of CLI commands from a
batch file:

http://forums.slimdevices.com/showthread.php?t=17032&highlight=sstime

But the link to the executable is currently dead :-(. Maybe you could
write the author to ask for it.

--

Michael

-----------------------------------------------------------
Help translate SlimServer by using the
SlimString Translation Helper (http://www.herger.net/slim/)

richidoo
2006-08-15, 05:59
Your podcast program gives you command line access and telnet is a command line program. So you can enter your telnet command and paramenters in the command option and it will run when the download is complete. If the problem is more complex than that you will need to more provide details of the difficulty you are having. Getting any custom command line initiated event to work properly most often requires a bit of experimenting and working it out.

Alternatively, if you know what the file name will be before the download events (standardized filename protocol) then you can use Windows Scheduled Tasks application to make the podcast play at a specific time, but that time will be unrelated to the download time, unless you automate the download with scheduled tasks too. You would still use the telnet command. Scheduled Tasks application is very flexible and easy. It is in Accessories | System Tools
Good Luck!
Rich

lrossouw
2006-08-15, 09:16
hi

Telnet as per windows xp only takes 2 parameters (to my knowledge) e.g: telnet localhost 9090

Does this mean I can't pass a command to it via the commang line?

I need to tell telnet to connect to localhost:9090 and run the play file command and then quit. this all in the one line the command line of the program i'm working with.

I'm sure it can be done just don't know how...

Cheers
Louis

MrC
2006-08-15, 10:14
As you've discovered, telnet does not accept inital command line strings to run upon login (although some accept an argument to run a remote script file). The CLI docs indicate that for Unixy platforms, you can use STDIN. This is not supported under Windows.

You'll need to write your VBA code to launch telnet, connect, and then enter the commands as encoded strings (as per the CLI tech reference indicated earlier in this post) after the login has succeeded. Have your podcast downloader call your script with the proper arguments.

You could also do similar with the Perl module Net::Telnet at :

http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm

which might prove even easier.

MrC
2006-08-15, 10:48
Here's a very simply perl script that allows you to pass a single command line to the SlimServer CLI interface on your localhost. Change to suit your needs:

test.pl
----------
use Net::Telnet ();

my $cmd;
my $result;

$cmd = $ARGV[0];
$t = new Net::Telnet (Timeout => 10);
$t->open(Host => "localhost", Port => 9090);
$t->print($cmd);
$result = $t->getline;
$t->print("exit");
print $result;

test with:

perl test.pl 'version ?'

and it will return the version of slimserver. One Windows, you can download and install ActivePerl or the cygwin environment to get a perl interpretor.

mherger
2006-08-15, 23:12
> But the link to the executable is currently dead :-(. Maybe you could
> write the author to ask for it.

Niek just sent me the new links for sstime:

- C source: http://www.qwertyboy.org/files/sstime.c
- Windows .EXE: http://www.qwertyboy.org/files/sstime.exe
- Linux binary: http://www.qwertyboy.org/files/sstime.bin

--

Michael

-----------------------------------------------------------
Help translate SlimServer by using the
SlimString Translation Helper (http://www.herger.net/slim/)

geoffb
2006-08-16, 08:32
On 8/16/06, Michael Herger wrote:
> > But the link to the executable is currently dead :-(. Maybe you could
> > write the author to ask for it.
>
> Niek just sent me the new links for sstime:
>
> - C source: http://www.qwertyboy.org/files/sstime.c
> - Windows .EXE: http://www.qwertyboy.org/files/sstime.exe
> - Linux binary: http://www.qwertyboy.org/files/sstime.bin
>
This looks like a great tool - I was about to write something similar.
The handy instructions:
http://www.qwertyboy.org/mono/niek.aspx?IChapter=7&Wiki=sstime

Geoff

lrossouw
2006-08-16, 14:00
ok went for perl option.

installed activeperl.

it doesn't have net-telnet library?

how do i get it?

MrC
2006-08-16, 14:08
ok went for perl option.

installed activeperl.

it doesn't have net-telnet library?

how do i get it?

I enclosed a link in my previous post. Its a single perl module file (.pm). Just place that next to your script, or in your perl path somewhere.

lrossouw
2006-08-16, 14:13
cool

i was blind soz. the version is working but it seems to need double quotes.

MrC
2006-08-16, 14:24
Yes, ok, i can see that single quotes won't work as command line quotes in cmd.exe. Sorry, I was using the cygwin bash shell under Windows.

You can place the Telnet.pm module under C:\Perl\lib\Net in ActivePerl.

lrossouw
2006-08-16, 14:35
yeah i placed it there.

i have written a bat file that contains the following:

@echo off
perl runslim.pl "00:04:20:06:3b:85 playlist play %1"

this passes the parameter of the bat file to the perl. this works ok if the parameter does not contain a space...

but as most music folders contain spaces...

any ideas?

seems like i need it to convert it to %20 kind of things?

lrossouw
2006-08-16, 14:56
ok i now have play.pl:
/start code
use Net::Telnet ();

my $f;
my $result;

$f = $ARGV[0];
$t = new Net::Telnet (Timeout => 10);
$t->open(Host => "localhost", Port => 9090);
$t->print("00:04:20:06:3b:85 playlist play ". $f);
$result = $t->getline;
$t->print("exit");
print $result;
/end of code

This works: perl play.pl "Eric%20Clapton"
This doesn't: perl play.pl "Eric Clapton"

Is there a function to change $f to from "Eric Clapton" to "Eric%20Clapton"?

Thanks for all the help!

Cheers
Louis

MrC
2006-08-16, 15:16
Since you really need to escape a number of characters, use the URI escape module

http://search.cpan.org/~gaas/URI-1.35/URI/Escape.pm

The modified example would be:
----

use Net::Telnet;
use URI::Escape;

my @cmd;
my $result;

$cmd = $ARGV[0];

foreach (@ARGV) {
push (@cmd, uri_escape($_));
}

$t = new Net::Telnet (Timeout => 10);
$t->open(Host => "localhost", Port => 9090);
$t->print("@cmd");
$result = $t->getline;
$t->print("exit");
print $result;

----

Your command line will then not require quotes, except to escape chars from cmd.exe.

perl testit.pl Arg1 Arg2 ...

lrossouw
2006-08-16, 15:52
Wooohooo! Thanks for your help. Got it to work.
"My" first perl!

For those who are interested:

Created slimplay.bat with
***
@echo off
perl "C:\Documents and Settings\UserName\My Documents\Perl\play.pl" %1
***
Created play.pl with contents:
***
use Net::Telnet ();
use URI::Escape;


my $f;
my $result;

$f = $ARGV[0];


$t = new Net::Telnet (Timeout => 10);
$t->open(Host => "localhost", Port => 9090);
$t->print("00:04:20:06:3b:85 playlist play ". uri_escape($f) );
$result = $t->getline;
$t->print("exit");
print $result;
***

placed the slimplay.bat in a my windows directory to be on the PATH.

now a command line is
slimplay "My Folder"
My Folder is a subfolder of the music library. This plays all songs in the folder.

slimplay "c:\my library\my folder\" works too
or slimplay "c:\my library\my folder\my song.mp3" (playing a specific file)

So my podcast program automatically sends a new podcast to my squeezebox.

Regards
Louis

MrC
2006-08-16, 16:10
Wooohooo! Thanks for your help. Got it to work.
"My" first perl!

You're welcome. Glad it works.



Created slimplay.bat with
***
@echo off
perl "C:\Documents and Settings\UserName\My Documents\Perl\play.pl" %1
***
Created play.pl with contents:

...

placed the slimplay.bat in a my windows directory to be on the PATH.

now a command line is
slimplay "My Folder"
My Folder is a subfolder of the music library. This plays all songs in the folder.


Can you save yourself a step and get rid of the bat script and just call "perl C:\Documents and Settings\UserName\My Documents\Perl\play.pl Arg1, Arg2..." instead?