Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create backups of audio and other CDs via the Terminal UNIX
I hate to backup my audio CDs using iTunes, because it keeps a copy in its library. So I wrote a shell script to backup the CDs. The script uses cdrdao (CD read Disk At Once, which can be installed using fink) to read the CD raw and burn them. When a CD is read, cdrdao creates a toc (table of contents file) which holds the description of the CD type, and information about which file holds the raw data. As a bonus, this script will also backup VCDs and DataCDs!

[robg adds: I haven't tested the following script...]

When you insert a CD, the Finder will take over and launch an appropriate application. To read the data using cdrdao, the device should be "unmount"ed. I use disktool to detect the mounted device and to unmount it automatically.

-------- copycd --------
#!/bin/bash
#Jan 29, 2004 06:46 PM Shankar Chakkere
#This script will make a diskimage of the AudioCD, VCD and DataCD.

#Enable the following line if you have Superdrive
#You might have to add IODVDServices/1 
#or IODVDServices/2 if you have multiple drives
DEVICE=IODVDServices

#Enable the following line if you have regular/combo drive
#You might have to add IOCompactDiscServices/1 
#or IOCompactDiscServices/2 if you have multiple drives
#DEVICE=IOCompactDiscServices

DRIVER=generic-mmc

case $# in
  0)
    echo 'Usage: copycd filename' >&2 ; exit 1;;
  *)
  #extract the bsd disk number/name and volumename from the disktool listing
  disk=`disktool -l |grep Volumes |cut -d"," -f1|cut -d"(" -f2 |tr -d "'"` 
  volume=`disktool -l |grep Volumes |cut -d"," -f4|cut -d"(" -f2 |cut -d"'" -f2`
  echo "Unmounting disk:"$disk " volume:"$volume""
  disktool -u $disk
  echo "Creating disk image"
  sudo cdrdao read-cd --device $DEVICE --driver $DRIVER --read-raw $1.toc $1.bin
  echo "Created the disk image "$1.bin" and table of contents file "$1.toc"";;
esac  
-------- END copycd --------

--------  burncd ----------
#!/bin/bash 
#Jun 11, 2003 10:38 AM Shankar Chakkere 
#burn the AudioCD,VCD and DataCD

#Enable the following line if you have Superdrive
#You might have to add IODVDServices/1
#or IODVDServices/2 if you have multiple drives
DEVICE=IODVDServices

#Enable the following line if you have regular/combo drive
#You might have to add IOCompactDiscServices/1 
#or IOCompactDiscServices/2 if you have multiple drives
#DEVICE=IOCompactDiscServices

DRIVER=generic-mmc

case $# in
  0)
    echo 'Usage: burncd toc_file' >&2 ; exit 1;;
  *) 
  sudo cdrdao write --device $DEVICE --driver $DRIVER  $1;;
esac
-------- END burncd --------
A sample session:
[shankara@mymac ~/tmp/audio] % copycd besthits
Unmounting disk:"disk1 " volume:"Audio CD"
disk1 device will be unmounted ...
***Notifications Complete for type 1
***Responding yes to unmount - disk1
***Disk Unmounted('disk1')
Creating disk image
Password:
Cdrdao version 1.1.7 - (C) Andreas Mueller 
  SCSI interface library - (C) Joerg Schilling
  Paranoia DAE library - (C) Monty 
-----------
Reading toc and track data... 
-----------
Reading of toc and track data finished successfully.
Created the disk image "besthits.bin" and table of contents file "besthits.toc"
Now to burn the image ... when you insert a blank CD, the Finder will provide you with three options -- select "Ignore."
[shankara@mymac ~/tmp/audio] % burncd besthits.toc 
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[15,585 views]  

Create backups of audio and other CDs via the Terminal | 9 comments | Create New Account
Click here to return to the 'Create backups of audio and other CDs via the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
careful w/ what you're unmounting
Authored by: jtratcliff on Feb 11, '04 05:51:07PM

This looks like it'll unmount the 1st thing it finds in the /Volumes directory...

Is this guaranteed to be the CD/DVD? If you don't have a CD inserted when
you run this, it'll unmount the 1st external drive it finds...

You might want to key off the fsType = 'cddafs' field of the disktool output
instead of (or in addition to) "Volumes" in the mount point... This will make
sure you only get the 1st audio CD mounted...



[ Reply to This | # ]
some problems
Authored by: huzzam on Feb 11, '04 10:35:52PM

I have a problem running the copycd script. I have an ibook/500 with combo drive, so I enabled the "IOCompactDiscServices" line & disabled the DVD one. It succeeded in unmounting the disk, but failed to rip the cd. If I change it back, it will rip ok.

Also: DID you install cdrdao using fink, or are you just mentioning fink for our convenience? The version I have (installed via fink) seems to want a slightly different syntax, as it complains "Expecting only one toc-file" if I specify both the toc & bin files on the command line. If I specify just the toc, it runs, and dumps all the binary data into "data.bin", which I'll just rename appropriately after ripping.

I'm about to try burning... I'll let you know if that fails.



[ Reply to This | # ]
re: some problems
Authored by: huzzam on Feb 11, '04 10:40:55PM

Actually at the last minute I decided that I shouldn't rename "data.bin" before burning, and it looks like I was right. Seems the toc file knows the name of the data file....

So to get the script working for me, I had to keep the IODVDServices line, and remove "$1.bin" from the command towards the end of the script, leaving:

sudo cdrdao read-cd --device $DEVICE --driver $DRIVER --read-raw $1.toc

peter



[ Reply to This | # ]
a sed script for reformatting .toc files
Authored by: ChrisR on Apr 04, '04 04:05:08AM

I use cdrdao to rip the table of contents from CDs so that I can store it with my archived FLAC files. Problem is, the file that cdrdao creates contains more information than I care about - all I really want is the pregap information. sed to the rescue! The following script will only output the bare minimum information needed to burn a CD with pregaps identical to the source CD:


s/^CD_DA$/CD_DA\
/p;/^TRACK AUDIO$/p;/^FILE/{h;N;s/\(.*\)\n\(.*\)/\2\
\1/;s/^\n\(.*\)/\1/;s/^START/PREGAP/;s/FILE "\(.*\)".*/FILE "\1" 0\
/p;g;}

Save this script into a file named "striptoc" (or whatever you like) and use the following command to apply the changes to "old.toc" and save them to "new.toc":


sed -n -f striptoc old.toc > new.toc

Alternately, you could put it into a unix shell script for ease-of-use:


#!/bin/sh
if [ "$1" ]
then
  disktool -u disk1
  cdrdao read-toc --device IODVDServices --driver generic-mmc "$1"
  if [ -e "$1" ]
  then
    sed -n 's/^CD_DA$/CD_DA\
/p;/^TRACK AUDIO$/p;/^FILE/{h;N;s/\(.*\)\n\(.*\)/\2\
\1/;s/^\n\(.*\)/\1/;s/^START/PREGAP/;s/FILE "\(.*\)".*/FILE "\1" 0\
/p;g;}' "$1" | sed '$d' > "$1".new
    mv "$1".new "$1"
  else
    echo "No such file: "$1""
    exit 1
  fi
else
  echo "Usage: "$(basename "$0")" <tocfile>"
  exit 1
fi

Now simply type 'striptoc cd.toc' and it will read the table of contents from your inserted CD and save it to "cd.toc". You will still need to edit the file by hand to add the filenames for the .wav files that you want to burn onto the CD.

[ Reply to This | # ]

useless use of hold space
Authored by: ChrisR on Apr 09, '04 09:55:14AM

The use of the hold space in the above code is completely unnecessary. Here's how the script should look:


#n
s/^CD_DA$/CD_DA\
/p
/^TRACK AUDIO$/p
/^FILE/{
N
s/\(.*\)\n\(.*\)/\2\
\1/
s/^\n\(.*\)/\1/
s/^START/PREGAP/
s/FILE "\(.*\)".*/FILE "\1" 0\
/p
}

Run the script with 'sed -f SEDSCRIPT > TOCFILE'

[ Reply to This | # ]

final update
Authored by: ChrisR on Apr 12, '04 09:32:05PM

Okay, here's my final update to the striptoc script. I ported it over to awk so that I could bring in a listing of flac files from the current directory.


#!/usr/bin/awk -f
BEGIN { print "CD_DA\n" }
{ FS = "\n"; RS = ""
  if ($2 == "TRACK AUDIO") {
    print $2
    if ($NF ~ /^START/) { 
      sub(/^START/, "PREGAP", $NF)
      print $NF
    }
    FS = " "; RS = "\n"
    "ls *.flac" | getline file
    sub(/flac$/, "wav", file)
    print "FILE \"" file "\" 0\n"
  }
}


[ Reply to This | # ]
Create backups of audio and other CDs via the Terminal
Authored by: dmitri on Nov 27, '04 11:45:45AM
i was having trouble with ripping some cds because of an error in Msf.cc. you have to remove some checks on track length in the file. you can download a binary version (1.1.9) without the checks from here

[ Reply to This | # ]
Create backups of audio and other CDs via the Terminal
Authored by: jeffbyrnes on Jul 10, '06 09:30:12PM
A correction, if anybody finds this script like I did, and tries to use it. The original code for the copycd script no longer works like this for cdrdao:

sudo cdrdao read-cd --device $DEVICE --driver $DRIVER --read-raw $1.toc $1.bin

It needs to read

sudo cdrdao read-cd --device $DEVICE --driver $DRIVER --read-raw --datefile $1.bin $1.toc

---
-Jeff

[ Reply to This | # ]

Create backups of audio and other CDs via the Terminal
Authored by: jeffbyrnes on Jul 10, '06 09:42:54PM
Err, sorry, misspelling in that last post. Here it is with the spelling corrected:

A correction, if anybody finds this script like I did, and tries to use it. The original code for the copycd script no longer works like this for cdrdao:

sudo cdrdao read-cd --device $DEVICE --driver $DRIVER --read-raw $1.toc $1.bin

It needs to read

sudo cdrdao read-cd --device $DEVICE --driver $DRIVER --read-raw --datafile $1.bin $1.toc

---
-Jeff

[ Reply to This | # ]