Skip to content

Commit

Permalink
Initial version of puidlookup
Browse files Browse the repository at this point in the history
  • Loading branch information
alip committed Jan 26, 2010
1 parent 31ab132 commit 7767710
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ Makefile
/stamp-h1

src/afprint
scripts/puidlookup
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ MAINTAINERCLEANFILES= Makefile.in configure aclocal.m4 \
ACLOCAL_AMFLAGS= -I m4
AUTOMAKE_OPTIONS= dist-bzip2 no-dist-gzip std-options foreign
EXTRA_DIST= autogen.sh
SUBDIRS = src .
SUBDIRS = src scripts .
5 changes: 4 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ AC_INIT([src/main.c])

VERSION_MAJOR=0
VERSION_MINOR=1
VERSION_FULL="$VERSION_MAJOR.$VERSION_MINOR"
VERSION_MICRO=0
VERSION_FULL="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_MICRO"
VERSION="$VERSION_FULL"

AC_SUBST([VERSION_MAJOR])
Expand Down Expand Up @@ -66,5 +67,7 @@ AM_CONFIG_HEADER(config.h)
AC_OUTPUT(
Makefile
src/Makefile
scripts/Makefile
scripts/puidlookup
)
dnl }}}
3 changes: 3 additions & 0 deletions scripts/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CLEANFILES= puidlookup
SUBDIRS= .
bin_SCRIPTS= puidlookup
84 changes: 84 additions & 0 deletions scripts/puidlookup.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
# vim: set sw=4 et sts=4 tw=80 :
# Copyright 2010 Ali Polatel <[email protected]>
# Distributed under the terms of the GNU General Public License v2

# Constants
NAME="$(basename "${0}")"
VERSION="@VERSION@"
MUSICDNS_KEY="0a2cbb45cbbe7af5bf61ea5048d7f789"
MUSICDNS_URI="http://ofa.musicdns.org/ofa/1/track"
USER_AGENT="${NAME}/${VERSION}"

# Functions
usage() {
cat <<EOF
${NAME} -- PUID lookup tool
Usage: ${NAME} [-hVv0]
\t-h, --help\tDisplay usage and exit
\t-V, --version\tDisplay version and exit
\t-v, --verbose\tBe verbose
\t-0, --null\tExpect input is null delimited
${NAME} reads filename and audio fingerprint from standard input
EOF
}

post() {
local fmt="${1}"
local dur="${2}"
local fpt="${3}"
shift 3

curl "${@}" -A "${USER_AGENT}" \
--data "cid=${MUSICDNS_KEY}" \
--data "cvr=${NAME}-${VERSION}" \
--data "fpt=${fpt}" \
--data "rmd=2" \
--data "brt=0" \
--data "fmt=${fmt}" \
--data "dur=${dur}" \
--data "art=unknown" \
--data "ttl=unknown" \
--data "alb=unknown" \
--data "tnm=0" \
--data "gnr=unknown" \
--data "yrr=0" \
${MUSICDNS_URI}
}

# Parse options
OPT_DELIM=$' '
CURL_OPTS=()

ARGUMENTS="$(getopt -qo hVv0 -l help,version,verbose,null -- "${@}")"
eval set -- "${ARGUMENTS}"
while true; do
case "${1}" in
-h|--help)
usage
exit;;
-V|--version)
echo "${NAME}-${VERSION}"
exit;;
-0|--null)
OPT_DELIM=$'\0'
shift;;
-v|--verbose)
CURL_OPTS+=( --verbose )
shift;;
--)
shift
break;;
*)
echo "${NAME}: Error parsing arguments" >&2
exit 1;;
esac
done

IFS= read -r -d "${OPT_DELIM}" FILENAME
IFS= read -r -d "${OPT_DELIM}" DURATION
IFS= read -r -d "${OPT_DELIM}" FINGERPRINT
FINGERPRINT="${FINGERPRINT/$'\n'/}"
EXTENSION="${FILENAME##*.}"
post "${EXTENSION}" "${DURATION}" "${FINGERPRINT}" "${CURL_OPTS[@]}"

0 comments on commit 7767710

Please sign in to comment.