summaryrefslogtreecommitdiff
path: root/cgi-bin/playlists/album.pm
blob: 89f92739187a386a267832592f18fb2093079e64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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 = '<a href="front.plx?artist='.makeUnNice($artist).'&album='.makeUnNice($album).'" class="heading" target="_top" title="Platter link to '.$album.'"><span class="title">'.makeHTML($2).'</span></a>';
    $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%/<br>&nbsp;<b>$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 = '<p><a href="javascript:nextCover()"><img border=0 name="cover" id="cover" alt="Click for next image"></a><br>'.
                '<small>Image from <strong name="coversource" id="coversource">Nobody</strong>&nbsp;(<span name="coverno" id="coverno">0</span> of %TOTALCOVERS%)</small><script>nextCover();</script>';
    
            $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} .= '<p><i>'.$platter.' says:</i><br>'.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 = '<br><b>'.makeHTML($albumstub)."</b>\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 = '<br><small><i>';
                $foreigner .= 'with ' if (!$self->{custom});
                $foreigner .= '<a href="artist.plx?name='.makeUnNice($thisArtist).'&exact=1" target="_parent">'.makeHTML($thisArtist).'</a></i></small>' ;
            }
        }

        # paste the track in  
        $trackhtml .= '<li><a href="'.makeTrackURL($PLATTERS{$platter}, $url, $folder, $trackartist, $track ).'"><img src="/platdoc/img/filebutton_s.png" border=0 align="top"></a><a href="'.makeTrackPlaylist($folder, $trackartist, $album, $track, $platter).'"><img src="/platdoc/img/playbutton_s.png" border=0 align="top"> '.makeHTML($track)."</a>$foreigner</li>\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} = "&nbsp;<i>from <a href=\"artist.plx?name=".makeUnNice($artistlink)."&album=".$album."\" target=\"_parent\">$artistlink</a>";
            }
            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 = '<p><i>No further info available</i>' ;
    }
    else {
        $infolink = '<a href="#info"><img src="/platdoc/img/infobutton.png" width=32 height=32 border=0 alt="Information"></a>';
    }
    
    my $playbutton; my $hostreport;
    
    # playbutton
    if ($self->{platter}) {
        $playbutton = '<a href="'.$self->{playlink}.'">'.
        '<img src="/platdoc/img/playbutton.png" width=32 height=32 border=0 alt="Play"></a>';
        $hostreport = 'Hosted by <strong>%SOURCE%</strong>';
    }
    $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;