ripit.pl

Tim Pozar pozar at lns.com
Fri May 16 06:09:32 PDT 2003


On Fri, May 16, 2003 at 04:58:42PM +0930, Wilkinson,Alex wrote:
> Can anyone recommend a cdda->mp3 ripper that can access:
> 
> freedb.freedb.org:8880
> 
> ripit.pl doesn't seem to have the smarts to do this.

I have one I wrote that is pretty ugly but it works....

Tim
--
#!/usr/local/bin/perl

# LNSRIP uses "dagrab" for rip the CDDA data and "gogo" for the
# MP3 encoding.  It can use either "mp3info" or "id3ren" to write
# the ID3 tags in the MP3 files.  It also makes the assumption that 
# you have a working net connection up as it queries the CDDB server
# to get artist, album and track titles.

$prognam = "LNSRIP 1.0";
$comment = "via " . $prognam;	# Good to put in the ID3 comment field to 
				# track problems.
$log = ">>/tmp/lnsrip.log";

$i = 0;
$tracknum = 0;
$starttrack = 0;
$endtrack = 0;
$cddb_inet = 1;

while ($_ = $ARGV[0], /^-/) {
        shift;
        last if /^--$/;
	if(/-l/)	{ $cddb_inet = 0; }
        if (/^-D(.*)/)	{ $debug = $1; }
        if (/^-s(.*)/)	{ $starttrack = $1; }
        if (/^-e(.*)/)	{ $endtrack = $1; }
        if (/^-v/)	{ $verbose++; }
}     

# Get the track list.
# dagrab will return something like... (we hope)
# --
# dagrab -d /dev/cdrom -i -C -H ca.us.cddb.com -P 8880
# dagrab: cddb inexact matches found, picking first
# 
# DISK: The Beatles / Help!
# 
# track    start   length  type  duration   MB Title
#     1      183    10580 audio  00:02:21   23 Help!
#     2    10763    11752 audio  00:02:36   26 The Night Before
# [...]
#    14   141685    13069 audio  00:02:54   29 Dizzy Miss Lizzie
#  170   154754        - leadout
# 
# CDDB DISCID: a9080c0e
# --
# CDDB will return the album titles, artist and song titles.
# CDDB sites you can use...
# CDDB Protocol Server Sites 
# Site			IP Port Location 
# us.cddb.com		8880	Random, US
# in.us.cddb.com	8880	Carmel, IN US
# ca.us.cddb.com	8880	Berkeley, CA US
#
# In our case we are using freedb.freedb.org:8880
#
# We need to grab the album and artist's name and each track name.
# Song names we stick into an array...

if($cddb_inet){
	open(TRACKLIST, "dagrab -d /dev/cdrom -i -C -H freedb.freedb.org -P 8880 |");
} else {
	open(TRACKLIST, "dagrab -d /dev/cdrom -i |");
}
while(<TRACKLIST>){
	s/^\s*(.*?)\s*$/$1/;	# strip any spaces from the front.
	tr/ //s;		# compress any spaces.

	if(m/DISK:/){		# Get the album and artist name.
		($foo1,$foo2) = split(/:/);
		($artist,$album) = split(/\//,$foo2);

		$_ = $artist;
		s/^\s*(.*?)\s*$/$1/; 
		s/\"/_/g;
		tr/\"/_/;	# Strip funny chars that will  screw us up later.
		tr/\`//;
		tr/\;//;
		tr/\!//;
		$artist = $_;		# This is the final name for the
					# ID3 tag
		s/\&/and/g; 
		tr/\'/_/;
		tr/\,/_/;
		tr/\./_/;
		tr/(/_/;
		tr/)/_/;
		tr/\/ /_/s;		# Convert spaces to underscores for...
		$artist_fn = $_;	# the file name.

		$_ = $album;
		s/^\s*(.*?)\s*$/$1/; 
		s/\"/_/g;
		tr/\"//;
		tr/\'//;
		tr/\`//;
		tr/\;//;
		tr/\!//;
		$album = $_;
		s/\&/and/g; 
		tr/\'/_/;
		tr/\,/_/;
		tr/\./_/;
		tr/(/_/;
		tr/)/_/;
		tr/\/ /_/s;
		$album_fn = $_;
	}
	if(m/audio/){		# Get the song names...
		$i++;
		($tracknum[$i],$start[$i],$stop[$i],$type[$i],$duration[$i],$mb[$i],$song[$i]) = split(/ /, $_, 7);
		$_ = $song[$i];
		s/^\s*(.*?)\s*$/$1/; 
		s/\"/_/g;
		tr/\"//;
		tr/\`//;
		tr/\'//;
		tr/\;//;
		tr/\!//;
		$song[$i] = $_;
		s/\&/and/g; 
		tr/\'/_/;
		tr/\,/_/;
		tr/\./_/;
		tr/(/_/;
		tr/)/_/;
		tr/\/ /_/s;
		$song_fn[$i] = $_;
	}
}

$totaltracks = $i;

if(($artist ne "") && ($album eq "")){
	$album = $artist;	# Just in case...
}

print "Artist = $artist\n";
print "Album = $album\n";
print "Totaltracks = $totaltracks\n";
open(LOG,$log);
print LOG "Artist = $artist\n";
print LOG "Album = $album\n";
print LOG "Totaltracks = $totaltracks\n";
close(LOG);

if(($artist eq "")&&($album eq "")){	# Couldn't get cddb data...
	print ("Couldn't get cddb data for this CD.\n");
}

if($starttrack > 0){
	$starttrack--;
	$tracknum = $starttrack;
}
if($endtrack > 0){
	$totaltracks = $endtrack;
}

while ($tracknum != $totaltracks){
	$tracknum++;
	print "Ripping track $tracknum = \"$song[$tracknum]\"...\n";
	open(LOG,"$log");
	print LOG "Ripping track $tracknum = \"$song[$tracknum]\"...\n";
	close(LOG);

	if(($artist eq "")&&($album eq "")){	# Couldn't get cddb data...
		if ($tracknum < 10){
			$filename = "0$tracknum-track";
		} else {
			$filename = "$tracknum-track";
		}
		print ("Writing track $tracknum filename \"$filename.wav\".\n");
		$result = `dagrab -d /dev/cdrom -v -f $filename.wav $tracknum $log`;
		$result = `gogo $filename.wav $log`;
		print ("Removing \"$filename.wav\".\n");
		if (unlink("$filename.wav") < 1) {
			print("Troubles removing \"$filename.wav\".\n");
			`rm $filename.wav`;	# lets try this...
		}
	} else {
		if ($tracknum < 10){
			$filename = "$artist_fn-$album_fn-0$tracknum-$song_fn[$tracknum]";
		} else {
			$filename = "$artist_fn-$album_fn-$tracknum-$song_fn[$tracknum]";
		}
		$_ = $filename;
		tr [\200-\377] [\000-\177]; 	# delete 8th bit
		tr/_//s;
		$filename = $_;

		print ("Writing track $tracknum filename \"$filename.wav\".\n");
		$result = `dagrab -d /dev/cdrom -v -f $filename.wav -C -H ca.us.cddb.com -P 8880 $tracknum $log`;
		print ("Encoding \"$filename.wav\" -> mp3.\n");
		$result = `gogo $filename.wav $log`;
		print ("Removing \"$filename.wav\".\n");
		if (unlink($filename.wav) < 1) {
			print("Troubles removing \"$filename.wav\".\n");
			`rm $filename.wav`;	# lets try this...
		}
		print ("Tagging \"$filename.mp3\" with Album = \"$album\", Artist = \"$artist\", Song = \"$song[$tracknum]\".\n");
		$result = `mp3info -t \"$song[$tracknum]\" -a \"$artist\" -l \"$album\" -c \"$comment\" $filename.mp3 $log`;
		# $result = `id3ren -song \"$song[$tracknum]\" -artist \"$artist\" -album \"$album\" -verbose -tag $filename.mp3 $log`;
	}
}


More information about the freebsd-multimedia mailing list