Friday, April 6, 2012

WAV to MP3 for Sandisk Clip+

BB was able to listen to the audio CD riped from WAV to MP3 successfully.  However, the process of ripping is a bit involved

  • copy the WAV to disk & rename with author, title, disk, and track
  • convert to MP3 with lame
  • set MP3 tags with easytag
So I've improved the python script to do all these things.  Here's the current version:
# audiobookcopy.py
# copy multiple CDs in an audio book
# cd appears to automount at ls .gvfs/cdda\ mount\ on\ sr0/
#
# Output file name format that should work well with various players
# Author/Title/CD??-Track??
#
# for info on ripping see http://www.chuckegg.com/quickly-convert-audiobook-cds-to-mp3-files-audio-book-mp3/
# for info on easytag see http://easytag.sourceforge.net/EasyTAG_Documentation.html#ch_1_2_4
import sys
import os
import shutil
from subprocess import call
dir = "/home/rbell01824/.gvfs/cdda mount on sr0"
def ensure_dir(f):
    if not os.path.exists(f):
        os.makedirs(f)
def cacd( author, title, fnbase, cd ):
    print "Processing CD ", cd
    files = os.listdir( dir )
    ifn = 1
    for fn in files:
        src = dir+"/"+fn
        dstdir = author+'/'+title
        fn, fx = os.path.splitext( src )
        #print "Source:", src
        #print "Dest Dir:", dstdir
        #print "FN:", fn
        #print "FX:", fx
        if fx == '.wav' or fx == '.mp3':
            # lame -h -b 192 --tt title --ta artist --tl album --tn track --tg genre source destination.mp3
            idtitle = fnbase+'-%02d'%cd+'-%02d'%ifn
            dst = author+'/'+title+'/'+fnbase+'-%02d'%cd+'-%02d.mp3'%ifn
            #print "Dest:", dst
            cmd = 'lame -h -b 192 --tg Audiobook --tt "%s"' % idtitle
            cmd = cmd + ' --ta "%s"' % author
            cmd = cmd + ' --tl "%s"' % title
            cmd = cmd + ' --tn "%d%02d"' % (cd, ifn)
            cmd = cmd + ' "%s" "%s"' % (src, dst)
            print "lame: %s"%cmd
            return_code = call( cmd, shell=True)
        else:
            dst = author+'/'+title+'/'+fnbase+'-%02d'%cd+'-%02d'%ifn+'.%s'%fx
            print "Dest:", dst
            shutil.copy2( src, dst )
        ifn += 1
    return
def abc():
    if (len(sys.argv) < 3 ):
        print "audiobookcopy author title base_file_name start_CD"
        exit(1)
    print sys.argv[1:]
    author = sys.argv[1]
    title = sys.argv[2]
    fnbase = sys.argv[3]
    ensure_dir( author )
    ensure_dir( author+'/'+title )
    cd = int(sys.argv[4])
    print "start with disk "+str(cd)
    while cd <= 200:
        kbi = raw_input( "Mount CD "+str(cd)+" Press enter:\a" )
        cacd( author, title, fnbase, cd )
        cd += 1
if __name__ == '__main__':
    try:
        __file__
    except:
        sys.argv = [sys.argv[0], 3]
    abc()
Along the way I reorganized the directory structure to / but left the individual files as < code>.

I also found a utility app with a GUI interface, Audio CD Extractor.  It doesn't do as nice a job of naming but otherwise seems OK.

No comments: