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 ++++++++++++++++++++++++++++++++++++++++ cgi-bin/playlists/artistlist.pm | 78 ++++++++++++++++ cgi-bin/playlists/extm3u.pm | 36 ++++++++ cgi-bin/playlists/extpls.pm | 39 ++++++++ cgi-bin/playlists/extrmp.pm | 53 +++++++++++ cgi-bin/playlists/extwvx.pm | 64 +++++++++++++ cgi-bin/playlists/playlist.pm | 33 +++++++ cgi-bin/playlists/tracks.pm | 85 +++++++++++++++++ 8 files changed, 585 insertions(+) create mode 100644 cgi-bin/playlists/album.pm create mode 100644 cgi-bin/playlists/artistlist.pm create mode 100644 cgi-bin/playlists/extm3u.pm create mode 100644 cgi-bin/playlists/extpls.pm create mode 100644 cgi-bin/playlists/extrmp.pm create mode 100644 cgi-bin/playlists/extwvx.pm create mode 100644 cgi-bin/playlists/playlist.pm create mode 100644 cgi-bin/playlists/tracks.pm (limited to 'cgi-bin/playlists') 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; diff --git a/cgi-bin/playlists/artistlist.pm b/cgi-bin/playlists/artistlist.pm new file mode 100644 index 0000000..5c419c7 --- /dev/null +++ b/cgi-bin/playlists/artistlist.pm @@ -0,0 +1,78 @@ +package artistlist; + +use strict; +use Globals; +use Globals qw(%PLATTERS); +use Globals qw(@MUSIC); +use Globals qw(@VIDEO); +use Globals qw($target); +use Globals qw($delim); +use Globals qw($bgcolour); + +sub new { + my $self = { + mime => "text/html", + playlist => openTemplate("search"), + artistSearch => 0, + section => undef, + shortcuts => '
    ', + count => 0}; + + # show the logo if this is a new page + my $logo; + $logo = '' if ($target eq '_top'); + $self->{playlist} =~ s/%LOGO%/$logo/; + $self->{playlist} =~ s/%BGCOLOUR%/$bgcolour/; + + bless ($self); + return $self; +} + +sub desc { + return "Artist Search Results"; + } + +sub header { + my $self = shift; +} + +sub track { + my ($self, $abc, $artist) = @_; + $artist = $abc if !$artist; + my $firstletter = substr($abc, 0, 1); + if ($firstletter ne $self->{section}) { + $self->{playlist} .= '


    ' if ($self->{section}); + $self->{playlist} .= ''.$firstletter."\n

    "; + $self->{section} = $firstletter; + $self->{shortcuts} .= ''.$firstletter.' '; + } + my $realength = $artist; + $realength=~s/&[^;]*;/x/g; + $realength = (int(length($realength) / 20) +1)*120; + $self->{playlist} .= "

    ". + "".makeHTML($artist)." 
    "; + $self->{count}++; +} + +sub dump { + my $self = shift; + $self->{playlist} .= "\n
    "; + my $shortcuts = $self->{shortcuts}; + $self->{playlist} =~ s/%SHORTCUTS%/$shortcuts/; + + if ($self->{count} > 0) + { + my $REPORT = "Found ".$self->{count}." artists."; + $self->{playlist} =~ s/%COUNT%/$REPORT/; + return $self->{playlist}."

    $REPORT"; + } + else + { + $self->{playlist} =~ s/%COUNT%/

    Sorry, no-one found./; + + return $self->{playlist}.""; + } +} + +return 1; + diff --git a/cgi-bin/playlists/extm3u.pm b/cgi-bin/playlists/extm3u.pm new file mode 100644 index 0000000..01d7eee --- /dev/null +++ b/cgi-bin/playlists/extm3u.pm @@ -0,0 +1,36 @@ +package extm3u; + +use Globals; +use Globals qw(%PLATTERS); +use strict; +use Globals qw($delim); + +sub new { + my $self = { + mime => "audio/x-mpegurl", + playlist => "#EXTM3U\n" }; + bless ($self); + return $self; +} + +sub desc { + return "Standard format for mp3 playlists"; + } + +sub header { +} + +sub track { + my $self = shift; + my ($folder, $trackartist, $album, $year, $track, $url, $platter) = @_; + my $artist = getArtistString($folder, $trackartist); + $self->{playlist} .= + "#EXTINF:180,".makeNice($artist)." - ".makeNice($track)."\n".makeTrackURL( $PLATTERS{$platter}, $url, $folder, $trackartist, $track )."\n"; + } + +sub dump { + my $self = shift; + return $self->{playlist}; + } + +return 1; diff --git a/cgi-bin/playlists/extpls.pm b/cgi-bin/playlists/extpls.pm new file mode 100644 index 0000000..9cc048c --- /dev/null +++ b/cgi-bin/playlists/extpls.pm @@ -0,0 +1,39 @@ +package extpls; + +use strict; +use Globals; +use Globals qw(%PLATTERS); +use Globals qw($delim); + +sub new { + my $self = { + mime => "audio/scpls", + playlist => "[playlist]\n", + count => 0}; + bless ($self); + return $self; +} + +sub desc { + return "Very common audio playlist format"; +} + +sub header { +} + +sub track { + my $self = shift; + my ($folder, $trackartist, $album, $year, $track, $url, $platter) = @_; + my $artist = getArtistString($folder, $trackartist); + $self->{count}++; + $self->{playlist} .= "File".$self->{count}."=".makeTrackURL( $PLATTERS{$platter}, $url, $folder, $trackartist, $track )."\n". + "Title".$self->{count}."=".makeNice($track)."\n". + "Length".$self->{count}."=-1\n"; + } + +sub dump { + my $self = shift; + return $self->{playlist}."NumberOfEntries=".$self->{count}."\nVersion=2\n"; + } + +return 1; diff --git a/cgi-bin/playlists/extrmp.pm b/cgi-bin/playlists/extrmp.pm new file mode 100644 index 0000000..f17eb82 --- /dev/null +++ b/cgi-bin/playlists/extrmp.pm @@ -0,0 +1,53 @@ +package extrmp; + +use strict; +use Globals; +use Globals qw(%PLATTERS); +use Globals qw($delim); + +sub new { + my $self = { + mime => "application/vnd.rn-rn_music_package", + playlist => "\n". + "import,play,replace\n". + '%f', + count => 0}; + bless ($self); + return $self; +} + +sub desc { + return "RealOne Player"; + } + +sub header { + my $self = shift; + my ($artist, $album) = @_; + $self->{playlist} .= "".makeNice($album)."". + "%f". + "".makeNice($album)."". + "\n"; + +} + +sub track { + my $self = shift; + my ($folder, $trackartist, $album, $year, $track, $url, $platter) = @_; + my $artist = getArtistString($folder, $trackartist); + $self->{count}++; + $self->{playlist} .= "\n". + "".$self->{count}."\n". + "".makeNice($track)."\n". + "".makeNice($artist)."\n". + "".makeNice($album)."\n". + "".makeTrackURL( $PLATTERS{$platter}, $url, $folder, $trackartist, $track )."\n". + "\n"; + + } + +sub dump { + my $self = shift; + return $self->{playlist}.""; + } + +return 1; diff --git a/cgi-bin/playlists/extwvx.pm b/cgi-bin/playlists/extwvx.pm new file mode 100644 index 0000000..7decaee --- /dev/null +++ b/cgi-bin/playlists/extwvx.pm @@ -0,0 +1,64 @@ +package extwvx; + +use strict; + +use Globals; +use Globals qw($CGIROOT); +use Globals qw($APPNAME); +use Globals qw(%PLATTERS); +use Globals qw($delim); +use Globals qw(@VIDEO); + +sub new { + my $self = { + mime => "video/x-ms-wvx", + playlist => "\n"}; + bless ($self); + return $self; +} + +sub desc { + return "Windows Media Player Playlist"; + } + +sub header { + my $self = shift; + my ($artist, $album) = @_; + $album =~ /(\d{2} - |)(.*)(\((\d{4})\)|)/; + $self->{playlist} .= "$2". + "$artist". + "\n"; +} + +sub track { + my $self = shift; + + my ($folder, $trackartist, $album, $year, $track, $url, $platter) = @_; + my $artist = getArtistString($folder, $trackartist); + + my $mediatype = "audio"; + $track =~ /.*\.(.*?)/i; + my $filetype = $1; + foreach (@VIDEO) { + $mediatype = "video" if (/^$filetype$/i); + } + + $self->{playlist} .= "\n". + "".makeNice($track)."\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "Click to go to the ".makeNice($folder)." page\n". + "\n". + "\n". + "\n"; + } + +sub dump { + my $self = shift; + return $self->{playlist}.""; + } + +return 1; diff --git a/cgi-bin/playlists/playlist.pm b/cgi-bin/playlists/playlist.pm new file mode 100644 index 0000000..5ee280e --- /dev/null +++ b/cgi-bin/playlists/playlist.pm @@ -0,0 +1,33 @@ +package playlist; +use strict; +use Globals; + +return 1; + +sub new { + my ($proto, $playlist) = @_; + my $playlister = eval("use playlists::".$playlist."; ".$playlist."->new();"); + if (!defined $playlister) { + $playlister = { + mime => "text/html", + playlist => openTemplate("error"), + }; + $playlister->{playlist} =~ s/%NAME%/$playlist/g; + bless ($playlister); + } + + return $playlister; +} + +sub desc { return "Not Currently Working"; } + +sub header { + } + +sub track { + } + +sub dump { + my $self = shift; + return $self->{playlist}; + } diff --git a/cgi-bin/playlists/tracks.pm b/cgi-bin/playlists/tracks.pm new file mode 100644 index 0000000..5e73766 --- /dev/null +++ b/cgi-bin/playlists/tracks.pm @@ -0,0 +1,85 @@ +package tracks; + +use strict; +use Globals; +use Globals qw(%PLATTERS); +use Globals qw(@MUSIC); +use Globals qw(@VIDEO); +use Globals qw($target); +use Globals qw($delim); +use Globals qw($bgcolour); + +sub new { + my $self = { + mime => "text/html", + playlist => openTemplate("search"), + artistSearch => 0, + count => 0}; + + # show the logo if this is a new page + my $logo; + $logo = '' if ($target eq '_top'); + $self->{playlist} =~ s/%LOGO%/$logo/; + $self->{playlist} =~ s/%BGCOLOUR%/$bgcolour/g; + + bless ($self); + return $self; +} + +sub desc { + return "Track Search Results"; + } + +sub header { + my $self = shift; + $self->{playlist} .= '

      '; +} + +sub track { + my $self = shift; + my ($folder, $trackartist, $album, $year, $track, $url, $platter) = @_; + + $self->{count}++; + + $self->{playlist} .= "
    1. "; + + #prepare urls + + $self->{playlist} .= ' "'.makeHTML($track).""
      "; + + # prepare artist info + foreach( ($folder, $trackartist) ) { + + $self->{playlist} .= "".makeHTML($_)."," if (/.+/); + } + chop $self->{playlist}; # remove trailing comma + + if (length $album > 0) { # album + $self->{playlist} .= "
      from "; + $album =~ s/\(\d{4}\)(\/|$)/$1/; + $self->{playlist} .= makeHTML($album).""; + if ($year > 0) { $self->{playlist} .= " ($year)" } + } + + $self->{playlist} .= "
       
    2. \n"; +} + +sub dump { + my $self = shift; + $self->{playlist} =~ s/%SHORTCUTS%//; + if ($self->{count} > 0) + { + my $REPORT = "Found ".$self->{count}." matches."; + $self->{playlist} =~ s/%COUNT%/$REPORT/; + return $self->{playlist}."

    $REPORT"; + } + else + { + $self->{playlist} =~ s/%COUNT%/

    Sorry, nothing found./; + + return $self->{playlist}.""; + } +} + +return 1; + -- cgit v1.2.3