summaryrefslogtreecommitdiff
path: root/cgi-bin/search.plx
diff options
context:
space:
mode:
Diffstat (limited to 'cgi-bin/search.plx')
-rw-r--r--cgi-bin/search.plx127
1 files changed, 127 insertions, 0 deletions
diff --git a/cgi-bin/search.plx b/cgi-bin/search.plx
new file mode 100644
index 0000000..ce1513a
--- /dev/null
+++ b/cgi-bin/search.plx
@@ -0,0 +1,127 @@
+#!c:/perl/bin/perl
+
+# UNIX shebang line
+#
+#!/usr/local/bin/perl -w
+
+# Use me
+#
+use CGI;
+use strict;
+use Globals;
+use Globals qw(%PLATTERS);
+use Globals qw(@MUSIC);
+use Globals qw(@VIDEO);
+use Globals qw(@SHORTCUT);
+use Globals qw($delim);
+use Globals qw($debug);
+use playlists::playlist;
+use Search;
+
+my $QUERY = CGI::new();
+my $artist = $QUERY->param( "artist" );
+my $title = $QUERY->param( "title" );
+my $album = $QUERY->param( "album" );
+my $dateFrom = $QUERY->param( "dateFrom" );
+my $dateTo = $QUERY->param( "dateTo" );
+my $scope = $QUERY->param( "scope" );
+my $random = $QUERY->param( "random" );
+my $output = $QUERY->param( "output" );
+my $filter = $QUERY->param( "filter" );
+my $exact = $QUERY->param( "exact" );
+my $inv = $QUERY->param( "inv" );
+my $searchFor = $QUERY->param( "searchFor" );
+
+$searchFor = 'track' unless ($searchFor);
+
+# platter shortcut here
+if ($output eq 'redir') {
+ $searchFor = 'track';
+ $filter = 'music,video';
+ $random = 1; # in case the search returns more than one track
+}
+
+
+# fill in search params
+
+Search::setArtist($artist);
+Search::setTitle($title);
+Search::setAlbum($album);
+Search::setDateFrom($dateFrom);
+Search::setDateTo($dateTo);
+Search::setScope($scope);
+Search::setExact($exact);
+Search::setRandom($random);
+Search::searchFor($searchFor);
+
+# set inventories
+my @invs = split(',', $inv);
+if (scalar(@invs) == 0) {
+ @invs = keys %PLATTERS;
+}
+Search::setInv(@invs);
+
+# find the right file filters
+my @filters = split(',', $filter);
+my @allfilters = ();
+foreach (@filters) {
+ tr/a-z/A-Z/;
+ my @newfilter = eval("@".$_.";");
+ push (@allfilters, @newfilter);
+}
+
+Search::setFilter(@allfilters);
+my $exclTypes = $QUERY->cookie('exclTypes');
+Search::setExclTypes($exclTypes);
+
+my @result = Search::go();
+
+# redirect when there is only one match
+if ($searchFor eq 'artist' && scalar(@result)==1) { # Exact match
+ $result[0] = substr( $result[0], rindex( $result[0] , $delim)+1); # chop off the abc if there
+ print "HTTP/1.0 302 Found\nLocation: artist.plx?name=".makeUnNice($result[0])."&exact=1\nContent-Type:text/html\n\n";
+ exit;
+}
+
+# redirect platter shortcuts
+if ($output eq 'redir') {
+ if (length($result[0]) == 0) { print "HTTP/1.0 404 Not Found\n\n"; exit; }
+ my ($folder, $trackartist, $album, $year, $track, $url, $platter) = split($delim, $result[0]);
+ print "HTTP/1.0 302 Found\nLocation: http://".$PLATTERS{$platter}.$url."\nContent-Type:text/html\n\n";
+ exit;
+
+}
+
+# artist searches must return an artistlist
+if ($searchFor eq 'artist') {
+ $output = 'artistlist';
+}
+
+# if the output format was not specified, get the playlist format from the cookie
+if (length $output == 0) {
+ my $cookie = $QUERY->cookie("format");
+ if (length $cookie == 0) { # default to m3u
+ $cookie = 'extm3u';
+ }
+ $output = $cookie;
+}
+
+my $playlist = playlist->new($output);
+
+unless ($artist) { $artist = "Various" }
+if ($title && !$album) {$album = makeNice($title) }
+if ($random > 0) { $album = "Random ".$album }
+$playlist->header($artist, $album);
+
+foreach( @result) {
+ my @line = split($delim);
+ #print join(',', @line)."\n" if ($debug);
+ $playlist->track(@line);
+}
+
+print "HTTP/1.0 200 OK\nContent-type: ".$playlist->{mime}."\n";
+if ($playlist->{mime} ne "text/html" && $output =~ /^ext(.*)/) {
+ print "Content-Disposition: attachment; filename=\"$artist - $album.$1\";\n";
+ }
+print "\n";
+print $playlist->dump();