81 |
else |
else |
82 |
{ |
{ |
83 |
# |
# |
84 |
|
# We weren't, so we must choose some random tracks and |
85 |
|
# present them to the user for inspection. |
86 |
|
# |
87 |
|
|
88 |
|
# |
89 |
# The HTML template we use for output. |
# The HTML template we use for output. |
90 |
# And the text we build up to send. |
# And the text we build up to send. |
91 |
# |
# |
126 |
my @rand = ( ); |
my @rand = ( ); |
127 |
while( $count > 0 ) |
while( $count > 0 ) |
128 |
{ |
{ |
129 |
# |
# Pick a random line from the database. |
|
# Pick a random track. |
|
130 |
my $r = $lines[ rand @lines ]; |
my $r = $lines[ rand @lines ]; |
131 |
|
|
132 |
if ( $r =~ /([^\t]+)\t(.*)/ ) |
if ( $r =~ /([^\t]+)\t(.*)/ ) |
133 |
{ |
{ |
134 |
|
# Save the filename. |
135 |
push @rand, $1; |
push @rand, $1; |
136 |
$count -= 1; |
$count -= 1; |
137 |
} |
} |
164 |
# |
# |
165 |
my $tag = &getSongDisplay( $file, $format ); |
my $tag = &getSongDisplay( $file, $format ); |
166 |
|
|
|
print "$file -> $tag\n"; |
|
|
|
|
167 |
# |
# |
168 |
# Get the containing directory. |
# Get the containing directory. |
169 |
my $dir = $file; |
my $dir = $file; |
173 |
} |
} |
174 |
|
|
175 |
my $link = $dir; |
my $link = $dir; |
176 |
$link = &urlEncode( $link ); |
$link = &urlEncode( $link ); |
177 |
$link .= $suffix; |
$link .= $suffix; |
178 |
|
|
179 |
if ($dir =~ /(.*)\/(.*)$/ ) |
if ($dir =~ /(.*)\/(.*)$/ ) |
180 |
{ |
{ |
181 |
$dir = $1; |
$dir = $1; |
182 |
|
$dir = &urlEncode( $dir ); |
183 |
} |
} |
184 |
$dir = &urlEncode( $dir ); |
|
185 |
$output .= "<li>[<a href='$dir/'>+</a>] · <a href='$link'>$tag</a></li>\n"; |
# Add the entry to the output. |
186 |
|
$output .= "<li>[<a href=\"$dir/\" title=\"Visit the directory containing this track.\">+</a>] · <a href=\"$link\">$tag</a></li>\n"; |
187 |
|
|
188 |
} |
} |
189 |
$output .= "</ul>\n"; |
$output .= "</ul>\n"; |
190 |
|
|
191 |
# |
# |
192 |
# Add a hidden form to contain the selections. |
# Add a hidden form to contain the selections. |
193 |
# |
# |
194 |
my $form = "<table><tr><td><form action='/random/play' method='get'>\n"; |
my $form = "<table><tr><td><form action=\"/random/play\" method=\"get\">\n"; |
195 |
|
|
196 |
$count = 0; |
$count = 0; |
197 |
foreach my $file ( @rand ) |
foreach my $file ( @rand ) |
204 |
# Escape the link to the songs. |
# Escape the link to the songs. |
205 |
$file = &urlEncode( $file ); |
$file = &urlEncode( $file ); |
206 |
|
|
207 |
$form .= "<input type='hidden' name='track$count' value='$file'>\n"; |
$form .= "<input type=\"hidden\" name=\"track$count\" value=\"$file\">\n"; |
208 |
$count ++; |
$count ++; |
209 |
} |
} |
210 |
$form .= "<input type='Submit' name='submit' value='Play'>\n"; |
$form .= "<input type=\"submit\" name=\"submit\" value=\"Play\">\n"; |
211 |
$form .= "</form></td>\n"; |
$form .= "</form></td>\n"; |
212 |
|
|
213 |
|
|
226 |
$form .= "<option value=\"40\">40</option>\n"; |
$form .= "<option value=\"40\">40</option>\n"; |
227 |
$form .= "<option value=\"50\">50</option>\n"; |
$form .= "<option value=\"50\">50</option>\n"; |
228 |
$form .= "</select>\n"; |
$form .= "</select>\n"; |
229 |
$form .= "<input type='Submit' name='submit' value='Try Again'>\n"; |
$form .= "<input type=\"submit\" name=\"submit\" value=\"Try Again\">\n"; |
230 |
$form .= "</form></td></tr></table>\n"; |
$form .= "</form></td></tr></table>\n"; |
231 |
$output .= $form; |
$output .= $form; |
232 |
|
|
303 |
|
|
304 |
# |
# |
305 |
# If we have songs |
# If we have songs |
306 |
|
# |
307 |
if ( ($#songs+1) > 0 ) |
if ( ($#songs+1) > 0 ) |
308 |
{ |
{ |
309 |
# Send playlist header. |
# Send playlist header. |
329 |
close( $data ); |
close( $data ); |
330 |
exit; |
exit; |
331 |
} |
} |
332 |
else |
|
333 |
{ |
# Send error |
334 |
# Send error |
my $header = &getHTTPHeader( 200, "text/html" ); |
335 |
my $header = &getHTTPHeader( 200, "text/html" ); |
&sendData( $data, $header ); |
336 |
&sendData( $data, $header ); |
my $text = &getErrorPage( $ARGUMENTS{'theme'}, |
337 |
my $text = &getErrorPage( $ARGUMENTS{'theme'}, |
"Error - No tracks sent." ); |
338 |
"Error - No tracks sent." ); |
&sendData( $data, $text ); |
339 |
&sendData( $data, $text ); |
close( $data ); |
340 |
close( $data ); |
exit; |
|
exit; |
|
|
} |
|
341 |
} |
} |