Skip to content

Instantly share code, notes, and snippets.

@highgain86j
Forked from patrickmoffitt/rip_cdrom.sh
Created September 21, 2024 12:15
Show Gist options
  • Save highgain86j/06e942168e0f36e734a167b3bd44a04c to your computer and use it in GitHub Desktop.
Save highgain86j/06e942168e0f36e734a167b3bd44a04c to your computer and use it in GitHub Desktop.
Script to losslessly copy all the tracks on an audio CD to a folder named the same as the album. Requires Mac OS X, a cdrom drive and cdparanoia.
#!/bin/bash
# Script to losslessly copy all the tracks on an audio CD to a folder
# named the same as the album.
#
# System Requirements: Mac OS X, cdrom drive, cdparanoia.
#
# Patrick Moffitt October 8, 2017.
#
CDPARANOIA=$(which cdparanoia)
if [ "$CDPARANOIA" == "" ]; then
echo "cdparanoia not found. Try $ brew install cdparanoia"
exit 127
fi
DEVICE="$(drutil status | sed -En 's/(.*)(\/dev\/disk[0-9])$/\2/p')"
if [ "$DEVICE" == "" ]; then
echo "No CDROM compatable device found. Insert disk (close tray) and retry."
exit 6
fi
ALBUM="$(mount | grep disk2 | sed -En "s/^${DEVICE//\//\\/}.*(Volumes\/)(.*)( \(.*$)/\2/p")"
if [ "$ALBUM" == "" ]; then
echo "The CDROM is not mounted. Wait for the system to mount it and retry."
exit 2
fi
TRACKS="$(ls -1 "/Volumes/${ALBUM}" | sort -g)"
DIR="$(basename "$PWD")"
if [ "$DIR" != "$ALBUM" ]; then
if [ ! -d "$ALBUM" ]; then
mkdir "$ALBUM"
fi
cd "$ALBUM" || exit 2
fi
while read -r TRACK; do
TRACK_NUM=$(echo "$TRACK" | sed -En 's/^([0-9]{1,2})(.*$)/\1/p')
TRACK_NAME="$(echo "$TRACK" | sed -En 's/^([0-9]{1,2}.*)(\..*$)/\1/p')"
cdparanoia "$TRACK_NUM" "${TRACK_NAME}.wav"
done <<< "$TRACKS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment