{"id":2297,"date":"2012-05-04T12:03:14","date_gmt":"2012-05-04T12:03:14","guid":{"rendered":"http:\/\/t.motd.kr\/articles\/2297\/how-to-rip-an-audio-cd-as-a-single-flac-with-embedded-cue-sheet-in-ubuntu-linux"},"modified":"2022-12-28T01:44:36","modified_gmt":"2022-12-27T16:44:36","slug":"how-to-rip-audio-cd-as-flac-with-embedded-cue-sheet-in-ubuntu-linux","status":"publish","type":"post","link":"https:\/\/vault.motd.kr\/wordpress\/posts\/2297\/how-to-rip-audio-cd-as-flac-with-embedded-cue-sheet-in-ubuntu-linux\/","title":{"rendered":"How to Rip Audio CD as FLAC with Embedded Cue Sheet in Ubuntu Linux"},"content":{"rendered":"\n

I wrote a pretty simple shell script that rips an audio CD as a single FLAC<\/span> file with embedded cuesheet for Linux. It ensures secure rip by ripping a disc three times with cdparanoia<\/a> and comparing their checksums. It has been tested on Ubuntu 12.04 Precise, but it should work for any Linux system such as Fedora.<\/p>\n\n\n\n

Usage<\/h2>\n\n\n\n

Just run the script in your shell prompt, it will retrieve the ID of the disc and generate a <DISCID>.flac<\/code><\/p>\n\n\n\n

Required packages<\/h2>\n\n\n\n

Install the following packages first:<\/p>\n\n\n\n

apt-get install cd-discid cdrdao cuetools flac cdparanoia\n<\/code><\/pre>\n\n\n\n

Install the ripper script<\/h2>\n\n\n\n

Put the following script into your path (e.g. \/usr\/local\/bin<\/code>). You might want to change the DEVICE<\/code> variable (e.g. \/dev\/cdrom<\/code>). If you want even more secure rip, you can set the COPIES<\/code> variable to a greater value (e.g. 5<\/code>).<\/p>\n\n\n\n

#!\/bin\/bash\n# \/usr\/local\/bin\/rip-audio-cd\nDEVICE=\"\/dev\/sr0\"\nCOPIES=\"3\"\nDISCID=\"`cd-discid $DEVICE 2>&1 | egrep -o '^[0-9a-z]{8}'`\"\nif [ \"$?\" != \"0\" ]; then\n  echo \"Failed to retrieve disc ID.\"\n  exit 1\nfi\necho -e \"33[1;32mDisc ID: $DISCID33[0;0m\"\nrm -f \"$DISCID\".*\necho -e \"33[1;32mExtracting a cue sheet:33[0;0m\"\ncdrdao read-toc --device \"$DEVICE\" --datafile \"$DISCID.wav\" \"$DISCID.toc\" || exit 2\ncueconvert -i toc -o cue \"$DISCID.toc\" | grep -vP '^ISRC \"' > \"$DISCID.cue\" || exit 2\nCHECKSUM=''\nI=0\nfor ((I=0; I < $COPIES; I++)); do\n  echo\n  echo -e \"33[1;32mPass $((I+1)) of $COPIES33[0;0m:\"\n  if [[ $I -eq 0 ]]; then\n    OUT=\"$DISCID.wav\"\n  else\n    OUT=\"$DISCID.new.wav\"\n  fi\n  rm -f \"$OUT\"\n    cdparanoia -zX '1-' \"$OUT\"\n  if [ \"$?\" != \"0\" ]; then\n    rm -f \"$DISCID\".*\n    echo \"Failed to rip a disc.\"\n    exit 3\n  fi\n    C=\"`sha1sum \"$OUT\" | cut -f1 -d' '`\"\n  if [[ \"x$CHECKSUM\" = 'x' ]]; then\n    echo \"Checksum: $C\"\n    CHECKSUM=$C\n  else\n    rm -f \"$OUT\"\n    if [[ \"$CHECKSUM\" != \"$C\" ]]; then\n      echo \"Mismatching checksum: $C\"\n      exit 4\n    else\n      echo \"Matching checksum: $C\"\n    fi\n  fi\ndone\neject \"$DEVICE\" &\necho\necho -en \"33[1;32mCompressing...33[0;0m\"\nflac -f -V --replay-gain --best --cuesheet=\"$DISCID.cue\" \"$DISCID.wav\"\nif [ \"$?\" != \"0\" ]; then\n  echo \"Failed to encode the ripped tracks.\"\n  exit 5\nfi\n\nrm -f \"$DISCID.wav\" \"$DISCID.cue\" \"$DISCID.toc\"\n\necho\necho -e \"33[1;32mAll done: $DISCID.flac33[0;0m\"<\/code><\/pre>\n\n\n\n

Fill metadata<\/h2>\n\n\n\n

Unfortunately, the script does not fill the metadata such as track information and cover art. I usually rip a bunch of discs first using this script and then fill their metadata in Windows. Here\u2019s the steps I take:<\/p>\n\n\n\n

    \n
  1. Load the FLAC<\/span> file into foobar2000<\/a><\/li>\n\n\n\n
  2. Fill the track information.\n