From fa170afd817648f306e322802ca85b6abbd37f74 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Jun 2011 16:33:26 +0200 Subject: Initial commit --- cgi-bin/playlists/album.pm | 197 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 cgi-bin/playlists/album.pm (limited to 'cgi-bin/playlists/album.pm') diff --git a/cgi-bin/playlists/album.pm b/cgi-bin/playlists/album.pm new file mode 100644 index 0000000..89f9273 --- /dev/null +++ b/cgi-bin/playlists/album.pm @@ -0,0 +1,197 @@ +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 = '

Click for next image
'. + '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)."$foreigner
  • \n%TRACKS%"; + + $self->{playlist} =~ s/%TRACKS%/$trackhtml/; + + # check if extract of another album + if (!$self->{foreign} && $self->{album} ne 'Miscellany') { + my $artistlink = makeNice($folder); + if ($artistlink && $artistlink ne $self->{artist}) { # link to proper artist page + $self->{foreign} = " from $artistlink"; + } + else { + $self->{foreign} = " "; # don't check again + } + } + + # update the host + if ($self->{platter} eq "") { + $self->{platter} = $platter; + } + elsif ($self->{platter} ne $platter && $self->{platter} ne 'Various') { + $self->{platter} = 'Various'; + } + + } +} + +sub dump { + my $self = shift; + # remove any unused placeholders + $self->{playlist} =~ s/%COVER%//; + $self->{playlist} =~ s/%TRACKS%//; + $self->{playlist} =~ s/%SOURCES%//; + $self->{playlist} =~ s/%LOCATIONS%//; + $self->{playlist} =~ s/%TOTALCOVERS%/$self->{coverCount}/g; + + # info + my $info = $self->{info}; + my $infolink; + if (!$info) { + $info = '

    No further info available' ; + } + else { + $infolink = 'Information'; + } + + my $playbutton; my $hostreport; + + # playbutton + if ($self->{platter}) { + $playbutton = ''. + 'Play'; + $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; -- cgit v1.2.3