#!/usr/bin/perl # # mus123, media player wrapper use strict; use warnings; use File::Basename; # player vars my $mp3 = "mpg321"; my $ogg = "ogg123"; my $wav = "play"; my $skipNext = 0; my $doRand = 0; my $where = 0; # current index into @ARGV my $quiet = 0; my $repeat = 0; my $sleep = 1; my @filelist; foreach (@ARGV) { if ($skipNext) { $skipNext = 0; $where++; next; } if (/\.[Oo][Gg][Gg]$/) { push (@filelist, $_); } elsif (/\.[Mm][Pp][23]$/) { push (@filelist, $_); } elsif (/\.[Ww][Aa][Vv]$/) { push (@filelist, $_); } elsif (/^-@/) { my (undef, $track) = split (/^-@/); if (!$track) { $track = 1; } my $path_to_list = &dirname($ARGV[$where+1]); open (LISTFILE, $ARGV[$where+1]) or die "Cannot open listfile: $ARGV[$where+1]"; while () { if (/^#/) { next; } if ($track != 1) { $track--; next; } chomp; if (/^\//) { push (@filelist, $_); } else { my $curName = $path_to_list . "/" . $_; push (@filelist, $curName); } } close LISTFILE; $skipNext = 1; } elsif (/^-/) { if (/z/) { # get random play going $doRand = 1; } if (/q/) { # give much less output $quiet = 1; $mp3 .= " -q"; $ogg .= " -q"; } if (/r/) { # repeat $repeat = 1; } if (/g/) { # gapless-er (reduces gap) $sleep = 0; } } else { # ignoring it.. } $where++; } foreach (@filelist) { s/\$/\\\$/g; s/\"/\\\"/g; s/\`/\\\`/g; } do { if ($doRand) { srand; my @randList = (); for (@filelist) { my $r = rand @randList+1; push(@randList,$randList[$r]); $randList[$r] = $_; } @filelist = @randList; } foreach (@filelist) { sleep $sleep; if (/\.[Oo][Gg][Gg]$/) { if ($quiet) { print ("Playing: $_\n"); } system ("$ogg \"$_\""); } elsif (/\.[Mm][Pp][23]$/) { if ($quiet) { print ("Playing: $_\n"); } system ("$mp3 \"$_\""); } elsif (/\.[Ww][Aa][Vv]$/) { if ($quiet) { print ("Playing: $_\n"); } system ("$wav \"$_\""); } else { # shouldn't have gotten here, we're ignoring it print STDERR "WARNING: unrecognized file in playlist"; } } } while ($repeat);