68 |
my ( $uri ) = (@_); |
my ( $uri ) = (@_); |
69 |
|
|
70 |
# |
# |
71 |
|
# See if we should just return a random directory... |
72 |
|
# |
73 |
|
if ( $uri =~ /^\/random\/directory/ ) |
74 |
|
{ |
75 |
|
&handleRandomDirectory( ); |
76 |
|
exit; |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
|
# |
81 |
# See if we were called as a result of our form submission or not. |
# See if we were called as a result of our form submission or not. |
82 |
# |
# |
83 |
if ( $uri =~ /^\/random\/play/ ) |
if ( $uri =~ /^\/random\/play/ ) |
237 |
$form .= "<option value=\"50\">50</option>\n"; |
$form .= "<option value=\"50\">50</option>\n"; |
238 |
$form .= "</select>\n"; |
$form .= "</select>\n"; |
239 |
$form .= "<input type=\"submit\" name=\"submit\" value=\"Try Again\">\n"; |
$form .= "<input type=\"submit\" name=\"submit\" value=\"Try Again\">\n"; |
240 |
$form .= "</form></td></tr></table>\n"; |
$form .= "[ <a href=\"/random/directory\">Random Directory</a> ] </form> </td></tr></table>\n"; |
241 |
$output .= $form; |
$output .= $form; |
242 |
|
|
243 |
|
|
349 |
close( $data ); |
close( $data ); |
350 |
exit; |
exit; |
351 |
} |
} |
352 |
|
|
353 |
|
|
354 |
|
# |
355 |
|
# Choose a random line from the cache file, and work out the |
356 |
|
# directory the given track lives in. |
357 |
|
# |
358 |
|
# Issue a redirect to force the user to view that. |
359 |
|
# |
360 |
|
# |
361 |
|
sub handleRandomDirectory( ) |
362 |
|
{ |
363 |
|
|
364 |
|
open( FILY, "<$tag_cache" ); |
365 |
|
my @lines = <FILY>; |
366 |
|
close( FILY ); |
367 |
|
|
368 |
|
# Pick a random line from the database. |
369 |
|
my $random = $lines[ rand @lines ]; |
370 |
|
if ( $random =~ /([^\t]+)\t(.*)/ ) |
371 |
|
{ |
372 |
|
$random = $1; |
373 |
|
} |
374 |
|
|
375 |
|
# |
376 |
|
# We only care about the directory name. |
377 |
|
# |
378 |
|
if ( $random =~ /(.*)\/(.*)$/ ) |
379 |
|
{ |
380 |
|
$random = $1; |
381 |
|
} |
382 |
|
|
383 |
|
# |
384 |
|
# Strip off the root |
385 |
|
# |
386 |
|
if ( $random =~ /$ROOT\/(.*)/ ) |
387 |
|
{ |
388 |
|
$random= $1; |
389 |
|
} |
390 |
|
|
391 |
|
&sendData($data, "HTTP/1.0 300 OK\nLocation: /$random\n\n" ); |
392 |
|
|
393 |
|
exit; |
394 |
|
|
395 |
|
} |