Beispiel #1
0
def main(folder):
    if folder.endswith('.mp3'):
        files = [folder]
    else:
        # iterate over all .mp3 files in this directory, and identify them.
        files = [fullpath(folder, f) for f in os.listdir(folder) if f.endswith('.mp3')]
        
    updated = 0
    for path in files:
        print os.path.basename(path)
        songs = None
        try:
            songs = song.identify(path, buckets=['audio_summary'])
        except EchoNestAPIError, e:
            print "API Error: %s" % e
            continue
            
        s = songs and songs.pop()
        if not s:
            print "Couldn't resolve %s" % path
            continue
        
        m = Metadata(s)
        m.write_id3(path, create_only=False, replace=False)
        updated += 1