By now I have completed all parts of the system! It just rocks (finally my Roku is a useful device...).
Here is the how I did it:
- on your NSLU install the fantastic perl script for displaying the weather information - follow instructions from here:
http://billiatjapan.netfirms.com/Tools4Roku/index.html
- modify the main script by the following code (the while(1) loop):
while (1) {
$display->open || die("Could not connect to Roku Soundbridge");
$display->cmd("irman echo");
#$display->msg(text => "loop...", x => 0, y => 0, duration => 0, keygrab => 0);
do
{
my ($p, $m ) = $display->{connection}->waitfor(Match => '/irman: .*/',
Timeout => $minitimeout);
if ($m)
{
$m =~ s/^irman: //;
if (($m eq "CK_SEARCH") and ($display->ison())) {
$menu = 1;
};
};
}
until ($menu == 1 );
if ($menu == 1 )
{
$display->cmd("irman intercept");
$display->cmd("irman dispatch CK_EXIT");
showcode("1");
$display->close();
$menu = 0;
};
};
and put in the same file, somewhere in the section on subs, an additional function:
sub showcode {
my $from = shift;
my $position = 0;
my $myselection = -1;
my $rc;
my $myexit;
my ($p, $m);
my $digits = 1; # we start from second digit
my @arrdig = ("_","_","_","_");
my $i;
my $j;
$display->clear();
do
{
$rc = $display->msg(text => "Kod: ".$arrdig[1].$arrdig[2].$arrdig[3], font => 2, x=>10, y=> 0, duration =>6, keygrab => 1, clear => 1);
# we do not show the first digit (0)
if($rc eq "CK_PREVIOUS") {$arrdig[$digits] = 1; $digits++; };
if($rc eq "CK_PLAY") {$arrdig[$digits] = 2; $digits++;};
if($rc eq "CK_NEXT") {$arrdig[$digits] = 3; $digits++; };
if($rc eq "CK_PAUSE") {$arrdig[$digits] = 4; $digits++; };
if($rc eq "CK_VOLUME_UP") {$arrdig[$digits] = 5; $digits++; };
if($rc eq "CK_SHUFFLE") {$arrdig[$digits] = 6; $digits++; };
if($rc eq "CK_ADD") {$arrdig[$digits] = 7; $digits++; };
if($rc eq "CK_VOLUME_DOWN") {$arrdig[$digits] = 8; $digits++; };
if($rc eq "CK_REPEAT") {$arrdig[$digits] = 9; $digits++; };
if($rc eq "CK_WEST")
{
if($digits>1){ # only move back to second digit
$digits--;
$arrdig[$digits] = "_";
};
};
if($rc eq "CK_SOUTH") {$arrdig[$digits] = 0; $digits++; };
if($rc eq "timeout") {$myexit = 1 };
if($rc eq "CK_EXIT") {$myexit = 1 };
} until (($myexit == 1) or ($digits == 4));
# Execute the search
if (not $myexit == 1)
{
#$display->msg(text => "Szukam: ".$arrdig[0].$arrdig[1].$arrdig[2].$arrdig[3], x => 0, y => 0, duration => 0, keygrab => 0);
$display->close();
select(undef, undef, undef, 0.25);
$display->open || die("Could not connect to Roku Soundbridge");
#$display->cmd("rcp");
#$display->cmd("
#get to entering numbers in albums
$display->cmd("irman dispatch CK_EXIT");
select(undef, undef, undef, 0.05);
$display->cmd("irman dispatch CK_SEARCH");
select(undef, undef, undef, 0.05);
$display->cmd("irman dispatch CK_SOUTH");
select(undef, undef, undef, 0.05);
$display->cmd("irman dispatch CK_SELECT");
select(undef, undef, undef, 0.05);
$display->cmd("irman dispatch CK_NORTH");
select(undef, undef, undef, 0.05);
$display->cmd("irman dispatch CK_NORTH");
#process with entering number
for($i = 0; $i < 4; $i++)
{
for($j = 0; $j < $arrdig[$i]; $j++) { $display->cmd("irman dispatch CK_EAST");select(undef, undef, undef, 0.05); };
#select
$display->cmd("irman dispatch CK_SELECT");
select(undef, undef, undef, 0.05);
# then move back
for($j = 0; $j < $arrdig[$i]; $j++) { $display->cmd("irman dispatch CK_WEST");select(undef, undef, undef, 0.05); };
};
$display->cmd("irman dispatch CK_SOUTH");
select(undef, undef, undef, 0.05);
$display->cmd("irman dispatch CK_SOUTH");
select(undef, undef, undef, 0.05);
$display->cmd("irman dispatch CK_SOUTH");
select(undef, undef, undef, 0.05);
$display->cmd("irman dispatch CK_SELECT");
for($j = 0; $j < 30; $j++) {
select(undef, undef, undef, 0.1);
$display->cmd("irman dispatch CK_PLAY");
};
};
};
(it's a rough code, and could be optimized...)
Then create a separate script to discover the presence of the roku (it kills the main script if the roku is turned off) :
#! /bin/sh
#Set the IP of the controlled Soundbridge
ROKUIP=192.168.2.101
#Set the location of your main weather script
TOOLSDIR=/opt/etc/tools4roku
TOOLSFILE=t4roku.plC
#Set the directory where the PIDs files are stored
PIDDIR=/var/run
PIDFILE=Tools4roku1.pid
while [ 1 ]
do
#echo "Pinging"
if ping $ROKUIP -c 1 | grep round -q
then
#echo "Found"
if [ -e $PIDDIR/$PIDFILE ]; then
#echo "Service already started"
test 1
else
#echo "Starting Service"
cd $TOOLSDIR
perl $TOOLSFILE &
ps | grep perl | grep $TOOLSFILE | sed s/\ \a.*// > $PIDDIR/$PIDFILE
fi
else
#echo "Not found"
if [ -e /$PIDDIR/$PIDFILE ]; then
#echo "Killing and removing"
kill `cat $PIDDIR/$PIDFILE`
rm -f $PIDDIR/$PIDFILE
fi
fi
sleep 5
done
This scirpt has to be launched by one of your [init.d] scripts
Then you have to arrange your music library. Basically, the system works by searching the album names for series of digits in its name. So somehow you have to rename all of your albums in your music library by adding an unique number to all of them. To achieved this used the following process:
1. Re-arrange the music directory into:
[x]:\music\Album Artist - Album\*.mp3
If you use automatic re-arranging (like with the use of Mp3tag) you have to be careful not to allow to spread your albums across several folders if it happens that not all your tracks in albums have been given with the same album artist.
2. Rename all of the album folders into four digits unique name. For this I used this windows batch script:
if %1!==! goto end
if %1!==}{! goto pass2
dir %1\*. /b /o:n > %temp%\}{.dat
set count=0
for /F "tokens=*" %%a in (%temp%\}{.dat) do call %0 }{ "%%a"
del %temp%\}{.dat
goto end
:pass2
set /a count+=1
set fname=%count%
if %count% LSS 10000 set fname=0%count%
if %count% LSS 1000 set fname=00%count%
if %count% LSS 100 set fname=000%count%
if %count% LSS 10 set fname=0000%count%
rmdir %2 %fname%
:end
save this code into a new file [give-code.bat] to your [x]:\ directory and run from command line by giving the name of your muisc folder as the parameter:
[code
x:\>give-code.bat music
[/code]
- this is irreversible, so be careful and test before going full scale!
3. Use your favorite mp3 tag editor (I used Mp3tag v.2.39) to import the name of the folder into the album tag. Because of the limits of the software I had to do this in two stages: first import the code into the "comment" tag, then export it again into the name of the folder merged with the name of the album taken from the album tag. Then again import the merged name of the folder (\XXXX - Album name\) into the 'album' tag. Because my music library is located on the network drive connected to the NSLU, the whole process took like ... 6 hours...
4. Reboot everything and enjoy!
MANUAL:
- the roku has to be connected to your music library!
- to enter the code, press the 'search' button and provide the code with the buttons on your remote:
down = 0
|<< = 1
> = 2
>>| = 3
|| = 4
vol up = 5
shuffle = 6
add = 7
vol down = 8
repeat = 9
- searching starts with entering the last digit.
The last stage was a creation of the 'menu'. For this I used the Mp3tag function of exporting of your music collection data to the Excel file. Then I made a pivot table and selected only genre, album and artist. Then I copied to Word and made some fancy looking menu... I only need to get somehow that nice leather folders that they have in the restaurants
