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
|
#!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();
|