LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-10-2004, 08:39 AM   #1
darkleaf
Senior Member
 
Registered: Jun 2004
Location: the Netherlands
Distribution: debian SID
Posts: 2,170

Rep: Reputation: 45
is there a way to let cdda2wav write files and dirs with cddb names?


All graphical tools seem to screw up the files (only 1 second of sound and then nothing) so I'm using cdda2wav in the command line. Though I've set it to use cddb it only creates files like audio1.wav. Is there a way to make it write the title of the song and artist onto the file (and not in the loose .inf files?)

Which frontends are there cause I tried grip (ripper configuration error) ripperx (no sound) grip with paranoia (no sound) and I can't get grip to use cdda2wav
 
Old 10-10-2004, 05:58 PM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
I use a Python script to do this with the CDDB modules. I could paste the code here if you're interested, though you'd have to modify it a little if you actually want wav files - my script creates FLAC and OGG files directly with the CDDB names (in the hierarchy: (flacdir)/artist/album/00 - track name.flac)
 
Old 10-11-2004, 02:22 AM   #3
darkleaf
Senior Member
 
Registered: Jun 2004
Location: the Netherlands
Distribution: debian SID
Posts: 2,170

Original Poster
Rep: Reputation: 45
If you could I'd very much like to at least have a look at it I know some python myself so I might be able to do it but otherwise the other format is ok too, it's because my computer sound is better than my CD player so I want to listen my CDs on the computer. And on the fly it makes my CDs less used so they don't break anymore.
 
Old 10-11-2004, 05:58 AM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
OK, I've edited this a tiny bit to remove some unnecessary fluff, and it's not the best code, but I stopped as soon as it worked, since no-one else would ever need it... so much for that idea
I've also added a few comments to make it easier to weed out the stuff you don't care about.

Code:
#!/usr/bin/python
import os, sys, traceback
import DiscID, CDDB
import time

# The LISTFILE stuff is to keep a record of which CDs have been ripped already - I didn't want any mistakes or duplicates
LISTFILE = "rippedcd.lst"
os.system( 'touch ' + LISTFILE )            # Make sure it exists

# Handle problem characters - just replaces every first string with the matching second string
def safe( name ):
        badchars = [('?', ''), ('\\', ''), ('/', ''), (':', '-'), ('"', "'")]
        for x in badchars:
                name = name.replace( x[0], x[1] )
        return name

# I'm almost positive there is a 'right' way to do this...
def direxists( name ):
        try:
                os.stat( name )
                return 1
        except:
                return 0

# Function that checks the CD serial against those in LISTFILE and aborts if necessary
def check_cd():
        try:
                dev = DiscID.open()
                id = DiscID.disc_id(dev)
                dev.close()
                idhex = id[0].__hex__()
                try:
                        f = open(LISTFILE, 'r')
                except:
                        print os.getcwd()
                for line in f:
                        if line.strip('\n') == idhex:
                                print idhex, "CD already ripped"
                                f.close()
                                return 0
                f.close()
                return id
        except:
                inf = sys.exc_info()
                traceback.print_tb( inf[2] )
                return 0

details = check_cd()
if details:
        try:
                # Get the track and album names - may need some alterations for abnormal CDDB entries
                cddb = CDDB.query( details )
                cddb = cddb[1]
                if type(cddb) == type([]):
                        cddb = cddb[0]
                names = CDDB.read( cddb['category'], cddb['disc_id'] )
                names = names[1]
                titles = [ safe(x.strip()) for x in names['DTITLE'].split(' / ', 1) ]
                if len(titles) == 1:
                        titles = ['Various'] + titles
                n = 0
                while names.has_key( 'TTITLE%d' % n ):
                        titles.append(safe(names['TTITLE%d' % n]))
                        n+=1

                # I have flac and ogg directories already created - adjust for your needs
                dir1 = 'flac/' + titles[0]
                dir2 = 'ogg/' + titles[0]
                if not direxists( dir1 ):
                        print "*%s* does not exist" % dir1
                        os.mkdir( dir1 )
                if not direxists( dir2 ):
                        print "*%s* does not exist" % dir2
                        os.mkdir( dir2 )
                dir1 += '/' + titles[1]
                dir2 += '/' + titles[1]
                if not direxists( dir1 ):
                        print "*%s* does not exist" % dir1
                        os.mkdir( dir1 )
                if not direxists( dir2 ):
                        print "*%s* does not exist" % dir2
                        os.mkdir( dir2 )
                for x in range( 1, len(titles)-1 ):
                        # Build command line...
                        cmd = "cdda2wav -Q -q -D /dev/cdrom -t %d - " % x
                        cmd += " | flac --best -c -s -"
                        # This is silly, but it saves me escaping spaces on the command line
                        finput = os.popen( cmd )
                        fname = dir1 + "/%02d - %s.flac" % (x, titles[x+1])
                        foutput = open( fname, 'w' )
                        foutput.write( finput.read() )
                        finput.close()
                        foutput.close()
                        # First command creates the FLAC file, this recompresses to OGG without using the CD again (faster)
                        cmd = "flac -d -c -s \"%s\"" % fname
                        cmd += " | oggenc -Q -b 192 - 2>/dev/null"
                        finput = os.popen( cmd )
                        fname = dir2 + "/%02d - %s.ogg" % (x, titles[x+1])
                        foutput = open( fname, 'w' )
                        foutput.write( finput.read() )
                        finput.close()
                        foutput.close()
                # Add the CD serial to LISTFILE
                f = open(LISTFILE, 'a')
                f.write(details[0].__hex__() + "\n")
                f.flush()
                f.close()
        except:
                traceback.print_exc()
 
Old 10-11-2004, 08:03 AM   #5
darkleaf
Senior Member
 
Registered: Jun 2004
Location: the Netherlands
Distribution: debian SID
Posts: 2,170

Original Poster
Rep: Reputation: 45
Awesome thank you very much! I think I might even be able to make it output wavs
 
Old 10-11-2004, 03:34 PM   #6
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
You should be able to just by removing the "| flac" portion of the command and changing the fname parameter (and removing the second part that does the ogg stuff)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
invisible files and dirs karmine Slackware - Installation 8 12-26-2004 03:05 PM
ls, dirs first, files later TroelsSmit Linux - Newbie 4 05-31-2004 11:47 AM
SAMBA: display of share names is OK but files names are wrong superandrzej Linux - Software 5 02-02-2004 09:14 AM
PERL::evaluating names of files and dirs ocularbob Programming 5 08-28-2003 06:26 PM
how to make my account on proftpd to be able to see all dirs and able to write. Mouse_103 Linux - Newbie 2 04-02-2003 07:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration