taking notes about what you are listening to on last.fm: the hacky way

September 17th, 2007 español

Some time ago, I wondered how could I take some notes about the music I was listening to.

After having a look at the last.fm player source code* I instantly saw what a stupid thing I had suggested. In no way I’d be able to figure out that bunch of c++ classes (not that it made any sense to try, just to implement such a simple thing).

I thought of some other alternatives, mostly involving desktop widgets, but as far as I could see, none of the options could cover both my local music and the last.fm player (for when I’m listening to radio). I gave up the idea.

But one day, while sending a recommendation to a friend via the player I realized that I could write some text in that text box. Could I send recommendations to myself? Yes. And how could I take those recommendations out of last.fm? Luckily, they offer an rss feed for manual recommendations in their web services.

auto recommendation on last.fm

So I hacked together some code that parsed my recommendations and sent the ones with my username to my helipad notebook (not public, so I don’t have much to show). I set up a cron job and… You can see that I still use it in my rss feed.

The code is so trivial (and so tied to helipad in my case) that I’m sure you can do it better quickly, but in case you are interested, I could try to clean some of the php mess and send it upon request.

Although they are kind of personal, I’ve been thinking of publishing the notes directly here, since the rss feed is public anyway (and explicit sharing can improve your personal content, I think)

As a side note, I think last.fm could get some value of implementing such a thing. On one hand users could get some sort of musical microblogging, like a contextual twitter. On the other hand, since the info is always from last.fm, it could really enrich artists, songs and album pages, and more seamlesly than the current shoutbox, in my humble opinion.

* yes, I learned how to use subversion. Now I can’t live without it.

tags:

php and mysql in different time zones

April 13th, 2007 español

Just a quick code tip for working with dates in mysql and php.

I’m building a script to regularly mirror my last.fm recent tracks to a mysql database of my own. I’m interested in experimenting with daily and hourly statistics.

One problem that has taken me some head scratching has been the fact that the last.fm recentracks web service gives me the date a given track was played in a timestamp of my current timezone (+02:00 , Europe/Paris, as I’ve just learnt), but my web server is on a different timezone (-05:00, America/Los_Angeles), so when I try to insert a date in the database, even though I’m giving it a timestamp, it gets interpreted as being 7 hours less than it actually is. So a track played at let’s say 31 Mar 2007, 23:55 would be stored as having been played at 31 Mar 2007, 16:55. Not good.

Not wanting to fiddle with configurations or anything beyond my knowledge, I discovered that I could set the timezone in both php and mysql for a given script or db query.

Setting the timezone in php

If you want to know which timezone your server is in, you can guess it with


date_default_timezone_get();

Which should give you a string like “America/Los_Angeles” or any other of the supported timezones list

If it is different than your desired timezone, look for the one you want in the list and before doing any time operation, call:


// set your timezone as gmt +02:00
date_default_timezone_set("Europe/Paris");

From then on, all your php code should understand timestamps and dates in that timezone.

Then for mysql use CONVERT_TZ

Even though it is corrected in php, you’ll have to do it also when inserting information on you mysql db, because it will interpret timestamps again in its time zone. You can guess which is it by having a look at the system time zone variable.

In my case, after trying some hacky alternatives I discovered CONVERT_TZ in one of the latest comments in this post

From the mysql manual


CONVERT_TZ(dt,from_tz,to_tz)

CONVERT_TZ() converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value.

You have to pass it the timestamp, current timezone (’SYSTEM’ is the server time zone) and target timezone and it happily converts between them.

So now my query would look like this:


$query = "INSERT INTO recenttracks (artist, name, url, date, type)
	VALUES ( '$lastFmTrack->artist',
	'$lastFmTrack->name',
	'$lastFmTrack->url',
	CONVERT_TZ(FROM_UNIXTIME(’$lastFmTrack->playDate’), ‘SYSTEM’, ‘+02:00′), 
	‘$lastFmTrack->type’)”;


Basically that’s it. Hope it is useful for someone.

Mind you, I’m nothing of an expert in php or mysql, this is just a method which worked for me. Corrections are welcome.

tags:

Music and memory: A small (frustrated) last.fm project

January 30th, 2007 español

Antecedent:

A couple of months ago, having a look at some old stats in my last.fm profile, I realised how much I could remember a given time by just seeing the music I used to listen to (that old (unfinished?) project by marcos weskamp and didier hilhorst came to mind inmediately).

The source:

Last.fm keeps weekly data about what we listen to. We also can (could) construct a radio link based on various artists. For example:

lastfm://artist/bibio/similarartists

The application

A web page that, given some artists that I used to listen to in a given time (e.g: december 2005), constructs the url of a last.fm radio with those bands, so I can somehow “transport” myself to that time by listening to similar music…

And I’ve done it, but…

Last friday, the multiple artists station feature stopped working. In fact, I had some suspicion, but I thought that… nothing. I didn’t think of it and kept working.

So it is basically useless in its actual form, but it was finished (as a proof of concept, at least), so here it is:

Last.fm time machine (if it had worked i’d have looked for a better name).

I’m not sure if the idea can take another direction to become useful. I’ve thought of having a look at xspf to see if I can generate playlists instead of radios, but by now I don’t really know. If you have any ideas…

At the very least, it’s been useful to clean the dust over my php, use the last.fm webservices, a little bit of ajax (thanks mr.sofa naranja) and above all, to finish something.

By the way, avidos let me stay in their hosting to do some tests while mine hadn’t php5, and ignasi tudela tried to help me with the design, but apart from using Georgia and taking his colors for the different seasons, I didn’t pay him much (deserved) attention, and you can see the results. Thanks to both.

tags:

wouldn’t it be nice if…

January 14th, 2007 español

…you could take some notes about the songs you are listening directly on the last.fm player?

Nothing too fancy. Something similar to the delicious notes would be ok.

By now I’m using a tag (toresearch) for discovered artists, and sometimes I take notes on my helipad, but adding them right on the player would save some work, and definitely add richer information than just tags to help you keep track of good discovered artists, special songs… They shouldn’t be necessarily public (although they could).

This could make a good project for hacking the available source code for the last.fm player (mental note: learn subversion)

Yes, more last.fm. I can’t get it out of my head.

tags:

Song tags in (and two slight disappointments with) last.fm

January 11th, 2007 español

I’m always amazed at the use of tags in last.fm, specially for songs.

Some random examples I’ve seen lately:

What I love is the interpretations they suggest. And most of the times you can understand what the tag means listening to the song.

And then two things I don’t like about the last (otherwise great) last.fm player update (1.1.0.0):

  1. As far as I know, I can no longer see this information (tags for the currently playing song) directly in the player. That was, as you’ve seen, a good source of joy
  2. You can no longer construct a multiple artist radio either in the web or the radio player. I cannot see a reason for this, as you can still do it with a url (Note: this link will try to open your last.fm player, if you have one, and will tune in a radio based on all the artists mentioned in this post). Hope they are not deprecating this feature, as I have something soon to release based on that
tags:

Suggestive errors

December 15th, 2006 español

Beans (the one i know) is a hip hop mc, formerly a member of the great Antipop Consortium.
Beans

(The) Beans are a canadian post rock band, which I didn’t know before. They’re good if you’re into do make say think and bands like that.
Foto del grupo de post rock The Beans

It seems like last.fm is not so sure about that difference, as they give credit for Tired Snow (a recent record by The Beans) to Beans, the mc.

But far from annoying me, it gave me a magic moment yesterday when I was recommended Miko, a song from that record. I spent the whole three minutes waiting to hear how the abstract avant garde rap of the former would fit with the canadian instrumental post rock of the latter.

Still thinking…

tags:

Maintenance finished: New features

September 23rd, 2006 español

I’ve finished (at least for today) tweaking the blog. Some new features:

  • Two languages: From now on, i can provide posts in both spanish and english. Thanks to the polyglot plugin, users in either language will only see the post in its own language (which will be decided by the default language in your web browser). You can also grab rss feeds of both languages (see the footer of the page). If you are already subscribed to the blog, you will be receiving the english version. If you prefer the spanish one, subscribe to the rss en español. This doesn’t mean i will be posting everything in both languages, but i’ll try to do my best.
  • Tags: Now you can see tags at the end of each post and navigate using them. You can also see a fashionable tag cloud in the sidebar. Plugin: Ultimate tag warrior
  • Weekly favourite artists: You can also see a nice list of the musicians that have kept better care of my ears during the last week, as provided by last.fm and the scrobbler plugin
  • Permalinks: better url readability

There are still some things to do, like translating categories and adding (removing) some csstyling. But that’s pretty much it for now. Please, let me know any errors, comments…

*Nota: si ves esto a través de un lector de rss y quieres ver la entrada en castellano, ven al site.

tags: