Imported Upstream version 1.1.11
[platform/upstream/cdrkit.git] / icedax / cdda2ogg
1 #! /bin/sh
2 # Script for processing all audio tracks with an ogg or mp3 decoder
3 # based on a news article by Tom Kludy
4 # This variant uses named pipes in order to save space.
5 # usage: cdda2ogg <name prefix for all ogg/mp3 files>
6
7 # specify the sampling program and its options
8 # do not specify the track option here!
9 CDDA2WAV=${CDDA2WAV:-icedax}
10 CDDA2WAV_OPTS=${CDDA2WAV_OPTS:-'-H -P0 -q'}
11
12 # for normal use, comment out the next line
13 #DEBUG='-d1'
14
15 # the post processor is fed through a pipe to avoid space waste
16 # specify the post processing program and its options
17 case $0 in
18    *ogg|*OGG|*Ogg)
19    # ensure the right suffix for suffixes later
20    suffix=ogg
21    missmsg="Encoder not found. Install one first! (eg. vorbis-tools)"
22    MP_CODER=${MP_CODER:-oggenc}
23    outopt="-o"
24    ;;
25    *mp3|*MP3|*mpeg3|*MPEG3|*Mp3)
26    suffix=mp3
27    missmsg="Encoder not found. Install one first! (eg. lame)"
28    MP_CODER=${MP_CODER:-lame}
29    outopt=""
30    ;;
31    *)
32    echo Unknown target file type: $suffix. Valid names for this application are: cdda2mp3, cdda2ogg.
33    exit 1
34    ;;
35 esac
36
37 MP_OPTIONS=${MP_OPTIONS:-''}
38
39 MP_CODER=$(which $MP_CODER 2>/dev/null)
40 if [ ! -x "$MP_CODER" ] ; then
41    echo $missmsg
42    exit 1
43 fi
44
45 CDDA_DEVICE=${CDDA_DEVICE:-/dev/cdrw}
46 export CDDA_DEVICE
47
48 FILEPREFIX=${1:-audiotrack}
49
50 if [ -e /etc/default/cdda2$suffix ]; then
51         . /etc/default/cdda2$suffix
52 fi
53
54 if [ -z "$LIST" ] ; then
55    echo Looking for available tracks...
56    # could use list_audio_tracks instead but that would need an extra filter as
57    # well, and this way we do not depend on that symlink
58    LIST="$( $CDDA2WAV -J -vtoc -H 2>&1 | sed -e 's/^[^\ ].*//; s/\.([^)]*)/ /g;s/,//g;')"
59    if [ -z "$LIST" ] ; then
60       echo "ERROR: No valid audio tracks detected"
61       exit 1
62    fi
63 fi
64
65 echo Fetching `echo $LIST | wc -w` tracks from $CDDA_DEVICE, encoding with $MP_CODER.
66 echo Cancel with Ctrl-C, watch out for error messages.
67
68 for TRACK in $LIST ; do
69    NAME="`printf "%02d" $TRACK`-$FILEPREFIX.$suffix"
70    echo
71    echo "############ Starting with Track Nr. $TRACK -> $NAME ############"
72   $CDDA2WAV $CDDA2WAV_OPTS -t$TRACK $DEBUG - | \
73   $MP_CODER $MP_OPTIONS - $outopt "$NAME"
74
75   # check result code
76   RES=$?
77   if [ $RES != 0 ] ; then
78     echo File $NAME failed \(result $RES\). Aborted. >&2
79     break
80   fi
81 done
82