Skip to content

Instantly share code, notes, and snippets.

@Bajron
Created October 8, 2016 12:17
Show Gist options
  • Save Bajron/367838baae7207543a0ee2d20f15b478 to your computer and use it in GitHub Desktop.
Save Bajron/367838baae7207543a0ee2d20f15b478 to your computer and use it in GitHub Desktop.
#!/bin/bash
case "${1}" in
-h|--help) cat <<EOF
Simple script to save audio tracks as .mp3 files.
This script just automates what VLC can do file by file.
Usage:
$0 destination-dir start-track [end-track]
Example:
# Saves track from 1 to 14 into ./cd-as-mp3 directory
$0 ./cd-as-mp3 1 14
Default start track is 1.
When no end track is provided
only the start track is saved.
If you want to save all tracks, you need to figure out
how many tracks there are on the CD, and which are
actually audio tracks on your own.
You need VLC for this script to work.
EOF
exit ;;
esac
DESTINATION_DIR="${1:?Provide destination directory. Use \"$0 --help\" for details.}"
FIRST_TRACK=${2:-1}
LAST_TRACK=${3:-${FIRST_TRACK}}
FILE_NAME_FORMAT='Track_%03d'
TRANSCODE='vcodec=none,acodec=mp3,ab=192,channels=2,samplerate=44100'
echo "Transcoding tracks from ${FIRST_TRACK} to ${LAST_TRACK}"
echo "Transcoding destination ${DESTINATION_DIR}"
mkdir -p "${DESTINATION_DIR}" || exit
for ((i=${FIRST_TRACK};i<=${LAST_TRACK};++i)); do
OUTPUT=$(printf "${DESTINATION_DIR}/${FILE_NAME_FORMAT}.mp3" "${i}")
echo "Creating ${OUTPUT}"
vlc -I http cdda:///dev/sr0 --cdda-track=${i} \
":sout=#transcode{${TRANSCODE}}:std{access=file,dst=${OUTPUT}}" \
vlc://quit
echo "Done"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment