Click to See Complete Forum and Search --> : ripping to wavs script


TreeHugger
05-29-2003, 05:52 PM
Does anyone know where I can get a script to rip a CD and name the wav files according to the CD's cddb entry?

I've seen a couple on freshmeat and I've tried the GUI stuff like ripperX, but most things that do the CDDB bit also do the encoding part automatically as well, which I need to prevent so I can normalize the wavs first.

Thanks

sarah31
05-29-2003, 07:23 PM
cdparanoia or cdda2wav?

Dizzybacon
05-30-2003, 04:17 AM
As a graphical option you could try Grip. It rips and encodes by default but the options can be set to rip only and it will get track names from CDDB.

Dizzy

TreeHugger
06-02-2003, 07:55 AM
You can't use grip from the command line though, so I can't control it in a script.

I can script with cdparanoia or cdda2wav to make the wav files, but I don't know how to script a link to freedb or cddb to get the song titles.

I mean, I know I can do it manually in seperate steps, but I want to have a script do the whole thing, so I can go for a coffee until its finished, or whatever.

Dizzybacon
06-02-2003, 11:28 AM
You could try rip (http://rip.sourceforge.net).
I've tried to write a perl script to use rip to rip and name, normalize and then encode but didn't get far before being distracted.

So if your doing the same please let me know if you get anywhere.

Dizzy

TreeHugger
06-02-2003, 11:31 AM
Yo! Know what you mean. This has been on my list of things to do for 3 years.

TreeHugger
06-02-2003, 06:15 PM
Almost there. With rip I am able to create the wav files, and then I can run normalize on them, but then there's a problem writing the tag for the encoding.

I would have to get the cddb info again to pass to oggenc to make the tags. Drat!$(*£~~"!

Dizzybacon
06-03-2003, 03:44 AM
Can't you just name the wav files from rip and then use oggenc to encode them staying with the same name?

Dizzy

TreeHugger
06-03-2003, 04:22 AM
Yes, but then the ID3 tag would be empty unless I tell oggenc what the singer, album & track titles are. i.e. in the audio player the song would have no description.

Dizzybacon
06-05-2003, 04:05 AM
I've attached a file which does the job.

Now before reading this you should know that I'm not very good at scripting this sort of thing. It's all a bit messy and I'm sure that anyone who knows much about Perl will be disgusted by it.

I was also hoping to get the encoder to run seperately so it could go on and rip the next track (like Grip does) but so far I've failed in that.

You'd need to change some of it to name the files how you want them and to encode it all in ogg, but otherwise everything should work.

Dizzy

TreeHugger
06-10-2003, 04:53 PM
Been on holiday. Looks like you were busy! The script is great.

I didn't know about cddb.pl - and saving the info to file just hadn't occured to my simple brain. Good move.

I'm going to adapt it to use oggenc as my encoder, but otherwise it's perfect. Don't see what's wrong with the program structure either - but then I know nothing about perl.

As for getting the script to carry on ripping while it encodes, I know what I would do in java, but I don't know if it would work in perl.

You would have to write the three core rip, normalize, encode lines as a function, and its parameters would be the song info and the track it's on.

You would get rid of the loop and instead call the function. After the first rip, you call the function again with the next track number, starting the function in a seperate thread / process.

Something like this pseudo-code:

function runMeAgainInAnotherThread(songInfo, trackNo)
{
print `\n/usr/bin/cdparanoia ....\n`;
if (songInfo has trackNo + 1)
print `runMeAgainInAnotherThread(songInfo, trackNo + 1)
print `normalize ....`;
print `notlame ....`;
}

I'm not sure what you can do in perl.

Thanks again anyway. Excellent.

TreeHugger
06-20-2003, 04:33 AM
Hi Dizzy,
you also need a

$song[1] =~ s/\//-/g;

I just ripped a CD where the tracknames had slashes in. Totally stuffed the script until I removed them.

Dizzybacon
06-20-2003, 05:00 AM
Hi Treehugger,

I've been adding lines like that as and when I have problems with it. I'm sure there must be a simpler way but I haven't found one yet.

Dizzy

TreeHugger
07-07-2003, 04:01 AM
Come across a hitch with the script.

I ripped a CD where half the songs are full-on loud numbers and the other half are really quiet vocal and piano songs, and not only that but the songs all segue into each other without a break.

Normalize has increased the volume on the quiet songs totally noticeably, so when one loud song segues into the next quiet song, the volume jumps substantially.

I was looking at normalize and it can normalize a whole set of WAVs at the same time by the same amount, but we would have to structure the script so that all the WAVs are ripped and sitting in a directory ready to do that in one shot.

I'm going to see if I can do it. I'll post it in case you're interested.

:eek: :) :)

Dizzybacon
07-07-2003, 09:53 AM
Before you spend time writing a script check out whether normalize does do what you think it's going to.

If you have a folder full of mp3s and you run normalize *.mp3 it opens one file normalises it to a fixed level, closes it and starts on the next one.

I thought at first that it would compare the levels on all of them and then normalise at a suitable level but after fiddling about a bit I found that this is not the case.

I might be wrong but I think this is what you were hoping for.

Dizzy

Dizzybacon
07-07-2003, 09:56 AM
P.S. If you do write something please do post it as I would be interested to see how you've gone about it.

Dizzy

TreeHugger
07-07-2003, 09:58 AM
I'm thinking of the following normalize option:

-b, --batch batch mode: get average of all levels, and
use one adjustment, based on the average
level, for all files

and there's more in the info pages. I'll try it anyway. I wasn't thinking of making earth shattering changes to your original script anyway - possibly just duplicating the for-loop.

Dizzybacon
07-07-2003, 10:06 AM
I missed the batch mode in my reading obviously.

Isn't this going to do the same thing to your CD that you are trying to rip?

Dizzy

TreeHugger
07-07-2003, 04:45 PM
It works now with two loops, one to rip the cd into WAVs, then the normalize on them all, and then the loop to encode the WAVs into oggs.

Sorry I deleted your line for lame, so don't overwrite your file. I also changed the underscore treatment to use gaps.

It's a bit ugly though because the cddb file parsing is all done twice. If you tell me how to create an array in perl outside the first for loop, and then add an element to it with each iteration, I'll put that in to save the parsed names etc during the first loop to use in the second.

Dizzybacon
07-08-2003, 04:08 AM
It looks good! Does it solve the problem that you were having?

Dizzy

TreeHugger
07-08-2003, 06:26 AM
Yes, totally solves it - normalize applies the same adjustment to the whole album.

So what about the idea of arrays in perl? Can you declare dynamic arrays?

I am also thinking of adding an option to the command line for perl so that the script will just download the cddb entry and launch it in emacs so I can edit it. Does perl allow that? :eek: :eek:

and an option to specify lame or oggenc would be nice

Dizzybacon
07-08-2003, 07:04 AM
I've got no idea about dynamic arrays, I don't know that much about programming at all I'm afraid.

Perl should letr you open the file in Emacs and then return to the script. Try adding a line like this:

print `xterm -i \"emacs <FILENAME>\"`;

I think that should open up a seperate terminal with the file open in emacs. When you've finished editing the file just close the window and the ripping script will continue.

A lame/oggenc option could be done but as I never use oggenc and you probably never use lame I don't know if there is any point.

Dizzy

Dizzybacon
07-09-2003, 02:03 PM
I've looked into the editing of the CDDB output and I've added this bit of code into my script.

opendir(DIR, "/tmp/xmcd/");
@files = readdir DIR;
closedir(DIR);

print "Edit file?\n";
$edit = <STDIN>;
if ($edit =~ /y/i){
print `kate \"/tmp/xmcd/$files[2]\"`;
}

open(XMC, "/tmp/xmcd/$files[2]");
@xmcd = <XMC>;
close(XMC);

Type y or yes or in fact anything containing a y and it'll open Kate. Edit the file as you want, save it and close Kate.
(You can change Kate to any other editor you want obviously.)

I've found this addition useful already!

Dizzy

TreeHugger
07-25-2003, 12:13 PM
Hi Dizzy, everyone,

I came across this extra stuff in the cddb entry for a cd:

EXTD=All selections written by Van Morrison\n\nProduced by Van Morrison\n* Pro
EXTD=duced by Van Morrison and Ted Templeman
EXTT0=Saxophone - Jack Schroer, "Boots" Rolf Houston\nPiano - Mark Naftalin\nG
EXTT0=uitar - Doug Messenger\nBass - Bill Church\nDrums - Rich Schlosser\nRhyt
EXTT0=hm guitar - Van Morrison
EXTT1=Saxophone - Jack Schroer, Jules Broussard\nPiano - Mark Naftalin\n12 and
EXTT1= 6 string guitars - Doug Messenger\nBass - Bill Church\nDrums - Rick Sch
EXTT1=losser\nRhythm guitar - Van Morrison\nTrombone - Pat O'Hara\nBackup voca
EXTT1=ls - Janet Planet, Ellen Schroer

what should be done with this lot? All the audio players I have used don't ever show more than about 25 characters for this sort of comment when you look under "file info" or the ID3 tag or whatever.