Site Index:

Journal
Wedding
Old Stuff
Pictures
Programming
Ramblings
Links

  1: #!/usr/bin/perl
  2: #
  3: # mus123, media player wrapper
  4: #

  6: use File::Basename;

  8: my $skipNext = 0;
  9: my $doRand = 0;
 10: my $where = 0; # current index into @ARGV
 11: my $quiet = 0;
 12: my @fileList;

 14: foreach (@ARGV) {
 15:         if ($skipNext) { $skipNext = 0; $where++; next;}

 17:         if (/\.[Oo][Gg][Gg]$/) {
 18:                 push ( @fileList, $_ );
 19:         }
 20:         elsif (/\.[Mm][Pp][23]$/) {
 21:                 push ( @fileList, $_ );
 22:         }
 23:         elsif (/\.[Ww][Aa][Vv]$/) {
 24:                 push ( @fileList, $_ );
 25:         }
 26:         elsif ($_ eq "-@") {
 27:                 $path_to_list = dirname($ARGV[$where+1]);
 28:                 open (LISTFILE, $ARGV[$where+1]) or die "Cannot open listfile: $ARGV[$where+1]";
 29:                 while (<LISTFILE>)
 30:                 {
 31:                         chomp;
 32:                         if ( /^#/ ) { # skip
 33:                         }
 34:                         elsif ( /^\// ) {
 35:                                 push ( @fileList, $_ );
 36:                         }
 37:                         else {
 38:                                 my $curName = $path_to_list . "/" . $_;
 39:                                 push ( @fileList, $curName );
 40:                         }
 41:                 }
 42:                 close LISTFILE;
 43:                 $skipNext = 1;
 44:         }
 45:         elsif ($_ eq "-z") { # get random play going
 46:                 $doRand = 1;
 47:         }
 48:         elsif ($_ eq "-q") { # give much less output
 49:                 $quiet = 1;
 50:         }
 51:         else {
 52:                 # ignoring it..
 53:         }
 54:         $where++;
 55: }

 57: for (my $i = 0; $fileList[$i]; $i++ ) {
 58:         $fileList[$i] =~ s/\$/\\\$/g;
 59:         $fileList[$i] =~ s/\"/\\\"/g;
 60:         $fileList[$i] =~ s/\`/\\\`/g;
 61: }

 63: if ($doRand) {
 64:         srand;
 65:         @randList = ();
 66:         for (@fileList)
 67:         {
 68:                 my $r = rand @randList+1;
 69:                 push(@randList,$randList[$r]);
 70:                 $randList[$r] = $_;
 71:         }

 73:         @fileList = @randList;
 74: }

 76: foreach (@fileList)
 77: {
 78:         if (/\.[Oo][Gg][Gg]$/) {
 79:                 # it's an ogg, play it
 80:                 if ($quiet) {
 81:                         print ( "Playing: $_\n" );
 82:                         system ( "ogg123 -q \"$_\"" );
 83:                 }
 84:                 else {
 85:                         system ( "ogg123 \"$_\"" );
 86:                 }
 87:                 sleep 1;
 88:         }
 89:         elsif (/\.[Mm][Pp][23]$/) {
 90:                 # it's mpeg audio, play it
 91:                 if ($quiet) {
 92:                         print ( "Playing: $_\n" );
 93:                         system ( "mpg123 -q \"$_\"" );
 94:                 }
 95:                 else {
 96:                         system ( "mpg123 \"$_\"" );
 97:                 }
 98:                 sleep 1;
 99:         }
100:         elsif (/\.[Ww][Aa][Vv]$/) {
101:                 # wav audio
102:                 if ($quiet) {
103:                         print ( "Playing: $_\n" );
104:                         system ( "play --silent \"$_\"" );
105:                 }
106:                 else {
107:                         system ( "play \"$_\"" );
108:                 }
109:                 sleep 1;
110:         }
111:         else { # shouldn't have gotten here, we're ignoring it
112:         }
113: }