Advertisement
Guest User

lookup.py

a guest
Jun 10th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # This script takes an audio file and performs an echoprint lookup on it.
  4. # Requirements: pyechonest >= 4.2.15 http://code.google.com/p/pyechonest/
  5. #               The echoprint-codegen binary (run make from ../src)
  6. #               an Echo Nest API key
  7.  
  8. import sys
  9. import os
  10.  
  11. import pyechonest.config as config
  12. import pyechonest.song as song
  13.  
  14. config.CODEGEN_BINARY_OVERRIDE = os.path.abspath("/usr/local/bin/echoprint-codegen")
  15.  
  16. # Put your API key in a shell variable ECHO_NEST_API_KEY, or put it here
  17. config.ECHO_NEST_API_KEY='XXXXXXXXXX'
  18.  
  19. def lookup(file):
  20.     # Note that song.identify reads just the first 30 seconds of the file
  21.     fp = song.util.codegen(file)
  22.     if len(fp) and "code" in fp[0]:
  23.         # The version parameter to song/identify indicates the use of echoprint
  24.         result = song.identify(query_obj=fp, version="4.11")
  25.         print "Got result:", result
  26.         if len(result):
  27.             print "Artist: %s (%s)" % (result[0].artist_name, result[0].artist_id)
  28.             print "Song: %s (%s)" % (result[0].title, result[0].id)
  29.         else:
  30.             print "No match. This track may not be in the database yet."
  31.     else:
  32.         print "Couldn't decode", file
  33.  
  34.  
  35. if __name__ == "__main__":
  36.     if len(sys.argv) < 2:
  37.         print >>sys.stderr, "Usage: %s <audio file>" % sys.argv[0]
  38.         sys.exit(1)
  39.     lookup(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement