rendered paste bodypackage SLZ::Playlist;
use strict;
use warnings;
use Apache2::RequestRec;
use Apache2::RequestIO;
use Apache2::Const -compile => qw(:common);
use Apache2::Request;
use SLZ::DB;
use URI;
sub handler {
my $r = shift;
my $uri = $r->uri();
my $hostname = $r->hostname();
# Extract a valid eid or return an error
if($uri =~ /\/Playlist\/(\d+)/) {
my $eid = $1;
# Fetch the element
my $db = SLZ::DB->new;
my $element = $db->element($eid);
my @aves;
# Extract [av: names
while($element->{content} =~ /\[av:(.*?)(?<!\\)]/g) {
my $name = $1;
$name =~ s/\\]/]/;
push @aves, $name;
}
# Determine the playlist format
if($uri =~ /\.m3u$/) {
# m3u format
$r->content_type('application/m3u');
#$r->print('http://slzone.h1x.com/elements/90/07%20Theme%20for%20a%20Jackal.mp3'. "\n");
$r->print(join "\n", map "http://$hostname/elements/$eid/". URI->new($_), @aves);
$r->print("\n");
} elsif ($uri =~ /\.pls$/) {
# pls format
my $i;
$r->content_type('application/pls');
$r->print("[playlist]\n");
$r->print(join "\n", map "File". ++$i. "=http://$hostname/elements/$eid/". URI->new($_), @aves);
#$r->print("File". ++$i.'=http://slzone.h1x.com/elements/90/07%20Theme%20for%20a%20Jackal.mp3'. "\n");
$r->print("\n");
$r->print("NumberOfEntries=$i\nVersion=2\n");
}
else {return Apache2::Const::NOT_FOUND;}
}
else {return Apache2::Const::NOT_FOUND;}
return Apache2::Const::OK;
}
1;