Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pudge (1)

pudge
  (email not shown publicly)
http://pudge.net/
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Friday February 08, 2002
11:11 AM

Apache::MP3::Log

[ #2726 ]
# 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;
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.