#!/bin/sh
# $Id$
# elvis: cddb		-- Search for cd track listings in CDDB (www.gracenote.com)
# ianb@erislabs.net 20030124

. surfraw || exit 1

w3_config_hook () {
	def SURFRAW_cddb_search "artist" 
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
  Surfraw search CDDB (www.gracenote.com) for cd track listings
Local options:
  -artists                      Search artists (Default)
  -albums                       Search albums
  -songs                        Search songs
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
	-ar*)  setopt SURFRAW_cddb_search  "artist" ;;
	-alb*) setopt SURFRAW_cddb_search  "album"  ;;
	-so*)  setopt SURFRAW_cddb_search  "track"  ;;
	*) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
if test -z "$w3_args"; then
    w3_browse_url "http://www.gracenote.com/search/"
else
    escaped_args=`w3_url_of_arg $w3_args`
    w3_browse_url "http://www.gracenote.com/search/?query=${escaped_args}&search_type=${SURFRAW_cddb_search}"
fi
