dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles # fast
git clone https://src.adamsgaard.dk/dotfiles.git # slow
Log | Files | Refs | README | LICENSE Back to index

rip-audio-cd.sh (1375B)


      1 #!/bin/sh
      2 set -e
      3 
      4 help() {
      5     echo "$0 [FORMAT]"
      6     echo "uses cdio, ffmpeg, and id3tag to rip and encode audio cd tracks to FORMAT."
      7     echo "FORMAT is 'mp3' by default"
      8 }
      9 
     10 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
     11     help
     12     exit 0
     13 fi
     14 
     15 cddbinfo=$(cdio cddbinfo)
     16 artist=$(printf "%s" "$cddbinfo" | sed 1q | sed 's/ \/.*$//')
     17 album=$(printf "%s" "$cddbinfo" | sed 1q | sed 's/.* \/ //;s/(.*$//')
     18 
     19 format="${1:-mp3}"
     20 outdir="/home/music/${artist}/${album}/"
     21 
     22 echo "format: $format"
     23 printf "cddbinfo: %s\n" "$cddbinfo"
     24 echo "artist: $artist"
     25 echo "album: $album"
     26 echo "output dir: $outdir"
     27 
     28 while :; do
     29 	printf "above info ok? [Y/n] "
     30 	read -r yn
     31 	case "$yn" in
     32 		[Nn]*) exit 1;;
     33 		*) break;;
     34 	esac
     35 done
     36 
     37 mkdir -p "$outdir"
     38 cd "$outdir"
     39 cdio cdrip
     40 cdio eject
     41 
     42 for f in *.wav; do
     43 	track="$(echo "$f" | sed 's/track\([0-9]*\).wav/\1/')"
     44 	i="$(echo "$track" | sed 's/^0//')"
     45 	title="$(printf "%s" "$cddbinfo" | grep " $i " | sed 's/.*[0-9]  //')"
     46 	fout="${track} ${artist} - ${title}.${format}"
     47 	if [ "$format" = flac ]; then
     48 		flac "$i"
     49 		metaflac \
     50 			--set-tag=ARTIST="$song" \
     51 			--set-tag=ALBUM="$album" \
     52 			--set-tag=TITLE="$title" \
     53 			--set-tag=TRACKNUMBER="$track" \
     54 			"$fout"
     55 	else
     56 		ffmpeg -i "$f" -vn -ar 44100 -ac 2 -ab 192k "$fout"
     57 		id3tag --artist="$artist" --album="$album" --song="$title" --track="$track"\
     58 			"$fout"
     59 	fi
     60 done
     61 
     62 rm ./track*.wav
     63 cd -