M@trixXov brlôžtek

   I’ll be there when you fall   And they’ll be no pain at all  And I’ll be your shelter... Your shelter from the storm

Web Remote Control for Amarok 1.4

This is very simple and not very fail-proof script, which, when enabled, starts small web-server on localhost:4775 with now playing information and very basic controls (volume up/down, next, previous, play/pause, stop, rating plus/minus). ® is for refreshing the page, but it automaticaly refreshes each 6 seconds.
Requirements: perl, perl module HTTP::Server::Simple

It doesn't depend on any input from amarok, so you can run it just by starting the script. Another possibility is to create folder ~/.kde/share/apps/amarok/scripts/matrixx-web and there the file matrixx-web.pl (don't forget to add +x permissions) and the specs-file (all the way down). You can rename matrixx-web to whatever else, but you have to do it everywhere (folder and both file names).

For trinity: i think the folder name will be ~/.trinity/share/apps/amarok/scripts/matrixx-web - everything else should be the same.

#!/usr/bin/perl
 {
 package MyWebServer;
 
 use HTTP::Server::Simple::CGI;
 use base qw(HTTP::Server::Simple::CGI);
 
 my %dispatch = ( # list of supported adresses and its functions
     '/' => \&default,
     '/playpause' => \&playpause,
     '/stop' => \&stop,
     '/prev' => \&prev,
     '/next' => \&next,
     '/volumeup' => \&volumeup,
     '/volumedown' => \&volumedown,
     '/ratingplus' => \&ratingplus,
     '/ratingminus' => \&ratingminus,
     '/hello' => \&resp_hello,
     # ...
 );
 
 sub handle_request { # request handler
     my $self = shift;
     my $cgi  = shift;
   
     my $path = $cgi->path_info();
     my $handler = $dispatch{$path};
 
     if (ref($handler) eq "CODE") {
         print "HTTP/1.0 200 OK\r\n";
         $handler->($cgi);
         
     } else {
         print "HTTP/1.0 404 Not found\r\n";
         print $cgi->header,
               $cgi->start_html('Not found'),
               $cgi->h1('Not found'),
               $cgi->end_html;
     }
 }
 
# there are all the supported functions:

# default is the website, everything else is only for control in iframe.

 sub default {
     my $cgi  = shift;   # CGI.pm object
     return if !ref $cgi;
     
     my $who = $cgi->param('name');
     
my $year = `dcop amarok player year`;
my $hviezd = `dcop amarok player rating`;
my $rating="";
my $status = `dcop amarok player status`;

while($hviezd > 1){$rating .= "★"; $hviezd -= 2;}
if ($hviezd == 1){$rating .= "<span style=\"font-size:65%\">★</span>";}


chomp $year;

     print $cgi->header(-type=>'text/html; charset=UTF-8', -Refresh=>'6'),
           $cgi->start_html("amaroK"),
           $cgi->style('body { font-family: sans-serif; font-size: 24pt; text-align: center;} a {text-decoration:none; margin:7px; padding: 7px;}');
print $cgi->div({-style=>'background-color:#DDD'},
         "M\@trixX\'s amaroK now Playing + remote control :)"
           );
print "<br>";
if ($status == 0){print " ■ ";}
elsif ($status == 1){print "<div style=\"text-decoration:blink\"> ▌▌ ";}
elsif ($status == 2){print " ▶ ";}

print `dcop amarok player currentTime`." / ".`dcop amarok player totalTime`."<br>\n";
if ($status == 1){print "</div>";}

print $cgi->b(`dcop amarok player title`)."<br>\n";
print `dcop amarok player artist`."<br>\n";
print `dcop amarok player album`." ($year)"."<br>\n";

print "<div>";
print $rating;
print "</div>\n<br>\n";

print $cgi->div({-style=>'background-color:#DDD'},
         '<a href="volumedown" target=nic> ◢- </a> &nbsp; <a href="volumeup" target=nic> ◢+ </a> &nbsp; <a href="prev" target=nic> << </a> &nbsp; <a href="stop" target=nic> ■ </a> &nbsp; <a href="playpause" target=nic> ▶ </a> &nbsp; <a href="next" target=nic> >> </a> <a href="ratingminus" target=nic> ☆ </a> &nbsp; <a href="ratingplus" target=nic> ★ </a> &nbsp;  &nbsp; <a href="/"> ® </a> <br>'
           );
print "<iframe name=nic style=\"border: 0;\" width=500 height=50>";
print           $cgi->end_html;
     }

sub playpause {
 my $cgi  = shift;
system("dcop amarok player playPause");
     print $cgi->header,
           $cgi->start_html,
           $cgi->center("play / pause"),
           $cgi->end_html;
  }

sub stop {
 my $cgi  = shift;
system("dcop amarok player stop");
     print $cgi->header,
           $cgi->start_html,
           $cgi->div("stop"),
           $cgi->end_html;
  }

sub volumeup {
 my $cgi  = shift;
my $slon = system("dcop amarok player volumeUp");
     print $cgi->header,
           $cgi->start_html,
           $cgi->div("volume up to ".`dcop amarok player getVolume`),
           $cgi->end_html;
  }

sub volumedown {
 my $cgi  = shift;
system("dcop amarok player volumeDown");
     print $cgi->header,
           $cgi->start_html,
           $cgi->div("volume down to ".`dcop amarok player getVolume`),
           $cgi->end_html;
  }

sub prev {
 my $cgi  = shift;
system("dcop amarok player prev");
     print $cgi->header,
           $cgi->start_html,
           $cgi->div("previous track ".`dcop amarok playlist getActiveIndex`." of ".`dcop amarok playlist getTotalTrackCount`." in playlist"),
           $cgi->end_html;
  }

sub ratingplus {
 my $cgi  = shift;
my $hviezd = `dcop amarok player rating`;
$hviezd++;
system("dcop amarok player setRating $hviezd");
     print $cgi->header,
           $cgi->start_html,
           $cgi->div("rating plus: set rating $hviezd"),
           $cgi->end_html;
  }

sub ratingminus {
 my $cgi  = shift;
my $hviezd = `dcop amarok player rating`;
$hviezd--;
system("dcop amarok player setRating $hviezd");
     print $cgi->header,
           $cgi->start_html,
           $cgi->div("rating minus: set rating $hviezd"),
           $cgi->end_html;
  }

sub next {
 my $cgi  = shift;
my $slon = system("dcop amarok player next");
     print $cgi->header,
           $cgi->start_html,
           $cgi->div("next track ".`dcop amarok playlist getActiveIndex`." of ".`dcop amarok playlist getTotalTrackCount`." in playlist"),
           $cgi->end_html;
  }

 sub resp_hello {
     my $cgi  = shift;   # CGI.pm object
     return if !ref $cgi;
     
     my $who = $cgi->param('name');
     
     print $cgi->header,
           $cgi->start_html("Hello"),
           $cgi->h1("Hello $who!"),
           $cgi->end_html;
     }
 
 } 
 
 # start the server on port 8080
 my $pid = MyWebServer->new(4775)->run();
 print "Use 'kill $pid' to stop server.\n";

The specs file - ~/.kde/share/apps/amarok/scripts/matrixx-web/matrixx-web.spec :
name = M@trixX's Modified Web Control
type = generic