GSRip

GSRip Commit Details

Date:2010-08-01 16:16:02 (10 years 2 days ago)
Author:Grégory Soutadé
Branch:master
Commit:60fa5c197fc946a76216db634a5d42fb07f88410
Message:Initial import

Changes:
Agsrip.sh (full)
Agsrip.txt (full)
Amakedoc.sh (full)

File differences

gsrip.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/bin/bash
set -e
tmp=
function _exit()
{
cd /
[ ! -z "$tmp" ] && /bin/rm -rf $tmp
}
function usage()
{
echo "gsrip : rip an audio CD into wav/mp3/ogg (Grégory Soutadé <soutade@gmail.com>)"
echo
echo "usage : gsrip.sh [options]"
echo
echo "Options :"
echo "-a|--auto"
echo "\tSelect the first entry from cddb server"
echo ""
echo "-b|--bitrate <bitrate>"
echo "mp3 bitrate (32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320), default : 128"
echo ""
echo "-d|--dest <directory>"
echo "mp3 destination, default : /tmp "
echo ""
echo "-D|--dev <device>"
echo "CDROM device, default : /dev/cdrom"
echo ""
echo "-e|--extract-only"
echo "Only extract wav"
echo ""
echo "-f|--file <file>"
echo "Use a .cddb file instead of retrieving from cddb server"
echo ""
echo "-h|--help"
echo "This message"
echo ""
echo "-o|--overwrite"
echo "Overwrite files if existing, default is skipping"
echo ""
echo "-p|--pattern <pattern>"
echo "Output filename pattern"
echo "%g, %a, %l, %n, %t, %y replaced by genre, artist, album, track number, title, and year"
echo "default is \"%n - %t\""
echo ""
echo "-r|--resume <path>"
echo "Don't extract wav files from CD, just encode. Wav files must be into <path>"
echo "This option can be combined with -f"
echo ""
echo "--wav"
echo "Keep .wav files"
echo ""
echo "--mp3"
echo "Encode wav into mp3"
echo ""
echo "--ogg"
echo "Encode wav into ogg"
exit
}
function isAbsolute()
{
echo "$1" | grep "^/" > /dev/null
return $?
}
trap "_exit" 0
auto=0
bitrate=128
bitrates="32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320"
dev="/dev/cdrom"
dest="/tmp"
extract_only=0
audio_cddb="audio.cddb"
retrieve_infos=1
overwrite=0
pattern="%n - %t"
resume=0
keep_wav=0
encode_mp3=0
encode_ogg=0
[ $# = 0 ] && usage
while getopts ":ab:d:D:ef:hkop:r:-:" arg ; do
if [ "$arg" = "-" ] ; then
arg="${OPTARG%%=*}"
OPTARG="${OPTARG#*=}"
fi
case $arg in
a|auto)
auto=1
;;
b|bitrate)
bitrate=$OPTARG
echo $bitrates | grep $bitrate
if [ ! $? ] ; then
echo "Invalid bitrate $bitrate"
echo "valid bitrates are $bitrates"
exit 1
fi
;;
d|dest)
dest="$OPTARG"
isAbsolute $dest || dest=$PWD/$dest
;;
D|dev)
dev="$OPTARG"
;;
e|extract-only)
extract_only=1
;;
f|file)
audio_cddb="$OPTARG"
isAbsolute $audio_cddb || audio_cddb=$PWD/$audio_cddb
retrieve_infos=0
;;
h|"help")
usage
;;
o|overwrite)
overwrite=1
;;
p|pattern)
pattern="$OPTARG"
;;
r|resume)
resume=1
cd "$OPTARG"
retrieve_infos=0
;;
wav)
keep_wav=1
;;
mp3)
encode_mp3=1
which lame > /dev/null
if [ ! $? ] ; then
echo "lame not found, cannot continue"
exit 1
fi
;;
ogg)
encode_ogg=1
which oggenc > /dev/null
if [ ! $? ] ; then
echo "oggenc not found, cannot continue"
exit 1
fi
;;
":")
echo "Invalid argument: -$OPTARG need argument" >&2
usage
;;
"\?")
echo "Invalid option: -$OPTARG" >&2
usage
;;
esac
done
if [ $keep_wav = 0 -a $encode_mp3 = 0 -a $encode_ogg = 0 ] ; then
echo "At least one of --wav --mp3 --ogg option must be set"
exit 1
fi
if [ $resume = 0 ] ; then
which cdda2wav > /dev/null
if [ ! $? ] ; then
echo "cdda2wav not found, cannot continue"
exit 1
fi
tmp=$(mktemp)
/bin/rm -f $tmp
/bin/mkdir -p $tmp
cd $tmp
fi
if [ $retrieve_infos = 0 ] ; then
if [ ! -f "$audio_cddb" ] ; then
echo "$audio_cddb not found"
exit
fi
cat "$audio_cddb"
echo
echo "Is this correct ? (y[es], n[o], e[xit], c[opy])"
echo -n "> "
read response
if [ "$response" = "c" -o "$response" = "copy" ] ; then
echo /bin/cp audio.cddb /tmp
/bin/cp audio.cddb /tmp
exit
fi
[ ! -z "$response" -a $response != "y" -a $response = "yes" ] && exit
else
if [ $auto = 1 ] ; then
cdda2wav -D "$dev" -L 1 -J -v title
else
# Info query
while [ 1 ] ; do
cdda2wav -D "$dev" -L 0 -J -v title
echo
echo "Is this correct ? (y[es], n[o], e[xit], c[opy])"
echo -n "> "
read response
if [ "$response" = "c" -o "$response" = "copy" ] ; then
echo /bin/cp audio.cddb /tmp
/bin/cp audio.cddb /tmp
exit
fi
[ -z "$response" -o "$response" = "y" -o "$response" = "yes" ] && break
[ "$response" = "e" -o "$response" = "exit" ] && exit
done
fi
fi
# Read CD infos
band="Unknown"
album="Album"
genre="unknown"
year=""
i=0
if [ ! -f "$audio_cddb" ] ; then
while [ -d $dest/$band/$album ] ; do
i=$((i + 1))
album="album$i"
done
else
infos=`cat "$audio_cddb" | grep DTITLE | cut -d= -f2`
band=$(echo $infos | cut -d/ -f1)
album=$(echo $infos | cut -d/ -f2)
genre=`cat "$audio_cddb" | grep DGENRE | cut -d= -f2`
year=`cat "$audio_cddb" | grep DYEAR | cut -d= -f2`
fi
# Suppress spaces
band=$(echo $band)
album=$(echo $album)
genre=$(echo $genre)
year=$(echo $year)
if [ $resume = 0 ] ; then
# Extract wav
tracks=""
track=""
tracknum=1
while [ 1 ] ;
do
if [ $tracknum -lt 10 ] ; then
track="audio_0$tracknum"
else
track="audio_$tracknum"
fi
[ ! -f "$track.inf" ] && break
tracks="$tracks $track.wav"
tracknum=$((tracknum + 1))
done;
cdda2wav -B -D $dev $tracks
fi
# Convert into mp3
dir="$dest/$band/$album"
/bin/mkdir -p "$dir"
if [ $extract_only = 1 ] ; then
cp *.wav $dir
exit
fi
i=0
for track_wav in *.wav ; do
echo $track_wav | grep audio_ >/dev/null || continue
i=$(echo $track_wav | sed -r s/audio_0*\([0-9]*\).wav/\\1/g)
i=$((i - 1))
title=`cat "$audio_cddb" | grep TTITLE$i= | cut -d= -f2`
i=$((i + 1))
if [ $i -lt 10 ] ; then
prefix="0$i"
else
prefix=$i
fi
[ -z "$title" ] && title="Audio Track $prefix"
filename=$pattern
filename=$(echo $filename | sed "s/%g/$genre/g")
filename=$(echo $filename | sed "s/%a/$album/g")
filename=$(echo $filename | sed "s/%l/$band/g")
filename=$(echo $filename | sed "s/%n/$prefix/g")
filename=$(echo $filename | sed "s/%y/$year/g")
filename=$(echo $filename | sed "s/%t/$title/g")
new_file="$dir/$filename"
if [ $encode_mp3 = 1 ] ; then
if [ ! -f "$new_file.mp3" -o $overwrite = 1 ] ; then
lame -b $bitrate -h --tt "$title" --ta "$band" --tl "$album" --ty "$year" --tn $i --tg "$genre" --add-id3v2 $track_wav "$new_file.mp3"
else
echo "$new_file.mp3 already exists, skipping"
fi
fi
if [ $encode_ogg = 1 ] ; then
if [ ! -f "$new_file.ogg" -o $overwrite = 1 ] ; then
oggenc -b $bitrate -q 10 -t "$title" -a "$band" --album "$album" -d "$year" -N $i -G "$genre" $track_wav -o "$new_file.mp3"
else
echo "$new_file.ogg already exists, skipping"
fi
fi
if [ $keep_wav = 1 ] ; then
if [ ! -f "$new_file.wav" -o $overwrite = 1 ] ; then
cp $track_wav "$new_file.wav"
else
echo "$new_file.wav already exists, skipping"
fi
else
/bin/rm -f $track_wav
fi
done
echo "CD extracted into $dest"
exit
gsrip.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
gsrip (1)
=========
:author: Grégory Soutadé
:email: gregory@soutade.fr
:revdate: April 23, 2004
:revnumber: 1
:keywords:
NAME
----
GSRip - rip an audio CD into wav/mp3/ogg
SYNOPSIS
--------
gsrip.sh [options] (--mp3 | --ogg | --wav)
DESCRIPTION
-----------
GSRip is a command line tool used to rip/encode audio CD. It will download track list from a cddb server. In facts it's a wrapper for cdda2wav, lame and oggenc.
OPTIONS
-------
-a::
--auto::
Select the first entry from cddb server
-b::
--bitrate <bitrate>::
mp3 bitrate (32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320), default : 128
-d::
--dest <directory>::
mp3 destination, default : /tmp
-D::
--dev <device>::
CDROM device, default : /dev/cdrom
-e::
--extract-only::
Only extract wav
-f::
--file <file>::
Use a .cddb file instead of retrieving from cddb server
-h::
--help::
This message
-o::
--overwrite::
Overwrite files if existing, default is skipping
-p::
--pattern <pattern>::
Output filename pattern
%g, %a, %l, %n, %t, %y are replaced by genre, artist, album, track number, title, and year
default is "%n - %t"
-r::
--resume <path>::
Don't extract wav files from CD, just encode. Wav files must be into <path>
This option can be combined with -f
--wav::
Keep .wav files
--mp3::
Encode wav into mp3
--ogg::
Encode wav into ogg
SEE ALSO
--------
cdda2wav(2), lame, oggenc
Author
------
Written by Grégory Soutadé <soutade@gmail.com> (december 2009)
Documentation
-------------
Documentation by Grégory Soutadé <soutade@gmail.com> (december 2009)
makedoc.sh
1
2
3
4
5
6
7
#!/bin/bash
rm -f gsrip.1
asciidoc -b docbook -d manpage gsrip.txt
xsltproc --nonet /usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl gsrip.xml
rm -f gsrip.xml
man -l gsrip.1

Archive Download the corresponding diff file

Branches