Difference between revisions of "Rip Audio CDs"

From ArchWiki
Jump to: navigation, search
m (Shell script)
m (Shell script)
Line 16: Line 16:
 
# This script needs mp3splt, cdrtools, vorbis-tools
 
# This script needs mp3splt, cdrtools, vorbis-tools
  
CREATE_OGG="false";
+
CREATE_OGG="false";
CREATE_FLAC="false";
+
CREATE_FLAC="false";
CREATE_MKA="true";
+
CREATE_MKA="true";
  
WORKING_DIRECTORY=`pwd`
+
WORKING_DIRECTORY=`pwd`
  
 
function usage()  
 
function usage()  
 
{  
 
{  
   echo "Usage: $0 [OUTPUT_DIRECTORY] device";
+
   echo "Usage: $0 [OUTPUT_DIRECTORY] device";
 
   echo "eg.: $0 my_audio_cd /dev/sr0";
 
   echo "eg.: $0 my_audio_cd /dev/sr0";
 
   exit;
 
   exit;
}
+
}
  
 
function no_cdtext()
 
function no_cdtext()
Line 35: Line 35:
 
   echo "$0 OUTPUT_DIRECTORY device";
 
   echo "$0 OUTPUT_DIRECTORY device";
 
   exit;
 
   exit;
}
+
}
  
 
function remove_quotes() {
 
function remove_quotes() {
 
   local OUTPUT_STRING
 
   local OUTPUT_STRING
 
   # remove quotes
 
   # remove quotes
   OUTPUT_STRING=$(echo "$1" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
+
   OUTPUT_STRING=$(echo "$1" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
 
   # remove selected special characters
 
   # remove selected special characters
   echo "$OUTPUT_STRING" | sed "s/\(.*\)[\\]\(.*\)/\1\2/g"
+
   echo "$OUTPUT_STRING" | sed "s/\(.*\)[\\]\(.*\)/\1\2/g"
}
+
}
  
  
 
# store command line parameters
 
# store command line parameters
if  [[ "$#" = "2" ]] ; then
+
if  [[ "$#" = "2" ]] ; then
   CDROM=$2;
+
   CDROM=$2;
   OUTPUT_DIRECTORY=$1;
+
   OUTPUT_DIRECTORY=$1;
elif [[ "$#" = "1" ]] ; then
+
elif [[ "$#" = "1" ]] ; then
   CDROM=$1;
+
   CDROM=$1;
 
else  
 
else  
 
   usage;
 
   usage;
Line 58: Line 58:
 
# retrieve CD information
 
# retrieve CD information
 
echo "Retrieve CD information"
 
echo "Retrieve CD information"
# CD_INFO=$(cdda2wav -J -g /dev/sr0 2>&1)
+
# CD_INFO=$(cdda2wav -J -g /dev/sr0 2>&1)
  
 
# test if CD-Text is available
 
# test if CD-Text is available
if [[ "detected" == $(echo "${CD_INFO}" | awk '/^CD-Text.*/ {print $2}') ]]; then
+
if [[ "detected" == $(echo "${CD_INFO}" | awk '/^CD-Text.*/ {print $2}') ]]; then
 
   echo "CD-Text detected"
 
   echo "CD-Text detected"
   CD_TEXT_DETECTED=true
+
   CD_TEXT_DETECTED=true
   ALBUM_INFORMATION=$(echo "${CD_INFO}" | grep ^"Album title")
+
   ALBUM_INFORMATION=$(echo "${CD_INFO}" | grep ^"Album title")
 
   # remove characters from beginning of string
 
   # remove characters from beginning of string
   ALBUM_INFORMATION=$(echo "${ALBUM_INFORMATION#*Album title: }")
+
   ALBUM_INFORMATION=$(echo "${ALBUM_INFORMATION#*Album title: }")
   ALBUM_TITLE=$(echo "${ALBUM_INFORMATION% from *}")
+
   ALBUM_TITLE=$(echo "${ALBUM_INFORMATION% from *}")
   ALBUM_TITLE=$(remove_quotes "${ALBUM_TITLE}")
+
   ALBUM_TITLE=$(remove_quotes "${ALBUM_TITLE}")
   ALBUM_ARTIST=$(echo "${ALBUM_INFORMATION#* from }")
+
   ALBUM_ARTIST=$(echo "${ALBUM_INFORMATION#* from }")
   ALBUM_ARTIST=$(remove_quotes "${ALBUM_ARTIST}")
+
   ALBUM_ARTIST=$(remove_quotes "${ALBUM_ARTIST}")
 
fi
 
fi
  
 
# check if cd has cdtext
 
# check if cd has cdtext
if [[ true == ${CD_TEXT_DETECTED} ]]; then
+
if [[ true == ${CD_TEXT_DETECTED} ]]; then
   if [[ "2" = "$#" ]]; then
+
   if [[ "2" = "$#" ]]; then
 
     echo "CD-text found"
 
     echo "CD-text found"
 
     echo "Overriding given output directory name"
 
     echo "Overriding given output directory name"
 
   fi
 
   fi
   mkdir -p "./${ALBUM_ARTIST}/${ALBUM_TITLE}"
+
   mkdir -p "./${ALBUM_ARTIST}/${ALBUM_TITLE}"
   cd "./${ALBUM_ARTIST}/${ALBUM_TITLE}"
+
   cd "./${ALBUM_ARTIST}/${ALBUM_TITLE}"
   OUTPUT_DIRECTORY="${ALBUM_ARTIST}/${ALBUM_TITLE}"
+
   OUTPUT_DIRECTORY="${ALBUM_ARTIST}/${ALBUM_TITLE}"
   OUTPUT_FILENAME="${ALBUM_TITLE}"
+
   OUTPUT_FILENAME="${ALBUM_TITLE}"
 
else
 
else
   if [[ "$#" != "2" ]]; then
+
   if [[ "$#" != "2" ]]; then
 
     no_cdtext
 
     no_cdtext
 
   else
 
   else
     mkdir "${OUTPUT_DIRECTORY}"
+
     mkdir "${OUTPUT_DIRECTORY}"
     cd "${OUTPUT_DIRECTORY}"
+
     cd "${OUTPUT_DIRECTORY}"
     OUTPUT_FILENAME="${OUTPUT_DIRECTORY}"
+
     OUTPUT_FILENAME="${OUTPUT_DIRECTORY}"
 
   fi
 
   fi
 
fi
 
fi
  
# cdda2wav -cuefile -paranoia -t all dev=${CDROM} "${OUTPUT_FILENAME}.wav" &> "${OUTPUT_FILENAME}.log"
+
# cdda2wav -cuefile -paranoia -t all dev=${CDROM} "${OUTPUT_FILENAME}.wav" &> "${OUTPUT_FILENAME}.log"
  
if [[ "true" = ${CREATE_OGG} ]]; then
+
if [[ "true" = ${CREATE_OGG} ]]; then
 
   mkdir ogg
 
   mkdir ogg
 
   pushd ogg
 
   pushd ogg
   oggenc -o "${OUTPUT_FILENAME}.ogg" -q 6 "../${OUTPUT_FILENAME}.wav"
+
   oggenc -o "${OUTPUT_FILENAME}.ogg" -q 6 "../${OUTPUT_FILENAME}.wav"
   oggsplt -c "../${OUTPUT_FILENAME}.cue" -o "@N - @t" "${OUTPUT_FILENAME}.ogg"
+
   oggsplt -c "../${OUTPUT_FILENAME}.cue" -o "@N - @t" "${OUTPUT_FILENAME}.ogg"
 
   popd
 
   popd
 
fi
 
fi
  
if [[ "true" = ${CREATE_FLAC} ]]; then
+
if [[ "true" = ${CREATE_FLAC} ]]; then
 
   mkdir flac
 
   mkdir flac
 
   pushd flac
 
   pushd flac
   cd flac  # -5 -V -T "ARTIST=%a" -T "ALBUM=%g" -T "DATE=%y" -T "GENRE=%m" --tag-from-file=CUESHEET="%a - %g.cue" --cuesheet="%a - %g.cue" %s
+
   cd flac  # -5 -V -T "ARTIST=%a" -T "ALBUM=%g" -T "DATE=%y" -T "GENRE=%m" --tag-from-file=CUESHEET="%a - %g.cue" --cuesheet="%a - %g.cue" %s
   flac --cuesheet="../${OUTPUT_FILENAME}.cue" --tag-from-file=CUESHEET="../${OUTPUT_FILENAME}.cue" --output-name="./${OUTPUT_FILENAME}.flac" --best "../${OUTPUT_FILENAME}.wav"
+
   flac --cuesheet="../${OUTPUT_FILENAME}.cue" --tag-from-file=CUESHEET="../${OUTPUT_FILENAME}.cue" --output-name="./${OUTPUT_FILENAME}.flac" --best "../${OUTPUT_FILENAME}.wav"
 
   popd
 
   popd
 
fi
 
fi
  
if [[ "true" = ${CREATE_MKA} ]]; then
+
if [[ "true" = ${CREATE_MKA} ]]; then
 
   mkdir mka
 
   mkdir mka
 
   pushd mka
 
   pushd mka
   # -5 -V -T "ARTIST=%a" -T "ALBUM=%g" -T "DATE=%y" -T "GENRE=%m" --tag-from-file=CUESHEET="%a - %g.cue" --cuesheet="%a - %g.cue" %s
+
   # -5 -V -T "ARTIST=%a" -T "ALBUM=%g" -T "DATE=%y" -T "GENRE=%m" --tag-from-file=CUESHEET="%a - %g.cue" --cuesheet="%a - %g.cue" %s
   flac --output-name="./${OUTPUT_FILENAME}.flac" --best "../${OUTPUT_FILENAME}.wav"
+
   flac --output-name="./${OUTPUT_FILENAME}.flac" --best "../${OUTPUT_FILENAME}.wav"
   mkvmerge -q -o "${OUTPUT_FILENAME}.flac.mka" "${OUTPUT_FILENAME}.flac" --attachment-mime-type text/plain --attachment-description "cdda2wav Log" --attach-file "../${OUTPUT_FILENAME}.log" --attachment-mime-type text/plain --attachment-description "Original CUE Sheet" --attach-file "../${OUTPUT_FILENAME}.cue" --title "${ALBUM_TITLE}" --chapters "../${OUTPUT_FILENAME}.cue"
+
   mkvmerge -q -o "${OUTPUT_FILENAME}.flac.mka" "${OUTPUT_FILENAME}.flac" --attachment-mime-type text/plain --attachment-description "cdda2wav Log" --attach-file "../${OUTPUT_FILENAME}.log" --attachment-mime-type text/plain --attachment-description "Original CUE Sheet" --attach-file "../${OUTPUT_FILENAME}.cue" --title "${ALBUM_TITLE}" --chapters "../${OUTPUT_FILENAME}.cue"
   rm "./${OUTPUT_FILENAME}.flac"
+
   rm "./${OUTPUT_FILENAME}.flac"
 
   popd
 
   popd
 
fi
 
fi
  
# rm "${WORKING_DIRECTORY}/${OUTPUT_DIRECTORY}/${OUTPUT_FILENAME}.{cddb,cdindex,cdtext,wav}"
+
# rm "${WORKING_DIRECTORY}/${OUTPUT_DIRECTORY}/${OUTPUT_FILENAME}.{cddb,cdindex,cdtext,wav}"
 
}}
 
}}

Revision as of 01:27, 9 April 2012

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Graphical tools

There are several tools to create .mp3 or .ogg files from an audio CD (eg. k3b, KAudioCreator, Rhythmbox)

Console tools

abcde is a comprehensive audio ripping tool, including CDDB lookup.

Shell script

If you want to rip an audio CD gapless and using CD-Text you can use the following shell script. You need to have the following packages installed on your system: mp3splt, cdrtools and vorbis-tools.

You need cdrtools from AUR for this script to work: cdrtools

rip_gapless.sh
#!/bin/sh
# This script needs mp3splt, cdrtools, vorbis-tools

CREATE_OGG="false";
CREATE_FLAC="false";
CREATE_MKA="true";

WORKING_DIRECTORY=`pwd`

function usage() 
{ 
  echo "Usage: $0 [OUTPUT_DIRECTORY] device";
  echo "eg.: $0 my_audio_cd /dev/sr0";
  exit;
}

function no_cdtext()
{
  echo "CD doesn't contain cd-text information";
  echo "Please specify output directory";
  echo "$0 OUTPUT_DIRECTORY device";
  exit;
}

function remove_quotes() {
  local OUTPUT_STRING
  # remove quotes
  OUTPUT_STRING=$(echo "$1" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
  # remove selected special characters
  echo "$OUTPUT_STRING" | sed "s/\(.*\)[\\]\(.*\)/\1\2/g"
}


# store command line parameters
if  [[ "$#" = "2" ]] ; then
  CDROM=$2;
  OUTPUT_DIRECTORY=$1;
elif [[ "$#" = "1" ]] ; then
  CDROM=$1;
else 
  usage;
fi

# retrieve CD information
echo "Retrieve CD information"
# CD_INFO=$(cdda2wav -J -g /dev/sr0 2>&1)

# test if CD-Text is available
if [[ "detected" == $(echo "${CD_INFO}" | awk '/^CD-Text.*/ {print $2}') ]]; then
  echo "CD-Text detected"
  CD_TEXT_DETECTED=true
  ALBUM_INFORMATION=$(echo "${CD_INFO}" | grep ^"Album title")
  # remove characters from beginning of string
  ALBUM_INFORMATION=$(echo "${ALBUM_INFORMATION#*Album title: }")
  ALBUM_TITLE=$(echo "${ALBUM_INFORMATION% from *}")
  ALBUM_TITLE=$(remove_quotes "${ALBUM_TITLE}")
  ALBUM_ARTIST=$(echo "${ALBUM_INFORMATION#* from }")
  ALBUM_ARTIST=$(remove_quotes "${ALBUM_ARTIST}")
fi

# check if cd has cdtext
if [[ true == ${CD_TEXT_DETECTED} ]]; then
  if [[ "2" = "$#" ]]; then
    echo "CD-text found"
    echo "Overriding given output directory name"
  fi
  mkdir -p "./${ALBUM_ARTIST}/${ALBUM_TITLE}"
  cd "./${ALBUM_ARTIST}/${ALBUM_TITLE}"
  OUTPUT_DIRECTORY="${ALBUM_ARTIST}/${ALBUM_TITLE}"
  OUTPUT_FILENAME="${ALBUM_TITLE}"
else
  if [[ "$#" != "2" ]]; then
    no_cdtext
  else
    mkdir "${OUTPUT_DIRECTORY}"
    cd "${OUTPUT_DIRECTORY}"
    OUTPUT_FILENAME="${OUTPUT_DIRECTORY}"
  fi
fi

# cdda2wav -cuefile -paranoia -t all dev=${CDROM} "${OUTPUT_FILENAME}.wav" &> "${OUTPUT_FILENAME}.log"

if [[ "true" = ${CREATE_OGG} ]]; then
  mkdir ogg
  pushd ogg
  oggenc -o "${OUTPUT_FILENAME}.ogg" -q 6 "../${OUTPUT_FILENAME}.wav"
  oggsplt -c "../${OUTPUT_FILENAME}.cue" -o "@N - @t" "${OUTPUT_FILENAME}.ogg"
  popd
fi

if [[ "true" = ${CREATE_FLAC} ]]; then
  mkdir flac
  pushd flac
  cd flac  # -5 -V -T "ARTIST=%a" -T "ALBUM=%g" -T "DATE=%y" -T "GENRE=%m" --tag-from-file=CUESHEET="%a - %g.cue" --cuesheet="%a - %g.cue" %s
  flac --cuesheet="../${OUTPUT_FILENAME}.cue" --tag-from-file=CUESHEET="../${OUTPUT_FILENAME}.cue" --output-name="./${OUTPUT_FILENAME}.flac" --best "../${OUTPUT_FILENAME}.wav"
  popd
fi

if [[ "true" = ${CREATE_MKA} ]]; then
  mkdir mka
  pushd mka
  # -5 -V -T "ARTIST=%a" -T "ALBUM=%g" -T "DATE=%y" -T "GENRE=%m" --tag-from-file=CUESHEET="%a - %g.cue" --cuesheet="%a - %g.cue" %s
  flac --output-name="./${OUTPUT_FILENAME}.flac" --best "../${OUTPUT_FILENAME}.wav"
  mkvmerge -q -o "${OUTPUT_FILENAME}.flac.mka" "${OUTPUT_FILENAME}.flac" --attachment-mime-type text/plain --attachment-description "cdda2wav Log" --attach-file "../${OUTPUT_FILENAME}.log" --attachment-mime-type text/plain --attachment-description "Original CUE Sheet" --attach-file "../${OUTPUT_FILENAME}.cue" --title "${ALBUM_TITLE}" --chapters "../${OUTPUT_FILENAME}.cue"
  rm "./${OUTPUT_FILENAME}.flac"
  popd
fi

# rm "${WORKING_DIRECTORY}/${OUTPUT_DIRECTORY}/${OUTPUT_FILENAME}.{cddb,cdindex,cdtext,wav}"