Attached is a perl script that my friend John (who's actually on this
list, not sure why he didn't send this along himself) wrote.  Very cute
little script.  Usage and requirements are clearly laid out in the header.

E

On Tue, 13 Nov 2001, tack wrote:

> I am also intereseted in console based ripping on unix in general.
>
> tack
>
> On Tue, 13 Nov 2001, Phil Suh wrote:
>
> >
> > what do you use to rip mp3s on linux?
> >
> >
> >
>
>

-- 

Erik Curiel
Sometime Web Engineer/Almost Philosopher


"The affairs of human beings are not worthy of great seriousness,
and yet we must take them seriously."
                                        ---Plato, *The Laws*
#!/usr/local/bin/perl -w

#usage [-v] cd2mp3.pl

#-v is verbose: prints the output of the cdda2wav and lame commands

#

# Put a CD into the cd player, execute cd2mp3.pl command and let it

# go.  The program queries the internet data base CDDB and gets the

# songlist and other info.  It then converts the CD to mp3 files,

# where the outfile names are artist/title/trackno_track_name.mp3

#

# Also creates artist/title/songlist with the relevant info about the

# CD in one file for easy conversion to xmms or dbase formats

#

# You may need to configure CD_DEVICE below.  Default is /dev/cdrom.

#

# Requires lame, cdda2wav and perl module CDDB_get.

# CDDB_get: http://search.cpan.org/search?dist=CDDB_get

# lame: http://www.sulaco.org/mp3

# cdda2wav Part of cdr-tools.  Beware, this installs to /opt/schilly by 

#           default. http://www.escape.de/users/colossus/cdda2wav.html

#

# Yes I know there is another cd2mp3 out there, but it didn't support

# internet database queries for track titles so I rolled my own.

# This script is based on CDDB_get man page.

#

# John D. Hunter <[EMAIL PROTECTED]>



use strict 'vars';

use CDDB_get;

use Shell qw(cdda2wav lame mkdir touch);

use Getopt::Std;

use vars qw($opt_v);

getopts('v');



$Shell::capture_stderr = 1 unless $opt_v;

my %config;



# following variables just need to be declared if different from defaults

$config{CDDB_HOST}="freedb.freedb.org";        # set cddb host

$config{CDDB_PORT}=888;                        # set cddb port

$config{CD_DEVICE}="/dev/cdrom";



# user interaction welcome?

$config{input}=1;   # 1: ask user if more than one possibility

                    # 0: no user interaction





# get it on

print "querying $config{CDDB_HOST}\n";

my %cd=get_cddb(\%config);





unless(defined $cd{title}) {

  die "no cddb entry found";

}



$cd{artist} = fix_special_chars($cd{artist});

$cd{title} = fix_special_chars($cd{title});

my $outdir = "$cd{artist}/$cd{title}";

mkdir("-p", "$outdir");

open(SONGLIST, ">$outdir/songlist");

print SONGLIST "artist: $cd{artist}\n";

print SONGLIST "title: $cd{title}\n";

print SONGLIST "category: $cd{cat}\n";

print SONGLIST "cddbid: $cd{id}\n";

print SONGLIST "trackno: $cd{tno}\n";



print "Writing output to $outdir\n";



my $trackNumber=1;

foreach my $trackname ( @{$cd{track}} ) {



  my $track_prefix = one2Ndigits($trackNumber,2);

  my $trackfile = 

    $track_prefix . '_' .  fix_special_chars($trackname) . '.mp3';

  print SONGLIST "$track_prefix $trackfile $trackname\n";

  print "\tConverting track #$trackNumber: $trackname\n";



  #convert the track to wav 

  cdda2wav("-D$config{CD_DEVICE}", '--track', $trackNumber, '-xs', 'temp.wav');

  

  #convert the wav to mp3

  lame('-h', 'temp.wav', "$outdir/$trackfile");

  ++$trackNumber; 

}



sub fix_special_chars {

  my $fname = shift;

  $fname =~ s/ /_/g;

  $fname =~ s/\'//g;

  return $fname;

}



sub one2Ndigits {

  my $digits = $_[0];

  my $num_digits = $_[1];

  while (length $digits < $num_digits) {

    $digits = "0" . $digits;

  }

  if ($num_digits != 0) {

    return $digits;

  }

  else{

    return "";

  }

}

Reply via email to