1282 |
|
|
1283 |
|
|
1284 |
# |
# |
1285 |
# Get a playlist for the given directory. |
# Get a playlist for the given directory - the complexity of this |
1286 |
|
# code is something I wish I could simplify. |
1287 |
|
# |
1288 |
|
# Updated code welcome. |
1289 |
|
# |
1290 |
|
# TODO: Cleanup. |
1291 |
# |
# |
1292 |
sub playlistForDirectory( $ $ $ ) |
sub playlistForDirectory( $ $ $ ) |
1293 |
{ |
{ |
1299 |
# Read in the files for the playlist. |
# Read in the files for the playlist. |
1300 |
# |
# |
1301 |
if ( $recursive ) |
if ( $recursive ) |
1302 |
|
{ |
1303 |
|
@files = &filesInDirRecursively( $dir ); |
1304 |
|
} |
1305 |
|
else |
1306 |
|
{ |
1307 |
|
@files = &filesInDir( $dir ); |
1308 |
|
} |
1309 |
|
|
1310 |
|
# |
1311 |
|
# Downsampling and sort order. |
1312 |
|
# |
1313 |
|
my $quality = ""; |
1314 |
|
if ( defined( $ARGUMENTS{"quality"} ) and |
1315 |
|
length( $ARGUMENTS{"quality"} ) ) |
1316 |
|
{ |
1317 |
|
$quality = "?quality=" . $ARGUMENTS{"quality"}; |
1318 |
|
} |
1319 |
|
|
1320 |
|
if ( defined( $ARGUMENTS{"sort_order" } ) and |
1321 |
|
length( $ARGUMENTS{"sort_order" } ) ) |
1322 |
|
{ |
1323 |
|
$sort_order = $ARGUMENTS{ "sort_order" }; |
1324 |
|
} |
1325 |
|
if ( !length( $sort_order) ) |
1326 |
|
{ |
1327 |
|
$sort_order = '$FILENAME'; |
1328 |
|
} |
1329 |
|
|
1330 |
|
my $final = ""; |
1331 |
|
if ( $advanced_playlist ) |
1332 |
|
{ |
1333 |
|
$final = "#EXTM3U\n"; |
1334 |
|
} |
1335 |
|
|
1336 |
|
# Song tags if any. |
1337 |
|
my $tags = ""; |
1338 |
|
|
1339 |
|
|
1340 |
|
# Set the song format. |
1341 |
|
$tagCache->setFormatString( "#EXTINF:\$LENGTH,$song_format" ); |
1342 |
|
|
1343 |
|
# |
1344 |
|
# Sort the files according to the display preference. |
1345 |
|
# |
1346 |
|
my $sorter = gnump3d::sorting->new( ); |
1347 |
|
$sorter->setTagCache( $tagCache ); |
1348 |
|
@files = &sortFiles( $sort_order, @files ); |
1349 |
|
|
1350 |
|
# |
1351 |
|
# Process each file that we will include in the playlist. |
1352 |
|
# |
1353 |
|
foreach my $file ( @files ) |
1354 |
|
{ |
1355 |
|
# Skip invalid files. |
1356 |
|
next if ( ! isAudio( $file ) ); |
1357 |
|
|
1358 |
|
# Make sure we can read the file. |
1359 |
|
next if ( ! -r $file ); |
1360 |
|
|
1361 |
|
# Debug. TODO - Remove. |
1362 |
|
print "ADDING $file - ....\n"; |
1363 |
|
|
1364 |
|
|
1365 |
|
# |
1366 |
|
# Get the extra details from teh files there. |
1367 |
|
# |
1368 |
|
# Only read the tags if we want them. |
1369 |
|
if ( $advanced_playlist ) |
1370 |
{ |
{ |
1371 |
@files = &filesInDirRecursively( $dir ); |
$tags = ""; |
1372 |
|
$tags = getSongDisplay( $file ) . "\n"; |
1373 |
|
if ( not ( $tags =~ /^#/ ) ) |
1374 |
|
{ |
1375 |
|
# Song doesnt contain tags ... |
1376 |
|
$tags = "#" |
1377 |
|
} |
1378 |
} |
} |
1379 |
else |
|
1380 |
|
if ($file =~ /$ROOT(.*)/) |
1381 |
{ |
{ |
1382 |
@files = &filesInDir( $dir ); |
$file = $1; |
1383 |
} |
} |
1384 |
|
|
1385 |
if ( $random ) |
if ( ! $recursive ) |
1386 |
|
{ |
1387 |
|
$file = $dir . "/" . $file; |
1388 |
|
} |
1389 |
|
|
1390 |
|
if ( $file =~ /(.*)\/\/(.*)/ ) |
1391 |
{ |
{ |
1392 |
# permutes @array in place |
$file = $1 . "/" . $2; |
|
fisher_yates_shuffle( \@files ); |
|
1393 |
} |
} |
1394 |
|
|
1395 |
|
$file = "http://" . $host . urlEncode( $file ) . $quality; |
1396 |
|
|
1397 |
|
$final .= $tags; |
1398 |
|
$final .= $file . "\n"; |
1399 |
|
} |
1400 |
|
|
1401 |
# |
# |
1402 |
# Make sure that each file we include is an audio file. |
# Debug - TODO remove. |
1403 |
# |
# |
1404 |
my @results; |
print "*************\n$final**************\n"; |
1405 |
foreach my $entry (@files ) |
return( $final ); |
|
{ |
|
|
next if ( ! isAudio( $entry ) ); |
|
|
push @results, $entry; |
|
|
} |
|
|
|
|
|
return( join( "\n", @results ) ); |
|
1406 |
} |
} |
1407 |
|
|
1408 |
|
|
1454 |
$playlist = playlistForDirectory( $ROOT, $recurse, $random ); |
$playlist = playlistForDirectory( $ROOT, $recurse, $random ); |
1455 |
} |
} |
1456 |
|
|
1457 |
|
return( $playlist ); |
|
# |
|
|
# Get ready to add on any bitrate settings to the file |
|
|
# within the playlist. |
|
|
# |
|
|
if ( defined( $ARGUMENTS{"quality"} ) and |
|
|
length( $ARGUMENTS{"quality"} ) ) |
|
|
{ |
|
|
$bitrate = "?quality=" . $ARGUMENTS{"quality"}; |
|
|
} |
|
|
|
|
|
my $final = ""; |
|
|
if ( $advanced_playlist ) |
|
|
{ |
|
|
$final = "#EXTM3U\n"; |
|
|
} |
|
|
|
|
|
# |
|
|
# Get the extra details from teh files there. |
|
|
# |
|
|
$tagCache->setFormatString( "#EXTINF:\$LENGTH,$song_format" ); |
|
|
|
|
|
my @list = split( /\n/, $playlist ); |
|
|
foreach my $entry (@list) |
|
|
{ |
|
|
my $tags = ""; |
|
|
|
|
|
# Only read the tags if we want them. |
|
|
if ( $advanced_playlist ) |
|
|
{ |
|
|
$tags = getSongDisplay( $entry ) . "\n"; |
|
|
} |
|
|
|
|
|
if ($entry =~ /$ROOT(.*)/) |
|
|
{ |
|
|
$entry = $1; |
|
|
} |
|
|
|
|
|
if ( ! $recurse ) |
|
|
{ |
|
|
$entry = $dir . "/" . $entry; |
|
|
} |
|
|
|
|
|
if ( $entry =~ /(.*)\/\/(.*)/ ) |
|
|
{ |
|
|
$entry = $1 . "/" . $2; |
|
|
} |
|
|
|
|
|
$entry = "http://" . $host . urlEncode( $entry ) . $bitrate; |
|
|
|
|
|
$final .= $tags; |
|
|
$final .= $entry . "\n"; |
|
|
} |
|
|
return( $final ); |
|
1458 |
} |
} |
1459 |
|
|
1460 |
|
|