# I use this to put the current track I am listening to
# on pudge.net; each time a new MP3 is selected, it sends
# an HTTP request to pudge.net which calls a perl script
# to update the current track there. Essentially, this
# just tells the site "this is the track info for the
# just-requested track".
package Apache::MP3::Log;
use strict;
use vars qw(@ISA $VERSION);
use Apache::Constants qw(DECLINED);
use Date::Format;
use LWP::Simple;
use MP3::Info;
use Socket;
use Apache::MP3::Resample;
@ISA = 'Apache::MP3::Resample';
$VERSION = 1.0;
sub stream {
my $self = shift;
my $r = $self->r;
return DECLINED unless -e $r->filename;
# only my IPs for now ... maybe do by cookie/username later
$self->log_mp3 if $r->connection->remote_ip =~ /^10\.0\.1\.(?:132|107|177|108|109)$/;
$self->SUPER::stream;
}
sub log_mp3 {
my $self = shift;
my $r = $self->r;
my $tag = get_mp3tag($r->filename) or return;
my $url = $self->stream_base . $r->uri . '?stream=1';
$url =~ s/%/%25/g;
$url =~ s/ /%20/g;
$url =~ s/&/%26/g;
$url =~ s/;/%3B/g;
my $data = join "%%", @{$tag}{'TITLE', 'ALBUM', 'ARTIST'},
$url, strftime("%C", @{[localtime]});
$data =~ s/[\015\012]+//g;
$data =~ s/%/%25/g;
$data =~ s/&/%26/g;
$data =~ s/;/%3B/g;
my $get;
my $foo = 0;
eval {
local $SIG{ALRM} = sub { die "oops!" };
alarm 10;
$get = get("http://pudge.net/someperlscript?data=$data");
$foo = 1;
};
alarm 0;
}
1;
Re:This cries out for a web service
pudge on 2002-02-09T13:32:12
Yes, I do. But do you know how eager I am to write the web service?
That's right, not very!:)
Actually, since pudge.net is a Slash site, once we finalize the web service interface for Slash, I might do it. But not until then.