Archive for category code

Wicked smart playlists

Over the past few weekends I’ve been working on a little side project called the Playlist Builder Library (or PBL for short). The Playlist Builder Library is a Python library for creating and manipulating playlists. It’s sort of like remix for playlists. With PBL you can take songs from playlists, albums, artists, genres and flexibly combined them,  rearrange them, filter them and sort them into new playlists.

For example, here’s a PBL program that creates radio station of today’s top hits but guarantees that every 4th song is either by Sia or Katy Perry:

[gist https://gist.github.com/plamere/2fa839150815f040450d]

Here’s the resulting playlist:

[spotify spotify:user:plamere:playlist:6TIeQMve7pVBLCAY8WUX3L]

That’s 5 lines a code to create a non-trivial playlist.

PBL supports all sorts of sources for tracks such as Spotify playlists, top tracks from artists,  albums, genres, the extremely flexible and powerful Echo Nest playlisting API. These sources can be manipulated in all sorts of interesting ways.  Here are a couple more examples:

You can filter all the songs in ‘Your favorite coffeehouse’ to get just the lowest energy songs:

coffee = PlaylistSource('coffeehouse', ucoffee_house) 
low_energy_coffee = AttributeRangeFilter(coffee, 'echonest.energy', max_val=.5)

You an combine your favorite playlists in a single one:

playlist_names = ['Your Favorite Coffeehouse', 'Acoustic Summer','Acoustic Covers', 'Rainy Day']
all = DeDup(Alternate([Sample(PlaylistSource(n), 10) for n in playlist_names]))

Even sophisticated tasks are really easy. For instance, imagine dad is on a roadtrip with daughter. They agree to alternate between dad’s music and daughter’s music. Dad is selfish, so he makes a playlist that alternates the longest cool jazz tracks with the shortest teen party playlists with this 3 line script:

teen_party = First(Sorter(PlaylistSource('Teen Party'), 'duration'), 10) 

jazz_classics = Last(Sorter(PlaylistSource('Jazz Classics'), 'duration'), 10) 

both = Alternate([teen_party, Reverse(jazz_classics)])

Here’s the result

[spotify spotify:user:plamere:playlist:0VKGTR6eCPe55bBjezi5z3]

Note that the average duration of Teen Party songs is much less than 3 minutes, while the average duration of Jazz Classics is above 6 minutes. Selfish dad gets to listen to his music twice as long with this jazz-skewing playlist.

There’s a whole lot of nifty things that can be done with PBL.  If you are a Python programmer with an itch for creating new playlists check it out.  The docs are online at http://pbl.readthedocs.org/ and the source is at https://github.com/plamere/pbl.

PBL is pretty modular so it is easy to add new sources and manipulators, so if you have an idea or two for changes let me know or just send me a pull request.

, ,

1 Comment

The Drop Machine

I spent last weekend in Cannes, participating in the MIDEM Hack Day – an event where music hackers from around the globe gather to hack on music. My hack is called The Drop Machine.  It is a toy web app that plays nothing but the drops.  Here’s a video demo of it:

[youtube http://youtu.be/4C6a-MqAF_A]

The interesting bit in this hack is how The Drop Machine finds the drops.  I’ve tried a number of different ways to find the drops in the past – for instance, the app Where’s the Drama found the most dramatic bits of music based on changes in music dynamics. This did a pretty good job of finding the epic builds in certain kinds of music, but it wasn’t a very reliable drop detector. The Drop Machine takes a very different approach – it crowd sources the finding of the drop. And it turns out, the crowd knows exactly where the drop is.  So how do we crowd source finding the drop? Well, every time you scrub your music player to play a particular bit of music on Spotify, that scrubbing is anonymously logged. If you scrub to the chorus or the guitar solo or the epic drop, it is noted in the logs. When one person scrubs to a particular point in a song, we learn a tiny bit about how that person feels about that part of the song – perhaps they like it more than the part that they are skipping over  – or perhaps they are trying to learn the lyrics or the guitar fingering for that part of the song. Who’s to say? On an individual level, this data wouldn’t mean much. The cool part comes from the anonymous aggregate behavior of millions of listeners, from which a really detailed map of the song emerges.  People scrub to just before the best parts of the song to listen to them.  Let’s take a look at a few examples.

For starters here’s a plot that shows the most listened to part of the song In the Air Tonight by Phil Collins based upon scrubbing behavior:

2015-06-09 at 6.58 AM

The prominent peak at 3:40 is the point when the drums come in.  Based upon scrubbing behavior alone, we are able to find arguably the most interesting bit of that song.

Here’s another example – Whole Lotta Love by Led Zeppelin:

2015-06-09 at 7.02 AM

The trough at 1:40 corresponds to the psychedelic bits while the peak at 3:20 is the guitar solo. Again, by looking at scrubbing behavior we get a really good indication of what parts of a song listeners enjoy the most.

When we look at scrubbing behavior for dance music, especially dubstep and brostep, we see a very characteristic strong peak, usually at around a minute into the song. This is invariably ‘the drop’. Here are some examples:

2015-06-09 at 7.05 AM

 

 

 

2015-06-09 at 7.08 AM

 

 

 

2015-06-09 at 7.09 AM

The scrubbing behavior not only shows us where the drop is, but it also shows us how intense the drop is – drops with lots of appeal get lots of attention (and lots of scrubs) while songs with milder drops get less attention. Here’s a milder drop by Skrillex:

 

 

2015-06-09 at 7.14 AM

Compare that to the much more intense drop:

2015-06-09 at 7.15 AM

Songs with more intense drops have more prominent scrubbing and listening peaks at the drop than others.  The Drop Machine uses the prominence of the peak at the drop to find the songs with the most intense drops.

Putting it all together, the Drop Machine searches through the most popular dance, dubstep and brostep tracks and finds the ones with the most prominent listening peaks based upon scrubbing behavior. It then surfaces these tracks into a playlist, and then plays 10 seconds of each track centered around the drop. The result is non-stop drop. Add in a bit of animation synchronized to the music and that’s the Drop Machine.

Currently, the Drop Machine is an internal-use only hack, I’m working on making a public version, so hopefully the world won’t have to wait too long before you all can listen to the Drop Machine.

,

4 Comments

50 Years Ago in Music

There’s a strong connection between music and memory. Whenever I here the song Lovin You by Minnie Riperton, I’m instantly transported back to 1975 when I spent the summer apprenticed to Tom, my future brother-in-law, fixing electronic organs. I was 15, Tom was 22 and super cool. He had a business (New Hampshire Organ Service) and he had a van with an 8-track player and an FM radio (a rarity in 1975). As we drove between repairs across rural New Hampshire we’d pass the time by listening to the radio.  Now, when I hear those radio songs from 1975 it is like I’m sitting in that van again.

Music can be like a time machine.  Transporting us to different times in our lives. I was interested in exploring this a bit more. Inspired by @realtimewwii which gives a day-by-day account of World War II, I created a set of dynamically updating Spotify playlists that follow the charts week-by-week.

For example there’s the 50 Years Ago in Music playlist that contains the top 100 or songs that were on the chart 50 years ago.  As I write this on April 12, 2015, this playlist is showing the top songs for the week of April 12, 1965.

The music on this playlist sends me back to when I was 5 years old listening to music on our AM radio in the kitchen in the morning while eating breakfast.

If you follow this playlist you’ll be able to re-create what it was like to listen to music 50 years ago.  If the mid-sixties doesn’t speak to you musically, there are some other playlists that you can try.

There’s 40 Years Ago in Music that brings me back to 1975 on the road with Tom.

There’s 30 years Ago in Music which is currently playing music from the mid-80s like Madonna and Phil Collins.

There’s 20 Years Ago in Music currently playing music from the mid-90s:

10 Years Ago in Music plays the music that was on the radio when Spotify was just a gleam in Daniel’s eye.

5 Years Ago in Music – the playlist of @echonest in its heyday.

All of the playlists update weekly on Monday. If you’d like a reminder about when they are updated you can follow @50yearmusic. And of course, the code is on github.

, , , ,

1 Comment

The Playlist Miner

The Spotify Web API team pushed out a new feature recently that extends the search API to include playlist search. With this new feature it is now possible to search across all of the popular public playlists created by Spotify users. To try out the new search capability I created a new web app called The Playlist Miner.

The Playlist Miner is a web app that will create a Spotify playlist for you by finding the top songs in all of the playlists that match your criteria. Say, for example, that I want to create a dinner party playlist.  First, I find the top playlists that match ‘dinner party’ with The Playlist Miner:

The_Playlist_Miner

 

The Playlist Miner will find up to the top 1,000 most popular playlists that match dinner party. It shows them to me, giving me a chance to refine my query to focus in on the exact type of playlist that I am interested in.

 

The_Playlist_Miner

 

For this first try, I see lots of Christmas-oriented playlists (‘Tis the Season after all), but since I’m looking for music for a post-holiday dinner party, I’d rather not have holiday music in the playlist. So I refine my query to find non-Christmas oriented dinner party playlists like so:

 

The_Playlist_Miner

 

The resulting playlists are suitably non-Christmasy.

 

The_Playlist_Miner

I like the look of these playlists so I hit the Find Top Tracks button and The Playlist Miner will scour through all of the matching playlists (290 of them in this case) and find the most frequently appearing tracks.

The_Playlist_Miner

Once the top 100 tracks are found, I can save them to Spotify as my own playlist.

Selecting Prefer more distinctive labor and delivery tracks adjusts the track order for popularity so that tracks that are more distinctive to the particular playlist context will rise to the top. You can also use logical operators to focus in on the exact type of playlist you want to. You can search for “work out” OR workout NOT running  to find workout playlists without running in their titles/descriptions.

Under the hood – The Playlist Miner uses lots of bits of the Spotify API – user authentication, playlist search, playlist reading, playlist saving and more. The app is a an API calling beast – aggregating all the tracks from a thousand playlists requires 1,000 API calls. It’s a testament to the Spotify Web API that it doesn’t even blink under the load.  You can play with the code on github.

It’s fun to use The Playlist Miner to explore the quirkier aspects of how people listen to music. There are ironing playlists and sleeping baby playlists. There are playlists for getting psyched and playlists for Labor and Delivery.  With the Playlist Miner you can pull from all the playlists created for a particular purpose and build your own.  Give it a try.

, ,

1 Comment

‘Tis the Season

‘Tis the season for artists to release Christmas music … and they release lots of it. In the last two weeks Spotify has added thousands of releases with ‘Christmas’ in the title.   I though it would be fun to build a little web app that lets you explore through all the releases.  Here it is: ‘Tis the Season.

_Tis_the_season

It shows you all the Christmas albums that have been released in the last few weeks, lets you listen to them and lets you open them in Spotify.

It makes use of the Spotify Web API – there’s a nifty search feature that lets you restrict album searches to albums that have just been recently release. That’s what makes this app possible.  Check out the app at ‘Tis the Season. The source is on github.

Leave a comment

Tracking play coverage in the Infinite Jukebox

Yesterday, I upgraded the Infinite Jukebox to make it less likely that it would get stuck in a section of the song. As part of this work, I needed an easy way to see the play coverage in the song. To do so, I updated the Infinite Jukebox visualization so that it directly shows play coverage. With this update, the height of any beat in the visualization is proportional to how often that beat has been played relative to the other beats in the song. Beats that have been played more have taller bars in the visualization.

This makes it easy to see if we’ve improved play coverage. For example, here’s the visualization of Radiohead’s Karma Police with the old play algorithm after about an hour of play:
Infinite_Jukebox_for_Karma_Police_by_Radiohead

As you can see, there’s quite a bit of bunching up of plays in the third quarter of the song (from about 7 o’clock to 10 o’clock). Now compare that to the visualization of the new algorithm:

Infinite_Jukebox_for_Karma_Police_by_Radiohead

With the new algorithm, there’s much less bunching of play. Play is much more evenly distributed across the whole song.

Here’s another example.  The song First of the Year (Equinox) by Skrillex played for about seven hours with the old algorithm:

Infinite_Jukebox_for_Equinox_by_Skrillex

As you can see, it has quite uneven coverage. Note the intro and outro of the song are almost always the least played of any song, since those parts of the song typically have very little similarity with the rest of the song.

Here’s the same song with the new algorithm:

Infinite_Jukebox_for_Equinox_by_Skrillex

Again, play coverage is much more even across all of the song outside of the intro and the outro.

I like this play coverage visualization so much that I’ve now made it part of the standard Infinite Jukebox. Now as you play a song in the Jukebox, you’ll get to see the song coverage map as well. Give it a try and let me know what you think.

, , ,

3 Comments

Infinite Jukebox improved

It has been over two years since the Infinite Jukebox was first released after Music Hack Day Boston 2012.  Since then millions of people have spent nearly a million hours listening to infinite versions of their favorite songs. It has been my most popular hack.

There has always been a problem with the Infinite Jukebox. Certain songs have sections with very dense interconnections. For these songs the Infinite Jukebox would sometimes get stuck playing the same section of the song for many minutes or hours before breaking free.  This morning I finally sat down and worked out a good way to deal with this problem. The Infinite Jukebox will now try to steer the song toward the beats that have been played the least. When the jukebox is deciding which beat to play next, it will search through all the possible future paths up to five beats into the future to find the path that brings the jukebox to the least played part of the song.  The result is that we exit out of the rats nest of connections rather quickly.  The code is quite succinct – just 20 lines in one recursive function.  Good payback for such a small amount of code.

Infinite_Jukebox_for_Turn_Down_by_Rittz

While I was in the codebase, I made a few other minor changes. I switched around the color palettes to favor more green and blue colors, and I use a different color to draw the beat connections when we make a jump.

1 Comment

More on “Where’s the Drama?”

My Music Hack Day Berlin hack was “Where’s the Drama?” – a web app that automatically identifies the most dramatic moment in any song and plays it for you. I’ve been having lots of fun playing with it … and even though (or perhaps because) I know how it works, I’m often surprised at how well it does at finding the most dramatic moments.  Here are some examples:

How does it work? The app grabs the detailed audio analysis for the song from The Echo Nest.  This includes a detailed loudness map of the song. This is the data I use to find the drama.  To do so, I look for the part of the song with the largest rise in volume over the course of a 30 second window (longer songs can have a bit of a longer dramatic window). I give extra weight to crescendos that culminate in louder peaks (so if there are two crescendos that are 20dB in range but one ends at 5dB louder, it will win). Once I identify the most dynamic part of a song, I pad it a bit (so we get to hear a bit of the drop after the build).

The rest is just UI – the song gets plotted as a heavily filtered loudness curve with the dramatic passage highlighted. I plot things with Highcharts, which is a pretty nifty javascript plotting and charting library. I recommend.

 Where_is_the_Drama_

Playing the music – I wanted to use Spotify to play the music, which was a bit problematic since there currently isn’t a way to play full streams with the Spotify Web API, so I did a couple of hacky hacks that got me pretty far. First of all, I discovered that you can add a time offset to a Spotify URI like so:

        

When this URI is opened in Spotify (even when opened via a browser), Spotify will start to play the song a the 1:05 time offset.  

I still needed to be able to stop playing the track – and there’s no way to do that directly – so instead, I just open the URI:

      

which happens to be the URI for John Cage’s 4’33.  In other words, to stop playing one track, I just start playing another (that happens to be silent).  The awesome side effect of this is that I’ll be slowly turning anyone who uses “Where’s the Drama?” into experimental music listeners as the Spotify recommendation system responds to all of those John Cage ‘plays’. This should win some sort of ‘hackiest hack of the year’ award.

It was a fun hack to make, and great fun to demo. And now that I have the app, I am no longer wasting time listening to song intros and outros, I can just get to the bit of the song that matters the most. 

, , , , , ,

3 Comments

Acrostify – make Spotify playlists with embedded secret messages

For my summer vacation early-morning coding for fun project I revamped my old Acrostic Playlist Maker to work with Spotify.  The app, called Acrostify, will generate acrostic playlists with the first letter of each song in the playlist spelling out a secret message.  With the app, you can create acrostic playlists and save them to Spotify.

 

Screen Shot 2014-08-07 at 6.38.41 AM

The app was built using The Echo Nest and Spotify APIs. The source is on github.

Give it a try at Acrostify.

 

,

1 Comment

Outside Lands Recommendations

I am at Outside Hacks this weekend – A hackathon associated with the Outside Lands music festival. For this hack I thought it would be fun to try out the brand new Your Music Library endpoints in the Spotify Web API. These endpoints let you inspect and manipulate the tracks that a user has saved to their music. Since the hackathon is all about building apps for a music festival, it seems natural to create a web app that gives you festival artist recommendations based upon your Spotify saved tracks. The result is the Outside Lands Recommender:

 

Your_Outside_Lands_Festival_Recommendations

 

The Recommender works by pulling in all the saved tracks from your Spotify ‘Your Music’ collection, aggregating the artists and then using the Echo Nest Artist Similar API to find festival artists that match or are similar to those artists. The Spotify API is then used to retrieve artist images and audio samples for the recommendations where they are presented in all of their bootstrap glory.

This was a pretty straight forward app, which was good since I only had about half the normal hacking time for a weekend hackathon. I spent the other half of the time building a festival dataset for hackers to use (as well as answering lots of questions about both the Spotify and Echo Nest APIs).

It has been a very fun hackathon. It is extremely well organized, the Weebly location is fantastic, and the quality of hackers is very high. I’ve already seen some fantastic looking hacks and we are still a few hours from demo time.  Plus, this happened.

Screenshot_7_27_14__12_32_PM

Two more victims

,

Leave a comment