Initial import

This commit is contained in:
Grégory Soutadé 2010-08-01 16:16:02 +02:00
commit 60fa5c197f
3 changed files with 429 additions and 0 deletions

337
gsrip.sh Executable file
View File

@ -0,0 +1,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

85
gsrip.txt Normal file
View File

@ -0,0 +1,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)

7
makedoc.sh Executable file
View File

@ -0,0 +1,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