Slash Boxes
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)

  (email not shown publicly)
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Friday February 08, 2002
11:11 AM


[ #2726 ]
# I use this to put the current track I am listening to
# on; each time a new MP3 is selected, it sends
# an HTTP request to 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)$/;

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("$data");
        $foo = 1;

    alarm 0;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.