Skip to content

Commit

Permalink
Example lookup app
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
alastair committed Jun 24, 2011
1 parent ad1a7d4 commit 82fe772
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -27,6 +27,8 @@ Additional non-included requirements for the demo:
API/fp.py - main python module for Echoprint
API/solr.py - Solr's python module (with slight enhancements)

examples/lookup.py - an example fingerprint and lookup of a query

Hashr/ - java project for a custom solr field type to handle Echoprint data

solr/ - complete solr install with Hashr already in the right place and with the right schema and config to make it work.
Expand Down
51 changes: 51 additions & 0 deletions examples/lookup.py
@@ -0,0 +1,51 @@
#!/usr/bin/python

# This script takes an audio file and performs an echoprint lookup on it.
# Note that it does a direct lookup on an echoprint server that you will
# need to boot yourself. See the README.md document for more information
# on how to do this.
# To do a lookup against a public echoprint server, see the example in the
# echoprint-codegen project, which uses the Echo Nest developer API.

# Requirements: The echoprint-codegen binary from the echoprint-codegen project

import sys
import os
import subprocess
try:
import json
except ImportError:
import simplejson as json

sys.path.insert(0, "../API")
import fp

codegen_path = os.path.abspath("../../echoprint-codegen/echoprint-codegen")

def codegen(file, start=0, duration=30):
proclist = [codegen_path, os.path.abspath(file), "%d" % start, "%d" % duration]
p = subprocess.Popen(proclist, stdout=subprocess.PIPE)
code = p.communicate()[0]
return json.loads(code)

def lookup(file):
codes = codegen(file)
if len(codes) and "code" in codes[0]:
decoded = fp.decode_code_string(codes[0]["code"])
result = fp.best_match_for_query(decoded)
print "Got result:", result
if result.TRID:
print "ID: %s" % (result.TRID)
print "Artist: %s" % (result.metadata.get("artist"))
print "Song: %s" % (result.metadata.get("track"))
else:
print "No match. This track may not be in the database yet."
else:
print "Couldn't decode", file


if __name__ == "__main__":
if len(sys.argv) < 2:
print >>sys.stderr, "Usage: %s <audio file>" % sys.argv[0]
sys.exit(1)
lookup(sys.argv[1])

0 comments on commit 82fe772

Please sign in to comment.