my perl script for ripping mp3s...aka MP3scRIPt

From: John Smith (jsmith_at_macroshaft.com)
Date: 01/09/05


Date: Sat, 08 Jan 2005 22:00:08 -0500

mp3scRIPt-.1
This is a Perl script to convert audio cd tracks to mp3s. It uses the CDDB at
freedb.org for title/path creation. It should require minimal prep work
as described below. I have only tested it on my FreeBSD5.3 box and have
no plans to test it elsewhere.

Requirements:
1. Perl (I have 5.8.5)
2. CDDB_get perl module found at http://armin.emx.at/cddb/
 - i had to insert a line just above line 407 of the
   file /usr/local/lib/perl5/site_perl/5.8.5/CDDB_get.pm -> $input=1;
 - "this module requires *BSD, Linux, or SunOS"
3. Internet connectivity
4. Possibly root privs to access the cdrom device
5. Assumes 'lame' and 'cdda2wav' exist and can be found in your path
6. Default encoding is 192 bit (it is hard coded but feel free to change it - line 82)
7. This script is for ATAPI/IDE cdroms -ie not SCSI

If you fat finger the user input portions, it's best to ctrl-c and start
over. (see #2 below)

TODO:
1. Be able to handle 'special characters' in song titles (eg "/")
   - this is mainly a problem on 'variety cds', mp3 files suffering from this ill
     effect will be named 'audioxy.mp3' where xy is a track number, once
created you can manually rename it 2. Advanced control structuring 3.
Output may be weird with long pathnames (script is still functional
though) - needs fixed

This was written on FreeBSD 5.3/i386 using vi...this is my first Perl script ever and
 was written because the Handbook instructions are too arduous (ie I'm
 lazy) and xmcd bugs me (however it is based directly on the Handbook).
 "Hello World" was technically my first perl script, so please, be gentle
 in your criticisms. This script is provided on an as is basis, no support
 is assumed or expected from myself. It's a bit crude and even a little
 rude...please leave me some feedback here should you decide to give it a
 whirl.
ps - I realize there are probably scores of scripts that already do this
and probably better(not to mention programs) I just felt like doing it
myself

===============================
#!/usr/bin/perl -w
#Thank you for trying MP3scRIPt-.1

print "\nWelcome to Steve's MP3 scRIPt\n\n";
print "What is your cdrom device (<enter> for default /dev/acd0): \n";
$cdrom = <STDIN>;
if ($cdrom eq "\n")
   {
      $cdrom = '/dev/acd0';
   }
else
   {
      chomp($cdrom);
   }

use CDDB_get qw( get_cddb );
my %config;
$config{CD_DEVICE}="$cdrom";
my %cd=get_cddb(\%config);
unless(defined $cd{title})
   {
      die "no cddb entry found";
   }
print "Artist: $cd{artist}\n";
print "Title: $cd{title}\n";
print "Category: $cd{cat}\n";
print "CDDD-ID: $cd{id}\n";
print "Tracks: $cd{tno}\n\n";
my $n=1;
foreach my $i ( @{$cd{track}} )
   {
      print "Track $n: $i\n";
      $n++;
   }

print "\nWhat is your base mp3 directory? \n";
chomp($path = <STDIN>);
print "\nShall I create $path\/$cd{artist}\/$cd{title} for you, y or n?\n";
chomp($create_dir = <STDIN>);
if ($create_dir eq 'y')
   {
      $path = "$path\/$cd{artist}\/$cd{title}";
      print "\nThe full pathname will be $path\n";
      system "mkdir -p \"$path\"";
   }

print "\nWhich tracks would you like ripped, entering each track on a seperate line (or '0' for all) and then end with ctrl-D: \n";
chomp(@tracks = <STDIN>);
$i = 0;
$tno = 1;
if ($tracks[0]==0)
   {
      while ($i < $cd{tno})
         {
            $tracks[$i] = $tno;
            $i += 1;
            $tno += 1;
         }
   }

print "\n\nEject when finished (requires eject command), y or n?\n";
chomp($eject = <STDIN>);
print "\n\nYou have chosen the following options: \n";
print "1. Your cdrom device is $cdrom\n";
print "2. Your output path will be $path\n";
print "3. You have chosen to rip tracks @tracks\n";
print "\nIf you have chosen wisely, please enter 1, otherwise enter 0: \n";
chomp($i = <STDIN>);

if ($i == 1)
   {
      print "\nStarting the MP3 scRIPt...\n\n";
      chdir "$path" or die "Cannot chdir to $path, please create $path and try again: $!";
      print "\nChanged directory to $path...\n\n";
      foreach $tracks (@tracks)
         {
            my $title = @{$cd{track}}[$tracks-1];
            print "\n\n$title is now being ripped...\n\n";
            system "cdda2wav -D $cdrom -t $tracks";
            rename "audio.inf", "audio$tracks.inf";
            rename "audio.wav", "audio$tracks.wav";
            system "lame -h -b 192 --tt \"$title\" --ta \"$cd{artist}\" --tl \"$cd{title}\" audio$tracks.wav \"$title\".mp3";
         }
      unlink glob "*.inf";
      unlink glob "*.wav";
   }

else
   {
      print "Can't you type, you imbecile?!\n";
   }

if ($eject eq 'y')
{
   system "eject $cdrom";
}
print "\nThank you for using MP3 scRIPt\n\n";



Relevant Pages

  • [NEWS] IBM Informix Web DataBlade Local Root by Design
    ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... that ease development of "intelligent", interactive, Web-enabled database ... person who has access to change the Perl script. ...
    (Securiteam)
  • Re: Perl script to mimic uniq
    ... mdfoster44@netscape.net spits TOFU in my face: ... > # Perl script to find most common CS ... > So I'm back to my original script which looks like this. ... > identify a sequence as unique. ...
    (comp.lang.perl)
  • Re: Slow Performance When Using DBI, otherwise Not
    ... If I run the same perl script on the database server itself it runs ... check versions of DBI and DBD (I greped for version on every module under ...
    (perl.dbi.users)
  • Re: Recovering from compromised system
    ... > perl script I have ever seen, and I would hate even more to learn a new ... > language to understand one script. ... That command is normal for a lot of substring functions. ... Hey, put a few lines in list_2_ck, run the perl script, cat j.ksh. ...
    (comp.os.linux.security)
  • Re: Linux - Programm als root absichern
    ... > ich habe ein Programm welches die konfiguration eines ... Diesses Programm hat einen schlecht abgesicherten ... > als LoginShell für einen user mit UID 0 das PERL Script hat. ...
    (de.comp.security.misc)

Quantcast