Apache::MP3::Log

| | Comments (0)
# 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("https://pudge.net/someperlscript?data=$data");
        $foo = 1;
    };

    alarm 0;
}

1; use.perl.org

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on February 8, 2002 8:11 AM.

MacPerl 5.6.1b4 was the previous entry in this site.

Instant is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.