perl123

A command-line frontend to mpg123/mpg321 that supports playlist files

I have a 486 laptop (among my other computers). I've found that I can play mp3s on it, including shoutcast streams, using an old version of mpg123. However, mpg123 doesn't support playlist files, and doesn't exactly have the smartest approach for playing directories full of mp3s that one could wish for.

Hence, perl123. This script has as its only requirements a copy of mpg123/mpg321 and the AppConfig perl module. In Debian terms, that's libappconfig-perl plus some package that provides mpg123.

Here's the script.

#!/usr/bin/perl

use AppConfig;

my $config = AppConfig->new('command' => { ARGCOUNT => 1 },
                            'options' => { ARGCOUNT => 1 });
$config->file($ENV{"HOME"} . '/.perl123');

# first, check to see if we have an argument, to prevent reading from STDIN
if (@ARGV) {
    while (<>) {
  # Look for lines beginning with File, then a digit
  if (/File\d*=/) {
      if (m#http://#) {
                s#(File\d*=)(\S*://[^ \r\t\n\f/]*)(.*\n)#\2#;
          # Check for trailing slash after the hostname, add it if not present
          unless (m#//.*/#) {
                    s#(.*)#\1/#;
                }
            }
      else {
          # we have a regular filename, process it
                s/(File\d*=)//;
                s/[\r\t\n]//;
            }
      push (@tracklist, '"' . $_ . '"');
        }
    }
}

# If our tracklist is empty, then search for all mp3s in the current directory
unless (@tracklist) {
    foreach (<./*.mp3>) {
  push (@tracklist, '"' . $_ . '"');
    }
}

# If we were able to build a tracklist, then play it!
if (@tracklist) {
    exec ($config->command . " " . $config->options . " -q " . (join ' ', @tracklist));
}

It takes one or more command-line arguments. Each argument should be a playlist file that you want played. If there are no playlists on the command-line, or if there's some kind of problem reading them and it gets no URLs or filenames, it scans the current directory for mp3s and builds a tracklist consisting of all mp3s in the current directory.

This is alpha software. It works for me, but to say that it hasn't been tested stringently would be understating greatly. ;)

It's licensed under the GNU General Public License.

It reads a configuration file from your home directory called .perl123. Here's mine.

# perl123 configuration file
# this is the command used to launch mpg123
command = mpg123
# these are the command options given to mpg123 (other than -q)
options = -m

The -m option forces mono decoding. My 486 is too slow to decode in stereo. If your machine is faster, you can drop it.

You can email me with questions about this script, or bug-fixes (yay!) if you like. Keep in mind that I get an avalanche of spam each day; do not change the subject heading for fear of sudden deletion, and expect slow responses. ;) My GnuPG public key is available.

Valid XHTML 1.0! Valid CSS!