I made lastfm to csv - a page for downloading lastfm listening data as a csv file. API requests are made directly from the browser, avoiding the need for any server-side code.
give it a shot now (my username is benjaminf)
My friend Andy wanted some lastfm listening data for a visualisation project so I wrote him a ruby script that uses the user.getrecenttracks method to get the track history for a user. This worked fine though if someone else wanted to use it - they would need to install ruby, and have a familiarity of the command line.
I figured it might be easier for people to do this in the browser - so I put together lastfm-to-csv, which lets you enter a username and download a csv file containing all the tracks for a user.
Using the browser
Generating a csv of all the tracks requires many requests to the api, these need to be processed and combined together. I decided to do this all from the browser, by using xhr to make requests to the api and storing the processed csv data in a javascript Blob.
A few libraries that I found useful:
- reqwest - for making xhr calls, nice and lightweight.
- async - for organising the calls to the api and processing the results.
- Filesaver.js - lets you download the resulting Blob objects as a file.
A few things I noticed by doing it this way:
- people have access to their data instantly - no waiting around for a file to be generated on the server before downloading it.
- no servers to keep running - all code runs in the browser
- harder to avoid api limiting - it someone gathers data in several windows, they could get rate limited.
- potential access issues. Last fm gives you access to a nice cors endpoint, though that’s not always the case with other apis.
Andy blogged about his awesome last fm visualisations, you should check them out - turns out that I’m quite obsessive.