View Single Post
Old 12-04-2006, 10:22 AM   #87
johnny
Moderator
 
johnny's Avatar
 

Join Date: Oct 2004
Location: Upper Canada
Posts: 1,276
johnny is on a distinguished road
here's something you might find interesting.. a few months ago i wrote a simple little perl script to rip cds and encode them as *.ogg files. (i'm never happy with the other programs out there...)
you need to have the cdparanoia and oggenc commands available to you in order for this to work correctly [sudo apt-get install cdparanoia vorbis-tools]. what it does is gets information about the album from a text file i've created. here's an example:
Code:
album=Green Cosmos
artist=Deerhoof
Come See the Duck
Green Cosmos
Malalauma
Spiral Golden Town
Hot Mint Air Balloon
Koneko Kitten
Byun
so the script reads that, prompts you whether or not you want to go ahead with ripping the cd, then uses cdparanoia to make *.wav files, and then uses oggenc to encode *.ogg files.

the script:
Code:
#!/usr/bin/perl

my $album, $artist, $numtracks;
my @songs;

open ALBUMDATA, "<album.data"
  or die "album.data file is missing!?";

# read the album name, artist name, and track
# names from the album.data text file
$album = (split /=/, <ALBUMDATA>)[1];
chomp $album;
$artist = (split /=/, <ALBUMDATA>)[1];
chomp $artist;
while (<ALBUMDATA>) {
	chomp $_;
	push @songs, $_;
}
$numtracks = scalar @songs;
close ALBUMDATA;

# give the option to cancel ripping if
# the album.data information isn't good
print "\nalbum to rip: $album by $artist\n";
print "$numtracks songs\n";
for (my $i = 0; $i < $numtracks; ++$i) {
	print $i + 1 . ". " . $songs[$i] . "\n";
}
print "\nrip it? (y/n) ";
$line = <STDIN>;
chomp $line;

# if they say 'y', do it; if they say ANYTHING
# else, then don't do nothin'
if ($line eq "y") {
	# rip the *.wav files
	print "ripping tracks with cdparanoia...\n\n";
	# system "cdparanoia -d /dev/hdc -B";
	system "cdparanoia -B";

	# encode the *.ogg[/*.mp3] files
	print "encoding ogg files...";
	for (my $i = 1; $i < ($numtracks + 1); $i++) {
		$tnum = ($i < 10) ? "0$i" : "$i";
		$title = $songs[$i - 1];
		$cmd = "oggenc -N $i " .
		  " -t \"$title\" " .
		  " -l \"$album\" " .
		  " -a \"$artist\" " .
		  "--output=\"$tnum - $title.ogg\" -q 5 track$tnum.cdda.wav";
		print "\n\nripping track $tnum...\n";
		#print $cmd
		system $cmd;
	}
	
	# all done; tidy up and delete the *.wav files
	# and end the program
	print "done encoding .ogg files!\n\n";
	print "erasing .wav files\n\n";
	unlink glob "*.wav";
	print "ripping/encoding completed\n\n";
}
on some machines, the cdparanoia command would need a bit of extra information, if you have more than one cd drive (and example is commented out just above the command that it actually runs). if you can run "cdparanoia -vsQ" and cdparanoia finds the drive with the cd in it and displays a track listing to you, then "cdparanoia -B" ought to work for ripping the *.wav files. but sometimes you might need to do "cdparanoia -d [device] -B" in order for ripping to work from the correct device.. (i'm sure i'm not explaining this very well :/)

and if you wanted to make mp3s, you can just swap out oggenc for lame.. i should also mention that the oggenc command generates the ogg tag information for each file. it would be kinda silly to skip over that..

once you've put the right information in the data file (album.data) all you need to do is perl ripper.pl and it will go to work.


some things i should add:
- regular expression to remove characters that aren't allowed in file names, so it doesn't try to create a file with a bad name and die.
- make it use the Audio::CD perl module to do a cddb lookup so i don't have to type out the track names every time i rip a cd (but i'm too lazy to install this module and learn how to use it..)


who knows, somebody here just might find this useful.

note!!: i tacked on a .txt extension to each file so i could upload them, so if yer gonna download them just remove it. (or copy the text in the code boxes into brand new files called album.data and ripper.pl..)
Attached Files
File Type: txt album.data.txt (134 Bytes, 0 views)
File Type: txt ripper.pl.txt (1.5 KB, 0 views)
johnny is offline   Reply With Quote