├── artist_api ├── 01_artist_init.py ├── 02_artist_similars.py ├── 03_artist_news.py ├── 04_artist_audio.py ├── 05_artist_bios.py ├── 06_artist_blogs.py ├── 07_artist_reviews.py ├── 08_artist_images.py ├── 09_artist_video.py ├── 10_artist_summary.py ├── 11_hottt_artists.py ├── 12_hottt_similars.py └── 13_top_term_artists.py ├── bucket_api ├── 01_search_buckets.py └── 02_without_buckets.py ├── catalog_api ├── 02_rosetta_ids.py ├── 03_limit_search_catalog.py ├── 04_catalog_init.py ├── 05_catalog_update.py ├── 06_catalog_delete.py ├── 07_catalog_read_items.py └── 08_catalog_get_feed.py ├── playlist_api ├── 01a_playlist_static_artist_radio.py ├── 01b_playlist_static_song_radio.py ├── 02_playlist_dynamic_artist.py └── 03_playlist_dynamic_steer.py ├── song_api ├── 01_artist_songs.py ├── 02_song_search_by_artist.py ├── 03_musical_search.py ├── 04_song_basic.py ├── 05_song_audio_summary.py └── 06_songs_to_artists.py ├── supplemental_api └── 01_song_audio_details.py └── track_api ├── 01_song_get_tracks.py ├── 02_track_init_id.py ├── 03_track_from_filename.py └── 04_track_reanalyzing_md5.py /artist_api/01_artist_init.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | ra_search_results = artist.search(name='Rise Against') 9 | if ra_search_results: 10 | ra_by_search = ra_search_results[0] 11 | 12 | print 'Found "%s" (%s) by artist.search()' % (ra_by_search.name, ra_by_search.id) 13 | 14 | ra_by_id = artist.Artist('ARZWK2R1187B98F09F') 15 | 16 | if (ra_by_id == ra_by_search): 17 | print 'Found "%s" (%s) by ID initialization' % (ra_by_id.name, ra_by_id.id) 18 | 19 | ra_by_name = artist.Artist('Rise Against') 20 | 21 | if (ra_by_name == ra_by_search): 22 | print 'Found "%s" (%s) by name initialization' % (ra_by_name.name, ra_by_name.id) 23 | 24 | else: 25 | print 'Artist not found by artist.search()' 26 | -------------------------------------------------------------------------------- /artist_api/02_artist_similars.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | bk_results = artist.search(name='bikini kill') 9 | 10 | if bk_results: 11 | bk = bk_results[0] 12 | print 'Artists similar to: %s:' % (bk.name,) 13 | for similar_artist in bk.similar: 14 | print ' %s' % (similar_artist.name,) 15 | else: 16 | print 'Artist not found.' 17 | -------------------------------------------------------------------------------- /artist_api/03_artist_news.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | bk_results = artist.search(name='bikini kill') 9 | 10 | if bk_results: 11 | bk = bk_results[0] 12 | print 'News for %s:' % (bk.name,) 13 | for news_document in bk.news: 14 | print '%s' % (news_document['name'],) 15 | for key, val in news_document.iteritems(): 16 | print ' \'%s\': %s' % (key, val) 17 | else: 18 | print 'Artist not found.' 19 | -------------------------------------------------------------------------------- /artist_api/04_artist_audio.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | be_results = artist.search(name='bright eyes') 9 | 10 | if be_results: 11 | be = be_results[0] 12 | print 'Audio for %s:' % (be.name,) 13 | for audio_document in be.audio: 14 | print '%s' % (audio_document['artist'],) 15 | for key, val in audio_document.iteritems(): 16 | print ' \'%s\': %s' % (key, val) 17 | else: 18 | print 'Artist not found.' 19 | -------------------------------------------------------------------------------- /artist_api/05_artist_bios.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | weezer_results = artist.search(name='weezer') 9 | 10 | if weezer_results: 11 | weezer = weezer_results[0] 12 | print 'Biographies for %s:' % (weezer.name,) 13 | for bio_document in weezer.biographies: 14 | print '%s' % (bio_document['site'],) 15 | for key, val in bio_document.iteritems(): 16 | print ' \'%s\': %s' % (key, val) 17 | else: 18 | print 'Artist not found.' 19 | -------------------------------------------------------------------------------- /artist_api/06_artist_blogs.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | weezer_results = artist.search(name='weezer') 9 | 10 | if weezer_results: 11 | weezer = weezer_results[0] 12 | print 'Blogs for %s:' % (weezer.name,) 13 | for blog_document in weezer.blogs: 14 | print '%s' % (blog_document['name'],) 15 | for key, val in blog_document.iteritems(): 16 | print ' \'%s\': %s' % (key, val) 17 | else: 18 | print 'Artist not found.' 19 | -------------------------------------------------------------------------------- /artist_api/07_artist_reviews.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | td_results = artist.search(name='The Decemberists') 9 | 10 | if td_results: 11 | td = td_results[0] 12 | for review_document in td.reviews: 13 | print 'Album Review: "%s" by %s' % (review_document['release'], td.name) 14 | for key, val in review_document.iteritems(): 15 | print ' \'%s\': %s' % (key, val) 16 | else: 17 | print 'Artist not found.' 18 | -------------------------------------------------------------------------------- /artist_api/08_artist_images.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | td_results = artist.search(name='The Decemberists') 9 | 10 | if td_results: 11 | td = td_results[0] 12 | print 'Images for %s:' % (td.name,) 13 | for image_document in td.images: 14 | print '%s' % (image_document['url'][image_document['url'].rfind('/') + 1:],) 15 | for key, val in image_document.iteritems(): 16 | print ' \'%s\': %s' % (key, val) 17 | else: 18 | print 'Artist not found.' 19 | -------------------------------------------------------------------------------- /artist_api/09_artist_video.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | okg_results = artist.search(name='OK Go') 9 | 10 | if okg_results: 11 | okg = okg_results[0] 12 | print 'Vidoes for %s:' % (okg.name,) 13 | for video_document in okg.video: 14 | print '%s' % (video_document['title']) 15 | for key, val in video_document.iteritems(): 16 | print ' \'%s\': %s' % (key, val) 17 | else: 18 | print 'Artist not found.' 19 | -------------------------------------------------------------------------------- /artist_api/10_artist_summary.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | okg_results = artist.search(name='OK Go') 9 | 10 | if okg_results: 11 | okg = okg_results[0] 12 | print '%s (Echo Nest Artist ID: %s)' % (okg.name, okg.id) 13 | print 'Hotttnesss: %s, Familiarity: %s\n' % (okg.hotttnesss, okg.familiarity) 14 | print 'Terms: ', ', '.join([term.get('name') for term in okg.terms]), '\n' 15 | print 'Similar artists: ', ', '.join(similar_artist.name for similar_artist in okg.similar), '\n' 16 | 17 | print 'Artist URLs:' 18 | for url_key, url_val in okg.urls.iteritems(): 19 | print '%-16s %s' % ('\'' + url_key + '\'' + ':', url_val) 20 | 21 | print '\n%-20s %s' % ('News articles found:', okg.news.total) 22 | print '%-20s %s' % ('Blog articles found:', okg.blogs.total) 23 | print '%-20s %s' % ('Album reviews found:', okg.reviews.total) 24 | print '%-20s %s' % ('Songs found:', okg.songs.total) 25 | print '%-20s %s' % ('Audio URLs found:', okg.audio.total) 26 | print '%-20s %s' % ('Videos found:', okg.video.total) 27 | print '%-20s %s' % ('Images found:', okg.images.total) 28 | print '%-20s %s' % ('Biographies found:', okg.biographies.total) 29 | else: 30 | print 'Artist not found.' 31 | -------------------------------------------------------------------------------- /artist_api/11_hottt_artists.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | hottt_artists = artist.top_hottt() 9 | 10 | for hottt_artist in hottt_artists: 11 | print hottt_artist.name, hottt_artist.hotttnesss 12 | -------------------------------------------------------------------------------- /artist_api/12_hottt_similars.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | hottt_artists = artist.top_hottt(results=3) 9 | 10 | similar_artists = artist.similar(names=[hottt_artist.name for hottt_artist in hottt_artists]) 11 | 12 | for similar_artist in similar_artists: 13 | similar_to = [] 14 | for hottt_artist in hottt_artists: 15 | if similar_artist in hottt_artist.similar: 16 | similar_to.append(hottt_artist.name) 17 | 18 | print '%-30s %16s %s' % (similar_artist.name[0:30], 19 | similar_artist.hotttnesss, 20 | '...is in the top 15 similars of: ' + ', '.join(similar_to)) 21 | -------------------------------------------------------------------------------- /artist_api/13_top_term_artists.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | t_terms = [term_doc.get('name') for term_doc in artist.top_terms()] 9 | 10 | term_artists = artist.search(description=t_terms[2:4]) 11 | 12 | print 'Artists matching these top terms: ', ', '.join(t_terms[2:4]) 13 | for term_artist in term_artists: 14 | artist_terms = [term_doc.get('name') for term_doc in term_artist.terms[0:4]] 15 | print '%-30s terms: %s' % (term_artist.name[0:28] + ', ', ', '.join(artist_terms)) 16 | -------------------------------------------------------------------------------- /bucket_api/01_search_buckets.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import song 7 | from pyechonest import artist 8 | 9 | jazzy_results = artist.search(description=['jazz', 'bebop'], buckets=['hotttnesss', 'images'], results=5) 10 | 11 | for jazzy_artist in jazzy_results: 12 | print jazzy_artist.name 13 | print 'hotttnesss: ', jazzy_artist.hotttnesss 14 | if jazzy_artist.images: 15 | print 'image: ', jazzy_artist.images[0]['url'] 16 | 17 | print 'songs:' 18 | ja_songs = song.search(artist_id=jazzy_artist.id, buckets=['audio_summary'], results=3) 19 | for ja_song in ja_songs: 20 | print ' "%s"\n tempo: %s, energy: %s' % (ja_song.title, ja_song.audio_summary['tempo'], ja_song.audio_summary['energy']) 21 | 22 | print '' 23 | -------------------------------------------------------------------------------- /bucket_api/02_without_buckets.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import song 7 | from pyechonest import artist 8 | 9 | jazzy_results = artist.search(description=['jazz', 'bebop'], results=5) 10 | 11 | for jazzy_artist in jazzy_results: 12 | print jazzy_artist.name 13 | print 'hotttnesss: ', jazzy_artist.hotttnesss 14 | if jazzy_artist.images: 15 | print 'image: ', jazzy_artist.images[0]['url'] 16 | 17 | print 'songs:' 18 | ja_songs = song.search(artist_id=jazzy_artist.id, results=3) 19 | for ja_song in ja_songs: 20 | print ' "%s"\n tempo: %s, energy: %s' % (ja_song.title, ja_song.audio_summary['tempo'], ja_song.audio_summary['energy']) 21 | 22 | print '' 23 | -------------------------------------------------------------------------------- /catalog_api/02_rosetta_ids.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | synthpop_results = artist.search(description=['synthpop'], buckets=['id:7digital', 'id:musicbrainz'], results=5) 9 | 10 | for sp_artist in synthpop_results: 11 | print '%s (Echonest Nest ID: %s)' % (sp_artist.name, sp_artist.id) 12 | temp_artist = artist.Artist(sp_artist.get_foreign_id('7digital')) 13 | if temp_artist == sp_artist: 14 | print '%s (Echonest Nest ID: %s)' % (temp_artist.name, temp_artist.id) 15 | else: 16 | print '7digital artist is not the same' 17 | 18 | print ' 7digitial ID: ', sp_artist.get_foreign_id('7digital') 19 | print ' MusicBrainz ID: ', sp_artist.get_foreign_id('musicbrainz'), '\n' 20 | -------------------------------------------------------------------------------- /catalog_api/03_limit_search_catalog.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | buckets_options = [['id:7digital'], 9 | ['id:playme'], 10 | ['id:musicbrainz'], 11 | ['id:7digital', 'id:playme', 'id:musicbrainz']] 12 | 13 | for bucket_set in buckets_options: 14 | te_results = artist.search(name='The Ernies', buckets=bucket_set, limit=True) 15 | if te_results: 16 | print 'Found %s in %s.' % (te_results[0].name, bucket_set) 17 | else: 18 | print 'Not found in %s.' % (bucket_set,) 19 | -------------------------------------------------------------------------------- /catalog_api/04_catalog_init.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import catalog 7 | 8 | c = catalog.Catalog('example_songs', type='song') 9 | 10 | print 'Initialized Catalog: "%s" with id %s.' % (c.name, c.id) 11 | 12 | print 'Items in catalog: %s' % (c.read.total, ) 13 | print 'Items in catalog: %s' % (c.read_items().total, ) 14 | 15 | print 'Catalog profile:' 16 | cp = c.profile 17 | for key, val in cp.iteritems(): 18 | print ' %-15s %s' % (key, val) 19 | -------------------------------------------------------------------------------- /catalog_api/05_catalog_update.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import catalog, song 7 | import time 8 | 9 | c = catalog.Catalog('example_songs', type='song') 10 | 11 | song_artist_pairs = [('Lust For Life', 'Iggy Pop'), ('Under Cover Of Darkness', 'The Strokes'), ('B.O.B.', 'Outkast'), ('Help!', 'The Beatles')] 12 | 13 | item_id = 0 14 | items = [] 15 | 16 | for song_artist in song_artist_pairs: 17 | items += [{ 'item': 18 | { 19 | 'item_id': str(item_id), 20 | 'song_name': song_artist[0], 21 | 'artist_name': song_artist[1] 22 | } 23 | }] 24 | item_id += 1 25 | 26 | ticket = c.update(items) 27 | 28 | for i in range(0,12): 29 | time.sleep(5) 30 | if c.status(ticket)['ticket_status'] == 'complete': 31 | break 32 | 33 | if c.status(ticket)['ticket_status'] == 'complete': 34 | print 'Updated. read_items() titles:' 35 | for item in c.read_items(): 36 | if type(item) is song.Song: 37 | print ' "%s"' % (item.title, ) 38 | else: 39 | print ' "%s" not resolved' % (item['request']['song_name']) 40 | print ' %s' % (item,) 41 | cp = c.get_profile() 42 | print '\nCatalog profile:' 43 | for key, val in cp.iteritems(): 44 | print ' %-15s %s' % (key, val) 45 | else: 46 | print 'Update did not complete within 60 seconds.' 47 | -------------------------------------------------------------------------------- /catalog_api/06_catalog_delete.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import catalog, song 7 | import time 8 | 9 | c = catalog.Catalog('example_songs', type='song') 10 | 11 | items = [{ 'action': 'delete', 12 | 'item': { 'item_id': '1' }}] 13 | 14 | ticket = c.update(items) 15 | 16 | for i in range(0,12): 17 | time.sleep(5) 18 | if c.status(ticket)['ticket_status'] == 'complete': 19 | break 20 | 21 | if c.status(ticket)['ticket_status'] == 'complete': 22 | print 'Updated. read_items() titles:' 23 | for item in c.read_items(): 24 | if type(item) is song.Song: 25 | print ' "%s"' % (item.title, ) 26 | else: 27 | print ' "%s" not resolved' % (item['request']['song_name']) 28 | print ' %s' % (item,) 29 | cp = c.get_profile() 30 | print '\nCatalog profile:' 31 | for key, val in cp.iteritems(): 32 | print ' %-15s %s' % (key, val) 33 | else: 34 | print 'Update did not complete within 60 seconds.' 35 | -------------------------------------------------------------------------------- /catalog_api/07_catalog_read_items.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import catalog 7 | 8 | c = catalog.Catalog('example_songs', type='song') 9 | 10 | for item in c.read_items(buckets=['audio_summary','artist_hotttnesss']): 11 | print '"%s"' % (item.title,) 12 | print ' artist_hotttness: %s' % (item.artist_hotttnesss) 13 | print ' tempo: %s' % (item.audio_summary['tempo']) 14 | print ' energy: %s' % (item.audio_summary['energy']) 15 | -------------------------------------------------------------------------------- /catalog_api/08_catalog_get_feed.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import catalog 7 | 8 | c = catalog.Catalog('example_songs', type='song') 9 | 10 | older_news = c.get_feed(buckets=['news'], since='2011-03-01', start=20) 11 | newer_news = c.get_feed(buckets=['news'], since='2011-04-01', start=20) 12 | 13 | newer = False 14 | for feed_list in [older_news, newer_news]: 15 | if not newer: 16 | print 'Older news items:' 17 | print ' Full example item:' 18 | for key, val in feed_list[0].iteritems(): 19 | print ' %-12s %s' % (key, val) 20 | print '' 21 | newer = True 22 | else: 23 | print '\nNewer news items:' 24 | 25 | print ' Date posted for each news item:' 26 | for feed_item in feed_list: 27 | print ' %s about %s' % (feed_item['date_posted'],feed_item['references'][0]['artist_name']) 28 | -------------------------------------------------------------------------------- /playlist_api/01a_playlist_static_artist_radio.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import playlist, artist 7 | 8 | tsquare = artist.Artist('Thompson Square') 9 | jaldean = artist.Artist('Jason Aldean') 10 | afire = artist.Artist('Arcade Fire') 11 | 12 | a_playlist = playlist.static(type='artist-radio', artist_id=[tsquare.id, jaldean.id, afire.id], results=5) 13 | 14 | other_playlist = playlist.static(type='artist-radio', artist_id=[tsquare.id, jaldean.id, afire.id], results=5) 15 | 16 | print 'Songs in one playlist for seed artists %s:' % (', '.join(an_artist.name for an_artist in [tsquare, jaldean, afire]),) 17 | for a_song in a_playlist: 18 | print '"%s" by %s' % (a_song.title, a_song.artist_name) 19 | 20 | print '' 21 | 22 | print 'Songs in another playlist for seed artists %s:' % (', '.join(an_artist.name for an_artist in [tsquare, jaldean, afire]),) 23 | for a_song in other_playlist: 24 | print '"%s" by %s' % (a_song.title, a_song.artist_name) 25 | -------------------------------------------------------------------------------- /playlist_api/01b_playlist_static_song_radio.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import playlist, song 7 | 8 | kwstr = song.Song('SOSGSJB12A8C13B2D4') 9 | dptec = song.Song('SOOSADY12A6701F119') 10 | jwcb = song.Song('SOCEGKM12A58A7F30D') 11 | 12 | a_playlist = playlist.static(type='song-radio', song_id=[kwstr.id, dptec.id, jwcb.id], results=5) 13 | 14 | other_playlist = playlist.static(type='song-radio', song_id=[kwstr.id, dptec.id, jwcb.id], results=5) 15 | 16 | print 'Songs in one playlist for seed songs "%s":' % ('," "'.join(a_song.title for a_song in [kwstr, dptec, jwcb]),) 17 | for a_song in a_playlist: 18 | print '"%s" by %s' % (a_song.title, a_song.artist_name) 19 | 20 | print '' 21 | 22 | print 'Songs in another playlist for seed songs "%s":' % ('," "'.join(a_song.title for a_song in [kwstr, dptec, jwcb]),) 23 | for a_song in other_playlist: 24 | print '"%s" by %s' % (a_song.title, a_song.artist_name) 25 | -------------------------------------------------------------------------------- /playlist_api/02_playlist_dynamic_artist.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import playlist 7 | 8 | dyn_playlist = playlist.Playlist(type='artist', artist=['muse', 'death cab for cutie', 'the postal service']) 9 | 10 | print 'First five songs in a dynamic playlist for artists Muse, Death Cab for Cutie, and The Postal Service:' 11 | for i in range(0,5): 12 | print '"%s" by %s' % (dyn_playlist.song.title, dyn_playlist.song.artist_name) 13 | dyn_playlist.get_next_song() 14 | -------------------------------------------------------------------------------- /playlist_api/03_playlist_dynamic_steer.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import playlist 7 | 8 | prc = playlist.Playlist(type='artist-description', description=['style:progressive+rock', 'country']) 9 | 10 | print 'First three songs for description: "%s" with no steering:' % (', '.join(prc.info['description'])) 11 | print ' "%s" by %s' % (prc.song.title, prc.song.artist_name) 12 | for i in range(0,2): 13 | prc.get_next_song() 14 | print ' "%s" by %s' % (prc.song.title, prc.song.artist_name) 15 | 16 | print '\nNext five songs, increasing tempo:' 17 | for i in range(0,5): 18 | prc.get_next_song(steer='tempo^1.1') 19 | if prc.song.audio_summary: 20 | print ' "%s" by %s, tempo: %s' % (prc.song.title, prc.song.artist_name, prc.song.audio_summary['tempo']) 21 | 22 | def get_frequency(dyn_playlist, term_name): 23 | for a_term in dyn_playlist.info['terms']: 24 | if a_term['name'] == term_name: 25 | return a_term['frequency'] 26 | return None 27 | 28 | print '\nCurrent playlist:' 29 | print ' "country" frequency: %s' % (get_frequency(prc, 'country'),) 30 | print ' "jazz" frequency: %s' % (get_frequency(prc, 'jazz'),) 31 | 32 | print '\nGetting another song while removing "country," adding "mood:happy," and excluding "style:jazz"' 33 | prc.get_next_song(steer_description=['country^0', 'mood:happy', '-style:jazz']) 34 | 35 | print '\nUpdated playlist:' 36 | print ' description: "%s"' % (', '.join(prc.info['description']),) 37 | print ' "country" frequency: %s' % (get_frequency(prc, 'country'),) 38 | print ' "jazz" frequency: %s' % (get_frequency(prc, 'jazz'),) 39 | 40 | print '\nNext song:' 41 | print ' "%s" by %s' % (prc.song.title, prc.song.artist_name) 42 | -------------------------------------------------------------------------------- /song_api/01_artist_songs.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import artist 7 | 8 | kc_results = artist.search(name='Kid Cudi') 9 | if kc_results: 10 | kc = kc_results[0] 11 | for a_song in kc.get_songs(results=20, start=30): 12 | print '%s (Echo Nest ID: %s) by %s' % (a_song.title, a_song.id, a_song.artist_name) 13 | else: 14 | print 'Artist not found.' 15 | -------------------------------------------------------------------------------- /song_api/02_song_search_by_artist.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import song 7 | 8 | kc_songs = song.search(artist='Kid Cudi', results=20, start=30) 9 | 10 | if kc_songs: 11 | for a_song in kc_songs: 12 | print '"%s" by %s' % (a_song.title, a_song.artist_name) 13 | else: 14 | print 'No songs found.' 15 | -------------------------------------------------------------------------------- /song_api/03_musical_search.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import song 7 | 8 | short_quiet_songs = song.search(max_duration=90, max_loudness=-50, start=5, results=11) 9 | 10 | if short_quiet_songs: 11 | for a_song in short_quiet_songs: 12 | print '"%s" by %s' % (a_song.title, a_song.artist_name) 13 | else: 14 | print 'No songs found.' 15 | -------------------------------------------------------------------------------- /song_api/04_song_basic.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import song 7 | 8 | ntt_results = song.search(artist='Charlie Parker', title='Now\'s the time') 9 | ritd_results = song.search(artist='Adele', title='rolling in the deep') 10 | 11 | if ntt_results and ritd_results: 12 | for a_song in [ntt_results[0], ritd_results[0]]: 13 | print '"%s" (%s)\nby %s (%s)' % (a_song.title, a_song.id, a_song.artist_name, a_song.artist_id) 14 | print 'Song hotttnesss: ', a_song.song_hotttnesss 15 | print 'Artist hotttnesss: %s, artist familiarity: %s' % (a_song.artist_hotttnesss, a_song.artist_familiarity) 16 | print 'Artist location:' 17 | for loc_key, loc_val in a_song.artist_location.iteritems(): 18 | print ' %-13s %s' % (loc_key, loc_val) 19 | print '' 20 | else: 21 | print 'Missing a song.' 22 | -------------------------------------------------------------------------------- /song_api/05_song_audio_summary.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import song 7 | 8 | ts_results = song.search(artist='the beatles', title='twist and shout') 9 | 10 | if ts_results: 11 | ts = ts_results[0] 12 | print 'Audio summary of "%s" by %s:' % (ts.title,ts.artist_name) 13 | for aud_key, aud_val in ts.audio_summary.iteritems(): 14 | print ' %-15s %s' % (aud_key, aud_val) 15 | else: 16 | print 'No songs found.' 17 | -------------------------------------------------------------------------------- /song_api/06_songs_to_artists.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import song 7 | from pyechonest import artist 8 | 9 | short_unloud_songs = song.search(max_duration=90, max_loudness=-10, start=34, results=10) 10 | 11 | if short_unloud_songs: 12 | artist_ids = [a_song.artist_id for a_song in short_unloud_songs] 13 | artists = [artist.Artist(id) for id in set(artist_ids)] 14 | for an_artist in artists: 15 | biographies = an_artist.get_biographies(results=1) 16 | if biographies: 17 | print '%-30s %s' % (an_artist.name[0:30], biographies[0]['url']) 18 | else: 19 | print an_artist.name 20 | else: 21 | print 'No songs found.' 22 | -------------------------------------------------------------------------------- /supplemental_api/01_song_audio_details.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import song, track 7 | 8 | sth_results = song.search(title='Stairway to Heaven', artist='Led Zeppelin') 9 | sth = sth_results[0] 10 | 11 | sth_track = track._track_from_response( 12 | {'response': { 13 | 'track': { 14 | 'status': 'complete', 15 | 'id': 'StairwayID', 16 | 'audio_summary': sth.audio_summary 17 | } 18 | }}) 19 | 20 | for attr in ['analysis_channels', 'analysis_sample_rate', 'analysis_url', 'artist', 'audio_md5', 'catalog', 'danceability', 'duration', 'end_of_fade_in', 'energy', 'foreign_id', 'foreign_release_id', 'id', 'key', 'key_confidence', 'loudness', 'md5', 'meta', 'mode', 'mode_confidence', 'num_samples', 'preview_url', 'release_image', 'sample_md5', 'song_id', 'start_of_fade_out', 'status', 'tempo', 'tempo_confidence', 'time_signature', 'time_signature_confidence', 'title']: 21 | if hasattr(sth_track, attr): 22 | print '%-30s %s' % (attr, getattr(sth_track, attr)) 23 | else: 24 | print '%-30s *No such attribute*' % (attr,) 25 | 26 | print '' 27 | 28 | for dicts_attr in ['bars', 'beats', 'sections', 'segments', 'tatums']: 29 | print '"%s" example dict:' % (dicts_attr) 30 | if getattr(sth_track, dicts_attr): 31 | for key, val in getattr(sth_track, dicts_attr)[0].iteritems(): 32 | print ' %-26s %s' % (key, val) 33 | print '' 34 | 35 | print 'pitches for first 20 segments:' 36 | print ('%8s ' + '%-4s ' * 12) % ('start', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B') 37 | for a_dict in sth_track.segments[0:20]: 38 | print ('%8.2f ' + '%4.2f ' * 12) % ((a_dict['start'], ) + tuple(a_dict['pitches'])) 39 | -------------------------------------------------------------------------------- /track_api/01_song_get_tracks.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import song 7 | 8 | groovy_results = song.search(title='59th Street Bridge Song', artist='Simon & Garfunkel', buckets=['id:7digital'], limit=True) 9 | 10 | if groovy_results: 11 | groovy = groovy_results[1] 12 | print 'Tracks for "%s" (%s)\nby %s (%s):\n' % (groovy.title, groovy.id, groovy.artist_name, groovy.artist_id) 13 | for a_track in groovy.get_tracks('7digital'): 14 | print 'Track ID: %s' % (a_track['id']) 15 | for key, val in a_track.iteritems(): 16 | print ' %-20s %s' % (key, val) 17 | print '' 18 | else: 19 | print 'No songs found.' 20 | -------------------------------------------------------------------------------- /track_api/02_track_init_id.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import song, track 7 | 8 | rof_results = song.search(title='Ring of Fire', artist='Johnny Cash', buckets=['id:7digital'], limit=True) 9 | 10 | if rof_results: 11 | rof = rof_results[0] 12 | rof_tracks = rof.get_tracks('7digital') 13 | if rof_tracks: 14 | roft = track.track_from_id(rof_tracks[0]['id']) 15 | for attr in ['analysis_channels', 'analysis_sample_rate', 'analysis_url', 'artist', 'audio_md5', 'catalog', 'danceability', 'duration', 'end_of_fade_in', 'energy', 'foreign_id', 'foreign_release_id', 'id', 'key', 'key_confidence', 'loudness', 'md5', 'meta', 'mode', 'mode_confidence', 'num_samples', 'preview_url', 'release_image', 'sample_md5', 'song_id', 'start_of_fade_out', 'status', 'tempo', 'tempo_confidence', 'time_signature', 'time_signature_confidence', 'title']: 16 | print '%-30s %s' % (attr, getattr(roft, attr)) 17 | print '' 18 | for dicts_attr in ['bars', 'beats', 'sections', 'segments', 'tatums']: 19 | print '"%s" example dict:' % (dicts_attr) 20 | for key, val in getattr(roft, dicts_attr)[0].iteritems(): 21 | print ' %-26s %s' % (key, val) 22 | print '' 23 | else: 24 | print 'No tracks found.' 25 | else: 26 | print 'No songs found.' 27 | -------------------------------------------------------------------------------- /track_api/03_track_from_filename.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import track 7 | 8 | c_major = track.track_from_filename('c_major.mp3', filetype='mp3') 9 | 10 | for attr in ['analysis_channels', 'analysis_sample_rate', 'analysis_url', 'artist', 'audio_md5', 'catalog', 'danceability', 'duration', 'end_of_fade_in', 'energy', 'foreign_id', 'foreign_release_id', 'id', 'key', 'key_confidence', 'loudness', 'md5', 'meta', 'mode', 'mode_confidence', 'num_samples', 'preview_url', 'release_image', 'sample_md5', 'song_id', 'start_of_fade_out', 'status', 'tempo', 'tempo_confidence', 'time_signature', 'time_signature_confidence', 'title']: 11 | if hasattr(c_major, attr): 12 | print '%-30s %s' % (attr, getattr(c_major, attr)) 13 | else: 14 | print '%-30s *No such attribute*' % (attr,) 15 | 16 | print '' 17 | 18 | for dicts_attr in ['bars', 'beats', 'sections', 'segments', 'tatums']: 19 | print '"%s" example dict:' % (dicts_attr) 20 | if getattr(c_major, dicts_attr): 21 | for key, val in getattr(c_major, dicts_attr)[0].iteritems(): 22 | print ' %-26s %s' % (key, val) 23 | print '' 24 | 25 | print 'segment pitches:' 26 | print ('%8s ' + '%-4s ' * 12) % ('start', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B') 27 | for a_dict in c_major.segments: 28 | print ('%8.2f ' + '%4.2f ' * 12) % ((a_dict['start'], ) + tuple(a_dict['pitches'])) 29 | -------------------------------------------------------------------------------- /track_api/04_track_reanalyzing_md5.py: -------------------------------------------------------------------------------- 1 | # Uncomment to set the API key explicitly. Otherwise Pyechonest will 2 | # look in the ECHO_NEST_API_KEY environment variable for the key. 3 | #from pyechonest import config 4 | #config.ECHO_NEST_API_KEY='YOUR API KEY' 5 | 6 | from pyechonest import track 7 | 8 | c_major_file = track.track_from_filename('c_major.mp3', filetype='mp3') 9 | c_major_md5 = track.track_from_md5(c_major_file.md5) 10 | c_major_ra_md5 = track.track_from_reanalyzing_md5(c_major_file.md5) 11 | 12 | for c_major in (c_major_md5, c_major_ra_md5): 13 | print 'track ID: %s' % c_major.id 14 | print 'segment pitches:' 15 | print ('%8s ' + '%-4s ' * 12) % ('start', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B') 16 | for a_dict in c_major.segments: 17 | print ('%8.2f ' + '%4.2f ' * 12) % ((a_dict['start'], ) + tuple(a_dict['pitches'])) 18 | print '' 19 | 20 | --------------------------------------------------------------------------------