-#!/bin/sh
+#!/bin/bash
# Copyright (C) 1999 Nathaniel Smith <njs@uclink4.berkeley.edu>
# Copyright (C) 1999, 2000, 2001 Robert Woodcock <rcw@debian.org>
# This code is hereby licensed for public consumption under either the
# GNU GPL v2 or greater, or Larry Wall's Artistic License - your choice.
#
-# You should have recieved a copy of the GNU General Public License
+# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Copyright for this work is to expire January 1, 2010, after which it
# shall be public domain.
HTTPGETOPTS=${HTTPGETOPTS:="-f -s"}
else
HTTPGET=wget
- HTTPGETOPTS=${HTTPGETOPTS:="-q -O -"}
+ HTTPGETOPTS=${HTTPGETOPTS:="-q -nv -e timestamping=off -O -"}
fi
fi
query server proto user host disc-id tracks
Looks up disc on server (should be of form "http://host/~cddb/cddb.cgi")
remainder of command line is in the same form as that returned
- by the cd-discid program.
+ by the cd-discid program.
read server proto user host disc-id genre
CDDB file is dumped to stdout. File will contain an extra
#CATEGORY= line, which leaves it a valid CDDB file but which will
if the server supports given protocol. Most common values for proto
should be 5 and 3. With 3 you will not get DYEAR and DGENRE fields
in response.
- help
+ help
Display this.
EOF
}
done
}
+new_checkexec ()
+{
+ if [ ! "$@" = "" ]; then
+ # Cut off any command-line option we added in
+ X=$(echo $@ | cut -d' ' -f2)
+ if [ "$(which $X)" = "" ]; then
+ return 1
+ elif [ ! -x $(which $X) ]; then
+ return 2
+ fi
+ fi
+ return 0
+}
+
COMMAND=$1
shift
case $COMMAND in
parse) # takes 1 argument, a filename, and dumps out a sh parseable version
CDDBFILE="$1"
-
+
set -e
# names chosen to match usage in abcde code
DISCID=$(grep ^DISCID= "$CDDBFILE" | cut -f2 -d= | tr -d \[:cntrl:\])
ADDRESS="$2"
DISCID=$(grep ^DISCID= "$FILE" | cut -f2 -d= | tr -d \[:cntrl:\])
CDDBGENRE=$(grep '^#CATEGORY=' "$FILE" | cut -f2- -d= | tr -d \[:cntrl:\])
- grep -v "^#CATEGORY=" "$FILE" | iconv -t utf-8 | mail -a "Content-Type: text/plain; charset=utf-8" -s "cddb $CDDBGENRE $DISCID" "$ADDRESS"
+ # Use bsd-mailx by preference if we can, as it allows addition
+ # of extra headers. Otherwise, try to force UTF-8 via environment
+ if new_checkexec bsd-mailx; then
+ grep -v "^#CATEGORY=" "$FILE" | iconv -t utf-8 | bsd-mailx -a "Content-Type: text/plain; charset=utf-8" -s "cddb $CDDBGENRE $DISCID" "$ADDRESS"
+ else
+ # Find the first UTF-8 locale on the system, if any
+ UTF_LOCALE=$(locale -a | awk '/UTF-8/ { print $1; exit}')
+ if [ "$UTF_LOCALE"x != ""x ] ; then
+ export LC_ALL=$UTF_LOCALE
+ fi
+ grep -v "^#CATEGORY=" "$FILE" | iconv -t utf-8 | mail -s "cddb $CDDBGENRE $DISCID" "$ADDRESS"
+ fi
;;
query) # cddb-tool query serverurl proto user host discid...
shift 4
TRACKINFO="$@"
TRACKINFOPLUS=$(echo $TRACKINFO | tr ' ' '+')
- RESULTS=$($HTTPGET "$SERVER?cmd=cddb+query+$TRACKINFOPLUS\&hello=$HELLOINFO\&proto=$PROTO") || exit $LOOKUP_ERR
+ RESULTS=$($HTTPGET "$SERVER?cmd=cddb+query+$TRACKINFOPLUS&hello=$HELLOINFO&proto=$PROTO") || exit $LOOKUP_ERR
echo "$RESULTS" | tr '\r' '\n' | tr -s '\n' | sed 's/^ //g'
;;
CATEGORY="$5"
DISCID="$6"
HELLOINFO="$USER+$HOST+$NAME+$VERSION"
- $HTTPGET $CDDBDATA "$SERVER?cmd=cddb+read+$CATEGORY+$DISCID\&hello=$HELLOINFO\&proto=$PROTO" 2>/dev/null
+ $HTTPGET $CDDBDATA "$SERVER?cmd=cddb+read+$CATEGORY+$DISCID&hello=$HELLOINFO&proto=$PROTO" 2>/dev/null
;;
stat) # cddb-tool stat serverurl user host proto
HOST="$3"
PROTO="$4"
HELLOINFO="$USER+$HOST+$NAME+$VERSION"
- $HTTPGET $CDDBDATA "$SERVER?cmd=stat&hello=$HELLOINFO\&proto=$PROTO" 2>/dev/null
+ $HTTPGET $CDDBDATA "$SERVER?cmd=stat&hello=$HELLOINFO&proto=$PROTO" 2>/dev/null
;;
help) # help