package album;
use Globals;
use CGI;
use Globals qw(%PLATTERS);
use Globals qw(@CUSTOM);
use Globals qw($delim);
use strict;
sub new {
my $self = {
mime => "text/html",
playlist => undef,
artist => undef,
coverCount => 0,
info => undef,
platter => undef,
currentAlbum => undef,
playlink => undef,
custom => undef,
foreign => undef
};
my $query = CGI::new();
my $target = $query->cookie("target");
if ( $target =~ /narrow/ )
{
$self->{playlist} = openTemplate("albumNarrow");
}
else
{
$self->{playlist} = openTemplate("album");
}
bless ($self);
return $self;
}
sub desc {
return "Used internally to build album views";
}
sub header {
my $self = shift;
my ($artist, $album) = @_;
$self->{artist} = $artist;
$self->{album} = $album;
#print $artist;
foreach ( @CUSTOM ) {
if ($artist eq $_) {
$self->{custom} = 1;
last;
}
}
# make a nice display for the albums
$album =~ /(\d{2} - |)(.*?)( \((\d{4})\)|)$/;
my $albumname = $2; my $year = $4;
my $htmlalbum = ''.makeHTML($2).'';
$htmlalbum = '' if ($albumname eq 'Miscellany');
# initialise the playlist
$self->{playlist} =~ s/%ALBUM%/$album/g;
$self->{playlist} =~ s/%HTMLALBUM%/$htmlalbum/g;
$self->{playlist} =~ s/%ARTIST%/$artist/g;
$self->{playlist} =~ s/%YEAR%/
$year<\/b>/g;
$self->{playlink} = 'search.plx?artist='.makeUnNice($artist).'&album='.makeUnNice($album).'&exact=1&searchFor=track&inv=%INV%&filter=music,video,shortcut';
$self->{currentAlbum} = makeNice($album);
}
sub track {
my $self = shift;
my ($folder, $trackartist, $album, $year, $track, $url, $platter) = @_;
if ($track =~ /(cover|artist).*\.(gif|jpg|png)$/i) {
# put the image and label in if not there yet
if (!($self->{coverCount})) {
my $cover = '
'.
'Image from Nobody (0 of %TOTALCOVERS%)';
$self->{playlist} =~ s/%COVER%/$cover/;
}
# insert into the javascript arrays
my $coverLoc = "locations[$self->{coverCount}] = '".makeJs('http://'.$PLATTERS{$platter}.$url)."';\n ";
$self->{playlist} =~ s/%LOCATIONS%/$coverLoc%LOCATIONS%/;
my $coverSource = "sources[$self->{coverCount}] = '$platter';\n ";
$self->{playlist} =~ s/%SOURCES%/$coverSource%SOURCES%/;
$self->{coverCount}++;
}
elsif ($track =~ /info\.txt$/i) {
$self->{info} .= '
'.$platter.' says:
'.getFile('http://'.$PLATTERS{$platter}.$url)."\n";
}
else { # add the track
# look to see if we're on a child album and report it
my $trackhtml;
my $nicealbum = makeNice($album);
if ($self->{currentAlbum} ne $nicealbum) {
my $albumstub = $nicealbum;
$albumstub =~ s/^\Q$self->{album}\E\///;
$trackhtml = '
'.makeHTML($albumstub)."\n";
}
$self->{currentAlbum} = $nicealbum;
# link to other folder if present
my $foreigner;
foreach (($folder, $trackartist)) {
my $thisArtist = $_;
my $thisNiceArtist = makeNice($thisArtist);
if ($thisArtist && !($thisNiceArtist =~ /^$self->{artist}$/i) && !($thisNiceArtist =~ /^$folder$/i) ) {
$foreigner = '
';
$foreigner .= 'with ' if (!$self->{custom});
$foreigner .= ''.makeHTML($thisArtist).'' ;
}
}
# paste the track in
$trackhtml .= '

'.makeHTML($track)."$foreignerNo further info available' ;
}
else {
$infolink = '
';
}
my $playbutton; my $hostreport;
# playbutton
if ($self->{platter}) {
$playbutton = ''.
'
';
$hostreport = 'Hosted by %SOURCE%';
}
$self->{playlist} =~ s/%PLAYBUTTON%/$playbutton/;
$self->{playlist} =~ s/%HOST%/$hostreport/;
#all other vars
my $source = $self->{platter};
$self->{playlist} =~ s/%SOURCE%/$source/;
$source = '' if ($source eq 'Various');
$self->{playlist} =~ s/%INV%/$source/;
$self->{playlist} =~ s/%INFO%/$info/;
$self->{playlist} =~ s/%INFOBUTTON%/$infolink/;
my $link = $self->{foreign};
$self->{playlist} =~ s/%FOREIGN%/$link/;
return $self->{playlist};
}
return 1;