#!/usr/bin/perl # Blosxom Plugin: slimserver # Author: Michael Dickerson # Version: 2005-11-12 package slimserver; use strict; #use warnings; # generates bogus "$blosxom::usr used only once" etc. # ----- Configuration variables: see pod documentation for explanations ----- my $CGI_URL = "/~mikey/slimserver.pl"; my $SONG_FILE = "/home/mikey/www/blosxom/plugins/state/songinfo.txt"; #my $SONG_FILE = "$blosxom::plugin_state_dir/songinfo.txt"; # ----- Export variables (use in stories as $slimserver::now_playing, etc) ----- my $now_playing = ''; # ----- end of export variables ----- # because I think I'm funny my @weapons = ( 'Candlestick', 'Revolver', 'Wrench', 'Rope', 'Knife', 'Lead Pipe' ); sub start { return (-f $SONG_FILE); } sub head { our $now_playing; if ($blosxom::static_or_dynamic eq 'static') { # when doing static rendering, output a SSI pointer to the dynamic # script $now_playing = "\n"; } else { $now_playing = &read_now_playing_from_files(); } return 1; } sub read_now_playing_from_files() { # the songinfo.txt is already a bite-size piece of HTML, but we parse it # ourselves so that we can display any format we want my %song; open SONG, "<$SONG_FILE" or die("can't open $SONG_FILE: $!"); while (my $line = ) { $line =~ m/([\w ]+):<\/b> <\/td>(.*?)<\/td>/ && ($song{$1} = $2); $line =~ m// && ($song{"url"} = $1); } close SONG; my $html = "
\n"; # 8 Jun 08 mikey: hack: relative path "albumart.jpg" not working now, hard # coded /albumart.jpg instead. # 3 Oct 08 mikey: disabled art posting because some of the files are like # 1 MB and that creates a long delay between songs when playing #$html .= "

\""

\n"; $html .= "

" . $song{"Song"} . "
"; $html .= "from " . $song{"Album"} . " by " . $song{"Artist"} . "
"; #$html .= "in the " . $song{"Played on"} . "
"; #$html .= "with the " . @weapons[rand(6)] . "
"; $html .= "at " . $song{"Last Updated"} . "

\n"; $html .= "
\n"; return $html; } # if running as a blosxom plugin, just return true, don't do anything at import return 1 if defined($blosxom::url); # otherwise we must be running as a standalone CGI: produce the HTML print "Content-type: text/html\n\n"; print &read_now_playing_from_files();