Last.fm activity now in Complexlife

Last.fm is one of the top, if not the best music service out there and it’s something I’ve been using for quite a while now. While last.fm includes things like groups, friends, forums and other aspects of a social network, your activities in these was never provided. In the latest version these activities (new friends, loved songs etc) were shown in the form of a little block in the sidebar but unfortunately there has been no way to grab that for use in Complexlife.

I knew there is a way to get these activities somehow as Friendfeed does show you when you love a track but having asked directly about it in the forum, I was told that getting this in a feed was just not an option.

Fortunately web-mastered stepped up and created a yahoo pipe which grabs the last.fm latest activities API and returns it as a feed. Very useful but unfrotunately I noticed that it wasn’t exactly in the format I needed. If I used that in Complexlife then you would only see the title (a generic “New activity from <username>”) and having no date info in the feed, b0rked the sort by date of Simplepie.

Thus I had to modify the pipe in a way that

  1. Made the content become the title of the post (removing any html which might break Complexlife)
  2. Provide the date in the RSS so that the item can be sorted

Creating the title

It took me a while to figure it out, but making the content become the title was the easiest part of it all. Since yahoo pipes provides a handy renaming function, all I needed to do is tell it to rename the content as the title

Renaming the content as Title
Renaming the content as Title

The first part copies the whole content as the date field. I will later use this get the date. The second part renames the current content to the title so that it is displayed in whole. If I didn’t do it, I would get only part of the content displayed with elipsis after 30 characters or so.

Now I need to remove all the html code the activity stream has in. As it includes links to my profile as well as to artists and tracks, this would break the link complexlife puts for each row. The only way to remove the unecessary parts is of course through regular expressions and yahoo pipes gives exactly that function.

Removing the unecessary parts from the content
Removing the unnecessary parts from the content

This part actually goes before the renaming/copying as I remove various parts I also don’t need from the date field. Thus when I copy, I save duplicating the work.
The most interesting part is the previous the last field, wherein I tell it to remove all html tags (anything between < and >) and all their settings (i.e. target=”_blank”). Thus I’m left with the title in plain text.

Creating the date

This was a more tricky part as not only does the last.fm activity stream API consider it a good idea to put the date on the content but it also puts it in as a relevant entry to the current date.

Putting the date in the correct field was the easy part as all I needed to do was copy the content in the date field and remove everything except the date. As right before the date there was a fullstop, it was fairly simple to use another regex to delete anything until the last fullstop

The regular expression removes everything until the last fullstop
With a little regex magic, anything except the date is gone

The more difficult part was to make the relevant fuzzy date to become something that is expected to be in an RSS feed, which is something very specific in time and format. Fortunately, I noticed that there is a specific module that does exactly that: Date builder. How convenient.

Unfortunately this module accepts only strings so I could not really parse my whole feed through it unless I had a loop. Oh wait…

With a loop I can make all date items in the correct format
With a loop I can make all date items in the correct format

Sweetness. Unfortunately one problem remains which is that because the date provided is always fuzzy, I end up getting a rolling date for the item each time the pipe is run. For example, an item which has a date of “one month ago” today will point to Aug 28, tomorrow on Aug 29 etc. There’s not much I can do about it other than wait until (and if) last.fm deems it worthy to give us a proper feed.

And now my new shiny feed is in exactly the format I need to have for Complexlife to use it. A little hacking later and version 0.9.8 is ready to go. The last.fm activity stream is finally lifestreamable 🙂

Reblog this post [with Zemanta]

A Quickie

OK, on rapid succession before I hit the bed:

  • I finished version 0.9.5 of Complexlife. It now includes support for stumbleupon and reddit, an option to simplify the settings menu by hading the extra options and some code improvements.
    This is 5 minor versions since the fork. Go me!
  • I finally added a favicon on the Division by Zer0. I wanted to do this for a while but I never got around to it and I also didn’t have anything in particular I wanted to use. Finally a guest post from Pharyngula gave me the idea to use the atheism symbol which looks cool enough.
    It took me a while to figure out what the correct code is but a little Google prayer and I got my divine answer.
  • We now have 22 Atheists in Scoutle which is pretty impressive if you consider it was only 4 days ago that I mentioned it. However the more impressive news is that found a fellow Epicurean blogger through the new network I setup. Coolness!
    So, for the rest of you who haven’t joined yet. What are you waiting for?! Git!
  • I now have an actual Comment Policy so I’d appreciate any opinions on it 😀

G’night!

ComplexLife

window peeksSo finally my very first WordPress plugin is accepted into the official plugins repository 🙂

This is a historic event. I’m certain that fame and fortune will not be very far back!

In case you haven’t seen my recent page about it and you don’t care to read it, Complexlife is a lifestreaming plugin which is a fork from SimpleLife (You see what I did there? 😛 ).

After adding a lot of features and options to it and seeing that Simplelife is not progressing I thought I’d go ahead and just upload it as a new version. This will allow me to have a more organised development and also have the help of anyone who wishes to improve it.

I’ve already got a few features I want to add and I’m also going to be merging changes from other places where I find them, i.e. the trumblog.

So if you’ve got a self-hosted WordPress blog, give it a go and let me know what you think. I’m eager for feedback.