Posts Tagged code

Where is my JSpot?

I like Spotify.  I like Java.  So I combined them.  Here’s a Java client for the new Spotify metadata API:  JSpot

This client lets you do things like search for a track by name and get the Spotify ID for the track so you can play the track in Spotify.  This is useful for all sorts of things like building web apps that use Spotify to play music, or perhaps to build a Playdar resolver so you can use Spotify and Playdar together.

Here’s some sample code that prints out the popularity and spotify ID for all versions of Weezer’s  ‘My Name Is Jonas’.

    Spotify spotify = new Spotify();
    Results<Track> results = spotify.searchTrack("Weezer",  "My name is Jonas");
    for (Track track : results.getItems()) { 
       System.out.printf("%.2f %s \n", track.getPopularity(), track.getId());
    }

This prints out:

0.75


0.00


0.09

If you have Spotify and you click on those links, and those tracks are available in your locale you should hear Weezer’s nerd anthem.

You can search for artists, albums and tracks and you can get all sorts of information back such as release dates for albums, countries where the music can be played, track length, popularity for artists, tracks and albums.  It is very much a 0.1 release. The search functionality is complete so its quite useful, but I haven’t implemented the ‘lookup’ methods yet.   There some javadocs.  There’s a jar file: jspot.jar.  And it is all open source: jspot at google code.

, , , ,

3 Comments

Playing with Playdar

On Saturday morning I opened my web browser, built a playlist of a few songs and started to listen to them while I went about my morning computer tasks. Some of the songs in the playlist were on my laptop, while some were on the mac mini in the family room, and some were on a laptop of a friend that was on the other side of the Atlantic ocean. And if my friend in London had closed his laptop before I listened to ‘his’ song on my playlist it could have been replaced by a copy of the song that was on the computer of a friend in Seattle. I had a seamless music listening experience despite the fact that the music was scattered across a handful of computers on two continents. Such is the power of Playdar.
playdar_logo
Playdar is a music content resolver. It is designed to solve one problem: given the name of track, find me a way to listen to it right now. You run Playdar on any computer that you own that has music and Playdar will make it easy to listen to all of that music as if it were on your local machine. The Playdar content resolver can also talk to other Playdar resolvers too, so if Playdar can’t find a track on my local network, it can ask my friend if it knows where the track is, extending my listening reach.

Playdar runs as a web service using standard web protocols for communicating with applications.  When Playdar receives a request to resolve a track it runs through a list of prioritized content resolvers looking for the track. First it checks your local machine, then your local network.  If it hasn’t found it there it could, if so configured, try your friends computers, or even a commercial song resolver (One could imagine for example, a music label offering up a portion of their catalog via a content resolver as a way to expose more listeners to their music).  Playdar will do its best to find a copy of a song that you can listen to now. Playdar enables a number of new listening modes:

  • Listen to my music anywhere – with Playdar, I don’t have to shoehorn my entire music collection onto every computer that I own just so I can listen to it no matter what computer I’m on.  I can distribute my music collection over all my computers – and no matter what computer I’m on I have all my music available.
  • Save money for music streamers – Music streaming services like Last.fm, Spotify and Pandora spend  money for every song that is streamed.  Often times, the listener will already own the song that is being streamed.   Playdar-enabled music streaming services could save streaming costs by playing  a local copy of a song if one is available.
  • Share playlists and mixtapes – with Playdar a friend could give me a playlist (perhaps in a XSPF format) and I could listen to the playlist even if I don’t own all of the songs.
  • Pool the music – At the Echo Nest, everyone has lots of music in their personal collections.  When we are all in the same room it is fun to be able to sample music from each other.  iTunes lets you do this but  searching through 15 separate collections for music in iTunes is burdensome.  With Playdar, all the music on all of the computers running Playdar on your local lan can be available for you to search and play without any of the iTunes awkwardness.
  • Add Play buttons to songs on web pages –  Since Playdar uses standard web protocols, it is possible to query and control Playdar from Javascript – meaning that Playdar functionality can be embedded in any web page.  I could blog about  a song and  sprinkle in a little Javascript to add a ‘play’ button to the song that would use Playdar to find the best way to play the song.  If I write a review about the new Beatles reissue and want the reader to be able to listen to the tracks I’m writing about, I can do that without having to violate Beatles copyrights.  When the reader clicks the play button, Playdar will find the local copy that is already on the reader’s computer.

Playdar’s Marconi Moment

Playdar is the brainchild of RJ, the inventor of the audioscrobbler and one of the founders of Last.fm.  RJ started coding Playdar in March of this year – but a few weeks ago he threw away the 10,000 lines of C++ code and started to rewrite it from scratch in Erlang.  A few days later RJ tweeted I should be taken aside and shot for using C++ for Playdar originally. It’s criminal how much more concise Erlang is for this. Less than 3 weeks after starting from a clean sheet of paper, the new Erlang-based Playdar had its first transatlantic track resolution and streaming. The moment occurred on Friday, October 16th.  Here’s the transcript from the IRC channel (tobyp is Toby Padilla, of MusicMobs and Last.fm fame) when London-based RJ first streamed a track from Toby’s Seattle computer:

[15:40:46] <tobyp> http://www.playdar.org/demos/search.html#artist=pantera&album=&track=burnnn
[15:41:06] <RJ2> woo, transatlantic streaming
[15:41:19] <tobyp> hot!
[15:41:35] <RJ2> playdar’s marconi moment
[15:41:42] <tobyp> hahah

An incredible amount of progress has been made in the last two weeks,  a testament to RJ’s skills as much as Erlang’s expressiveness.  Still, Playdar is not ready for the general public.  It requires a bit of work to install and get running – (yep, the erlang runtime is required), but developer Max Howell has been working on making a user-friendly package to make it easy for anyone to install. Hopefully it won’t be too long before Playdar is ready for the masses.

Even though it is new, there’s already some compelling apps that use Playdar.  One is Playlick:

Playlick

Playlick is a web application, developed by James Wheare that lets you build playlists. It uses Playdar for all music resolution.  Type in the name of an album and Playlick /  Playdar will find the music for you and let you listen to it.  It’s a great way to see/hear the power of Playdar.

Adding custom content resolvers

One of the strengths of Playdar is that it is very easy to add new resolvers.  If you are a music service provider you can create a Playdar content resolver that will serve up your content.    I wrote a content resolver that uses the Echo Nest to resolve tracks using our index of audio that we’ve found on the web.  This resolver can be used as a backstop.  If you can’t find a track on your computer or your friend’s computers the Echo Nest resolver might be able to find a version out there on some music blog.  Of course, the quality and availability of such free-range music is highly variable, so this resolver is a last resort.

Adding a new resolver to Playdar was extremely easy. It took perhaps 30 minutes to write – the hardest part was figuring out git – (thanks to RJ for walking me through the forks, pushes and ssh key settings).    You can see the code here: echonest-resolver.py.  Less than 150 lines of code, half of which is boilerplate.  150 lines and 30 minutes to add a whole new collection of music to the Playdar universe.   Hopefully soon we’ll see resolvers for music streaming services like Napster, Rhapsody and Spotify.

What’s Next for Playdar?

Playdar is new – and the plumbing and wiring are still be worked on – but already it is doing something pretty magical – letting me listen to any track I want to right now.  I can see how Playdar could be extended into acting as my music agent.  Over time, my Playdar servers will get to know quite a bit about my music tastes.  They’ll know what music I like to listen to, and when I like to listen to it.   Perhaps someday, instead of asking Playdar to resolve a specific track by name, I’ll just be able to ask Playdar to give me a playlist of new music that I might like.  Playdar can then use an Echo Nest, Last.fm or an AMG playlister to build a playlist of interesting, relevant new music.  Playdar won’t just be a music resolver, Playdar will be my music agent helping me explore for and discover new music.

, , , , ,

7 Comments

Updated Java client for the Echo Nest API

We’ve pushed out a new version of the open source Java client for the Echo Nest API.    The new version provides support for the different versions of the Echo Nest analyzer.  You can use the traditional,  but somewhat temperamental version 1 of the analyzer, or the spiffy new, ultra-stable version 3 of the analyzer.  By default, the Java client uses the new analyzer version, but if you need your application to work the exactly the same way that it did six months ago you can always use the older version.

Here’s a bit of Java code that will print out the tempo of all the songs in a directory:

void showBPMS(File dir) throws EchoNestException {
     TrackAPI trackAPI = new TrackAPI();
     File[] files = dir.listFiles();
     for (File f : files) {
         if (f.getAbsolutePath().toLowerCase().endsWith(".mp3")) {
             String id = trackAPI.uploadTrack(f, true);
             System.out.printf("Tempo 6%.3f %s\n",
                 trackAPI.getTempo(id).getValue(), f.getAbsoluteFile());
         }
     }
}

Running this code on a folder containing the new Breaking Benjamin album yields this output:

Tempo  85.57 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/01 - Fade Away.mp3
Tempo 108.01 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/02 - I Will Not Bow.mp3
Tempo 168.81 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/03 - Crawl.mp3
Tempo 156.75 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/04 - Give Me A Sign.mp3
Tempo  85.51 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/05 - Hopeless.mp3
Tempo  68.34 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/06 - What Lies Beneath.mp3
Tempo 116.94 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/07 - Anthem Of The Angels.mp3
Tempo  85.50 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/08 - Lights Out.mp3
Tempo 125.77 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/09 - Dear Agony.mp3
Tempo  94.99 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/10 - Into The Nothing.mp3
Tempo 160.38 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/11 - Without You.mp3

You can download the new Java client from the echo-nest-java-api code repository.  The new version is: echo-nest-java-api-1.2.zip

, , , , ,

Leave a comment

Artist radio in 10 lines of code

Last week we released Pyechonest, a Python library for the Echo Nest API.  Pyechonest gives the Python programmer access to the entire Echo Nest API including artist and track level methods.  Now after 9 years working at Sun Microsystems, I am a diehard Java programmer, but I must say that I really enjoy the nimbleness and expressiveness of Python.  It’s fun to write little Python programs that do the exact same thing as big Java programs.  For example, I wrote an artist radio program in Python that, given a seed artist, generates a playlist of tracks by wandering around the artists in the neighborhood of the seed artists and gathering audio tracks.   With Pyechonest, the core logic is 10 lines of code:

def wander(band, max=10):
   played = []
   while max:
     if band.audio():
         audio = random.choice(band.audio())
         if audio['url'] not in played:
             play(audio)
             played.append(audio['url'])
             max -= 1
     band = random.choice(band.similar())

(You can see/grab the full code with all the boiler plate in the SVN repository)

This method takes a seed artist (band) and selects a random track from set of audio that The Echo Nest has found on the web for that artist, and if we haven’t already played it, then do so. Then we select a near neighbor to the seed artist and do it all again until we’ve  played the desired number of songs.

For such a simple bit of code, the playlists generated are surprisingly good..Here are a few examples:

Seed Artist:  Led Zeppelin:

(I think the Dale Hawkins version of Susie-Q after  CCR’s Fortunate Son  is just brilliant)

Seed Artist: The Decemberists:

(Note that audio for these examples is audio found on the web – and just like anything on the web the audio could go away at any time)

I think these artist-radio style playlists rival just about anything you can find on current Internet radio sites – which ain’t to0 bad for 10 lines of code.

, , , , , ,

9 Comments

The Echo Nest Cocoa Framework

Kamel Makhloufi (aka melka) has created a Cocoa Framework for the Echo Nest and has released it as open source.  This framework makes it easy for Mac developers (and presumable iPhone and iTouch developers) to use the Echo Nest API services.  Kamel’s goal is to build an application similar to Audiosurf (a music-adapting puzzle racer that uses your own music), but along the way Kamel realized his framework may be useful to others and so he has released it for all of us to use.

The Framework supports all of the Track/Analysis methods of the API including Track Upload, getting tempos, duration, bar, beat and tatum info as well as detailed segment information.  On Melka’s TODO list is to add the Echo Nest artist methods.

Using the framework, Melka created a nifty track visualization tool that will render a colorful representation of the Echo Nest analysis for a track:

Kamel implemented this in about 300 lines of Objective-C code.

The Echo Nest Cocoa Framework is released under a GPL V3 license and is hosted on google code at:  http://code.google.com/p/echonestcocoaframework/.

The release is just in time for Music Hackday – I’m hoping we see an iPhone app or two emerge from this event that use the Echo Nest APIs! Kamel’s framework is just the thing to make it happen

, , , , , ,

Leave a comment

79 Versions of Popcorn, remixed.

Aaron Meyer’s issued a challenge for someone to remix 79 versions of the song Popcorn.   So I  fired up one of  the remix applications that Tristan and Brian wrote a while back  that uses our remix API to stitch all 79 versions of Popcorn together into one 12 minute track – songs are beat matched, tempos are stretched and beats are aligned to form a single seamless (well, almost seamless) version of the Hot Buttered classic.    I’m interested to hear what some of the other  computational remixologists could do with this challenge.  Everyone, stop writing your thesis, and make some popcorn!

Listen:

DownloadA Kettle of Echo Nest Popcorn.

If you are interested in creating your own remix, check out the Echo Nest API and the Echo Nest Remix SDK. (Thanks Andy, for the tip!).

, , ,

15 Comments

track upload sample code

One of the biggest pain points users have with the Echo Nest developer API is with the track upload method.  This method lets  you upload a track for analysis (which can be subsequently retrieved by a number of other API method calls such as get_beats, get_key, get_loudness and so on).   The track upload, unlike all of the other of The Echo Nest methods requires you to construct a multipart/form-data post request. Since I get a lot of questions about track upload I decided that I needed to actually code my own to get a full understanding of how to do it – so that (1) I could answer detailed questions about the process and (2) point to my code as an example of how to do it.   I could have used a library (such as the Jakarta http client library) to do the heavy lifting but I wouldn’t have learned a thing nor would I have some code to point people at.  So I wrote some Java code (part of the forthcoming Java Client for the Echo Nest web services) that will do the upload.

You can take a look at this post method in its google-code repository. The tricky bits about the multipart/form-data post is getting the multip-part form boundaries just right.  There’s a little dance one has to do with the proper carriage returns and linefeeds, and double-dash prefixes and double-dash suffixes and random boundary strings.  Debugging can be a pain in the neck too, because if you get it wrong,  typically the only diagnostic one gets is a ‘500 error’ which means something bad happened.

Track upload can also be a pain in the neck because you need to wait 10 or 20 seconds for the track upload to finish and for the track analysis to complete.  This time can be quite problematic if you have thousands of tracks to analyze.  20 seconds * one thousand tracks is about 8 hours.  No one wants to wait that long to analyze a music collection.  However, it is possible to short circuit this analysis.  You can skip the upload entirely if we already have performed an analysis on your track of interest.   To see if an analysis of a track is already available you can perform a query such as ‘get_duration’ using the MD5 hash of the audio file.  If you get a result back then we’ve already done the analysis and you can skip the upload and just use the MD5 hash of your track as the ID for all of your queries.   With all of the apps out there using the track analysis API, (for instance, in just a week, donkdj has already analyzed over 30K tracks) our database of pre-cooked analyses is getting quite large – soon I suspect that you won’t need to perform an upload of most tracks (certainly not mainstream tracks). We will already have the data.

, , , ,

7 Comments