def fetch_song_analysis(song):
    """
    Fetches song analysis of `song` from EchoNest.

    Args:
        song: a pyechonest Song object
    Returns:
        analysis: a dictionary containing all info EchoNest provides for the
                  song in question
    """
    opener = urllib2.build_opener()

    title = song.title if song.title else 'Unknown title'
    artist = song.artist_name if song.artist_name else 'Unknown artist'
    messenger.print_subtask('%s - %s' % (artist, title))

    song.get_audio_summary()
    analysis_url = song.audio_summary['analysis_url']

    request = urllib2.Request(analysis_url)
    f = opener.open(request)
    analysis = simplejson.load(f)

    analysis['audio_summary'] = song.audio_summary

    return analysis
Example #2
0
def get_segments(song):
    song.get_audio_summary()
    analysis_url = song.audio_summary["analysis_url"]

    r = requests.get(analysis_url)
    analysis = r.json()

    return analysis["segments"]
Example #3
0
def lookup(file):
    # Note that song.identify reads just the first 30 seconds of the file
    fp = pyechonest.song.util.codegen(file)
    #print "fp=%s" % fp
    if len(fp) and "code" in fp[0]:
        # The version parameter to song/identify indicates the use of echoprint
        result = pyechonest.song.identify(query_obj=fp, version="4.12")
        print "Got result:", result
        if len(result):
            song = result[0]
            print "artist=%s" % song.artist_name.encode('ascii', 'replace')
            print "song=%s" % song.title.encode('ascii', 'replace')
            summary = song.get_audio_summary()
            for attribute in summary:
                print "%s=%s" % (attribute, summary[attribute])

            score = song.score
            code_count = fp[0]["code_count"]
            print "score=%d code_count=%d accuracy=%f" % (score, code_count, float(score)/code_count)
        else:
            print "No match. This track may not be in the database yet."
    else:
        print "Couldn't decode", file