Posts Tagged examples

New Genre APIs

localhost_8000_index.html-2Today at the Echo Nest we are pushing out an update to our Genre APIs. The new APIs lets you get all sorts of information about any of over 800 genres including a description of the genre,  representative artists in the genre, similar genres, and links to web resources for the genre (such as a wikipedia page, if one exists for a genre).  You can also use the genres to create various types of playlists.  With these APIs you build all sorts of music exploration apps like Every Noise At Once, Music Popcorn and Genre-A-Day.

The new APIs are quite simple to use. Here are a few python examples created using pyen.

List all of the available genres with a description


import pyen
en = pyen.Pyen()
response = en.get('genre/list', bucket=['description'])
for g in response['genres']:
print g['name'], '-', g['description']

view raw

all_genres.py

hosted with ❤ by GitHub

This outputs text like so:


a cappella – A cappella is singing without instrumental accompaniment. From the Italian for "in the manner of the chapel," a cappella may be performed solo or by a group.
abstract hip hop –
acid house – From house music came acid house, developed in the mid-'80s by Chicago DJs experimenting with the Roland TB-303 synthesizer. That instrument produced the subgenre's signature squelching bass, used to create a hypnotic sound.
acid jazz – Acid jazz, also called club jazz, is a style of jazz that takes cues from a number of genres, including funk, hip-hop, house, and soul.

view raw

genre_list.txt

hosted with ❤ by GitHub

We can get the top artists for any genre like so:


import pyen
import sys
en = pyen.Pyen()
if len(sys.argv) > 1:
genre = ' '.join(sys.argv[1:])
response = en.get('genre/artists', name=genre)
for artist in response['artists']:
print artist['name']
else:
print "usage: python top_artists_for_genre.py genre name"

Here are the top artists for ‘cool jazz’


% python top_artists_for_genre.py cool jazz
Thelonious Monk
Stan Getz
Lee Konitz
The Dave Brubeck Quartet
Bill Evans
Cannonball Adderley
Art Pepper
Charlie Parker
John Coltrane
Gil Evans
Ahmad Jamal
Miles Davis
Horace Silver
Dave Brubeck
Oliver Nelson

We can find similar genres to any genre with this bit of code:


import pyen
import sys
en = pyen.Pyen()
if len(sys.argv) > 1:
genre = ' '.join(sys.argv[1:])
response = en.get('genre/similar', name=genre)
for genre in response['genres']:
print genre['name']
else:
print "usage: python sim_genres.py genre name"

view raw

sim_genres.py

hosted with ❤ by GitHub

Sample output:

% python sim_genres.py cool jazz
bebop
jazz
hard bop
contemporary post-bop
soul jazz
big band
jazz christmas
stride
jazz funk
jazz fusion
avant-garde jazz
free jazz

We can use the genres to create excellent genre playlists. To do so, create a playlist of type ‘genre-radio’ and give the genre name as a seed.  We’ve also added a new parameter called ‘genre_preset’ that, if specified will control the type of songs that will be added to the playlist. You can chose from core, in_rotation, and emerging. Core genre playlists are great for introducing a new listener to the genre.  Here’s a bit of code that generates a core playlist for any genre:


import pyen
import sys
en = pyen.Pyen()
if len(sys.argv) < 2:
print 'Usage: python genre_playlist.py seed genre name'
else:
genre = ' '.join(sys.argv[1:])
response = en.get('playlist/static', type='genre-radio', genre_preset='core-best', genre=genre)
for i, song in enumerate(response['songs']):
print "%d %s by %s" % ((i +1), song['title'], song['artist_name'])

The core classic rock playlist looks like this:

  1. Simple Man by Lynyrd Skynyrd
  2. Born To Be Wild by Steppenwolf
  3. All Along The Watchtower by Jimi Hendrix
  4. Kashmir by Led Zeppelin
  5. Sunshine Of Your Love by Cream
  6. Let’s Work Together by Canned Heat
  7. Gimme Shelter by The Rolling Stones
  8. It’s My Life by The Animals
  9. 30 Days In The Hole by Humble Pie
  10. Midnight Rider by The Allman Brothers Band
  11. The Joker by Steve Miller Band
  12. Fortunate Son by Creedence Clearwater Revival
  13. Black Betty by Ram Jam
  14. Heart Full Of Soul by The Yardbirds
  15. Light My Fire by The Doors

The ‘in rotation’ classic rock playlist looks like this:

  1. Heaven on Earth by Boston
  2. Doom And Gloom by The Rolling Stones
  3. Little Black Submarines by The Black Keys
  4. I Gotsta Get Paid by ZZ Top
  5. Fly Like An Eagle by Steve Miller Band
  6. Blue On Black by Kenny Wayne Shepherd
  7. Driving Towards The Daylight by Joe Bonamassa
  8. When A Blind Man Cries by Deep Purple
  9. Over and Over (Live) by Joe Walsh
  10. The Best Is Yet To Come by Scorpions
  11. World Boss by Gov’t Mule
  12. One Way Out by The Allman Brothers Band
  13. Corned Beef City by Mark Knopfler
  14. Bleeding Heart by Jimi Hendrix
  15. My Sharona by The Knack

While the emerging ‘classic rock’ playlist looks like this:

  1.  If You Were in Love by Boston
  2.  Beggin’ by Shocking Blue
  3.  Speak Now by The Answer
  4.  Mystic Highway by John Fogerty
  5.  Hell Of A Season by The Black Keys
  6.  No Reward by Gov’t Mule
  7.  Pretty Wasted by Tito & Tarantula
  8.  The Battle Of Evermore by Page & Plant
  9.  I Got All You Need by Joe Bonamassa
  10.  What You Gonna Do About Me by Buddy Guy
  11.  I Used To Could by Mark Knopfler
  12. Wrecking Ball by Joe Walsh
  13. The Circle by Black Country Communion
  14. You Could Have Been a Lady by April Wine
  15. 15 Lonely by Walter Trout

The new Genre APIs are really quite fun to use. I’m looking forward to seeing a whole new world of music exploration and discovery apps built around these APIs.

, , , ,

1 Comment