Skip to content

Instantly share code, notes, and snippets.

@bjorne
Last active December 15, 2015 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjorne/2128217f3e5b0904b1d9 to your computer and use it in GitHub Desktop.
Save bjorne/2128217f3e5b0904b1d9 to your computer and use it in GitHub Desktop.
Year in music

Get yer stats

  1. Go to https://yearinmusic.spotify.com/sv-SE
  2. Click "Se ditt year in music"
  3. When you see your first played track, open the developer console (command + alt + i) and paste this snippet:
var what = 'first-track-played my-top-artists my-top-albums my-top-tracks my-top-genres my-listening-minutes my-listening-artists my-listening-tracks'.split(' ');
var data = {};
var s=document.createElement('script'); s.src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js'; 
var done = function() {
  var res = "My Year in Music\n" + data.my_listening_minutes.total_hours + ' hours (+' + data.my_listening_minutes.more_pct + "%)\n" + data.my_listening_tracks.total_tracks + ' songs (+' + data.my_listening_tracks.more_tracks + ') by ' + data.my_listening_artists.total_artists + ' artists (+' + data.my_listening_artists.more_artists + ")\n";
  res += "*Top Tracks:*\n" + data.my_top_tracks.top5.map(function(t) { return '  ' + t.rank + '. ' + t.artist + ' - ' + t.song_title + "\n"; }).join("");
  res += "*Top Albums:*\n" + data.my_top_albums.top5.map(function(t) { return '  ' + t.rank + '. ' + t.artist_name + ' - ' + t.album_name + "\n"; }).join("");
  res += "*Top Artists:*\n" + data.my_top_artists.top5.map(function(t) { return '  ' + t.rank + '. ' + t.artist_name + ' (' + t.song_title + ")\n"; }).join("");
  console.log(res);
};
s.onload=function() {
var next = function(index) {
  var w;
  if (!(w = what[index])) {
    return done();
  }
  jQuery.getJSON('https://yearinmusic.spotify.com/api/app/year-in-music/sv-SE/' + w + '/').done(function(json) {
    data[json.id.replace(/-/g, '_')] = json.model;
    next(index+1);
  });
};
next(0);
};
document.body.appendChild(s);

The code will output a summary of your year in music in textual form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment