#!/usr/bin/perl -w my $RCS_Id = '$Id: playlist.pl,v 1.2 2004/03/29 11:37:32 jv Exp $ '; # Author : Johan Vromans # Created On : Sat Mar 27 12:54:43 2004 # Last Modified By: Johan Vromans # Last Modified On: Mon Mar 29 13:37:30 2004 # Update Count : 28 # Status : Unknown, Use with caution! ################ Common stuff ################ use strict; # Package or program libraries, if appropriate. # $LIBDIR = $ENV{'LIBDIR'} || '/usr/local/lib/sample'; # use lib qw($LIBDIR); # require 'common.pl'; # Package name. my $my_package = 'Sciurix'; # Program name and version. my ($my_name, $my_version) = $RCS_Id =~ /: (.+).pl,v ([\d.]+)/; # Tack '*' if it is not checked in into RCS. $my_version .= '*' if length('$Locker: $ ') > 12; ################ Command line parameters ################ use Getopt::Long 2.13; # Command line options. my $verbose = 0; # verbose processing my $strip; # Development options (not shown with -help). my $debug = 0; # debugging my $trace = 0; # trace (show process) my $test = 0; # test mode. # Process command line options. app_options(); # Post-processing. $trace |= ($debug || $test); ################ Presets ################ $strip = quotemeta($strip) if $strip; ################ The Process ################ my @filelist; my $dcount = 0; my $fcount = 0; my @dirs = @ARGV ? @ARGV : ; foreach ( @dirs ) { chomp; s/\\/\//g; s/\/+$//; unless ( -d $_) { if ( -f && /\.mp3$/i ) { my $file = $_; $file = $1 if $strip && $file =~ /^$strip(.*)/i; push(@filelist, $file); $fcount++; next; } warn("Skipping: $_ [$!]\n"); next; } unless ( opendir(DH, $_) ) { warn("Skipping: $_ [$!]\n"); next; } $dcount++; my @files; while ( my $file = readdir(DH) ) { next unless $file =~ /\.mp3$/i; $file = $_ . "/" . $file; $file = $1 if $strip && $file =~ /^$strip(.*)/i; push(@files, $file); $fcount++; } closedir(DH); warn("$_: ", scalar(@files), " file", @files == 1 ? "" : "s", "\n") if $verbose > 1; push(@filelist, @files); } while ( @filelist ) { print STDOUT (splice(@filelist, rand(@filelist), 1), "\n"); } warn("Playlist contains $fcount entr", $fcount == 1 ? "y" : "ies", " from $dcount director", $fcount == 1 ? "y" : "ies", "\n") if $verbose; exit 0; ################ Subroutines ################ sub app_options { my $help = 0; # handled locally my $ident = 0; # handled locally # Process options, if any. # Make sure defaults are set before returning! return unless @ARGV > 0; # Allow -vvv and so. Getopt::Long::config(qw(bundling)); if ( !GetOptions( 'ident|i' => \$ident, 'verbose|v+' => \$verbose, 'strip|s=s' => \$strip, 'trace|t' => \$trace, 'help|?|h' => \$help, 'debug' => \$debug, ) or $help ) { app_usage(2); } app_ident() if $ident; } sub app_ident { print STDERR ("This is $my_package [$my_name $my_version]\n"); } sub app_usage { my ($exit) = @_; app_ident(); print STDERR <