martes, septiembre 11, 2007

Syndicate your music!!!

Introducing Amarok Atom Syndication

Apart from the new look&feel of my blog, maybe some of yoy have noticed a new widget on the right-side panel which shows the recent tracks played on my computer. It seems there's nothing new there, a similar widget exists from Last.fm for example...

The thing is that couple of months ago I got one of those crazy ideas which sometimes come to my mind (and most part of the times I forget the next day). I wanted to do exactly this, I wanted to publish all the track songs I played on my computer to my blog, and I wanted to do it automatically.

It was pretty simple actually. I just needed to whenever I play something, then retrieve the data related like name of the song, artist, album, etc. Then I put it in a file format like RSS or Atom, and then I syndicate it to the net. Quite simple indeed...

By that time I started using Amarok as my music player. Amarok is a great music player. Apart from the common set of features which every music player has, Amarok supports lots of extra features: huge file list processing and organization tools, transparent integration with other services like Last.fm or Wikipedia, and lots more. Most important of all, Amarok can be extended via customized plugins. Writing your own plugin is damned easy, just use DCOP to communicate with Amarok back and forth. In addition, plugins can be written in any programming language, being the most popular Ruby and Python.

So via Amarok I got that part covered. I knew now how to get the data I needed and writing my output in a XML format. I chosed Atom file format for my output, since it seems is gaining ground.

What about syndicating? How to upload my Atom file to the net, so other applications could read it and show its data? Well, I started to dig on Google developer services, to see what can I used. I tried Google base but it wasn't exactly what I was looking for. Then I discarded the idea of using some Google services, and tried S3 from Amazon, but I also discarded short after playing a bit with it. Simply nobody will sign for S3 services just for having a stupid file list published somewhere on the net. Then I got back to Google but started playing with a wide unknown service from Google: Google Pages. Yes, you got it, Google Pages is something like Geocities, one of the oldest services which sprang up in an early Internet, but on a Google flavour. Whenever you sign for Google Pages you are giving a space where you can put your stuff and build your own website. Among other things, you can upload files, and that was exactly what I wanted.

On the contrary to many Google services, Google Pages has not an API developers can interact with, but if you can make via a browser you can make it via programming language, maybe will be loads more difficult, but still you can.

So basically, I got all my requirements satisfied. I programmed my sript in perl, which is my scripting language of choice. Perl helps me a lot for processing the text data and writing up the Atom file. It was also great for uploading my output to Google Pages, via LWP.

The pity is that maybe perl is not the best language for writing KDE applications. At this moment it lacks of binding support for Qt4.0, and according to the threads I read on the internet, it seems there is no interest on bringing Qt4.0 support for perl. As a consequence, the plugin requires to do some hand configuration work, straight on the source code.

Putting it all together

Download

You can download the plugin here, Amarok Atom Syndication.

Requirements
  • A Linux enviroment
  • Amarok and whatever libraries needed
  • Firefox. Plugin needs to read you firefox cookie file
  • A Google acount
Installing
  • Download the plugin
  • Open Amarok and go to Tools->Script Manager. Choose open and select the plugin downloaded
Configuration

First of all, you need to apply for Google Pages service. If you do not have a Google account, the sign first.

Then, log to Google Pages at least once. When doing so, check your Remember my password checkbox, so your login data will be saved on your cookie file. The script needs to read your cookie file in order to interact with Google Pages (no malicious code executed, you can checked, it is free software ;-))

And lastly, before running the plugin you need to add your username in the main script file. Edit the file with your favorite editor and set the $username variable. Do like this (I use vi for editing):

$ vi ~/.kde/share/apps/amarok/scripts/atomSyndication/atomSyndication.pl

Go to line 28, and set username:

$username = 'my_google_username_goes_here';

And that's all, then run Amarok Atom Syndication (again Amarok, Tools->ScriptManager, select atomSyndication and play on Run).

Reading the feed

Your Atom file will be posted at http://username.googlepages.com/amarok.xml. This is my Atom file: http://pinowsky.googlepages.com/amarok.xml.

You can your Atom file posted on you Google Page address, via any feed reader like Google Reader, Thunderbird or Firefox's extensions like Sage.

If you want to show the data of your Atom file on your blog, then use one of the new widgets Blogger comes along with. Click on Configuration at your Blogger backend frontpage, then go to the Template tab.

Many other websites allow to plug in feed readers, via iframes or so. There is one for Facebook for example. Check my Facebook profile to see an example (look for the Feed Invasion plugin).

Updating your Atom file

Atom file updates whenever you jump to a new song in Amarok. However, you won't see the results on your Google Reader or Blogger feed widget immediately. Those services, more specifically, take one hour to be updated, so you will notice changes on your track list only every hour if you are using these tools for reading your feeds.

If you want to get a more accurate update of your Atom file use other readers like Sage or Thunderbird. Basically, all feed readers based on web have an updating lag. It is simply something you have to cope with.

Cool features

One cool feature of this recent tracks played list, is that every entry is a link to Seeqpod searching by name of the song and artist. Seeqpod is a web-based music search engine. Basically, it crawls the Internet searching for music files, index them, and then you can query it later to search for new songs, and play them. If you are lucky and one of the songs on your track list is relatively popular, the likelihood to be found in Seeqpod is higher. So, imagine you were playing some music yesterday at home on your computer. On the next day at work you feel like listening to some of the songs from yesterday, but unfortunately you did not carry those songs with you on your ipod or even you cannot remember the name of that song you like. So you read your syndicated track list, and click on that song which will lead you to its mp3 file at seeqpod, if you are lucky. The other choice is not to forget your ipod next time, hehehe...and keep it updated, by the way.

Anyway, this is still fun. I think this approach is more to lazy people like me (or for those who have not an ipod yet, by the way, Christmas is coming...). It is also a kind of poor's man ubiquity service.

Extending the plugin

It has been good fun programming this plugin. It is not very customizable and lacks for a better configuration procedure, via a dialog-box or something for example. As I mentioned on a paragraph above, perl lacks for Qt4.0 support, so that means I may need to switch to other programming language, more likely Python, if I want to fix these problems.

I encourage everybody to use the source code and maybe extend the plugin. I also will like to see other people syndicating their music in other music players, using a similar approach (retrieve data, write ouput on a Atom file format, post to somewhere on the net (Google Pages)).

Hope you like it, have fun!!! and remember to vote for Amarok Atom Syndication (even if you could not even make it run, hehehe)

3 comentarios:

Anónimo dijo...

Great!!!!
Nice bunch of ideas and technologies put together :)

Voted!

iurgir dijo...

Too IT 4 me-laaaaa.
Saludos desde Bilbao.
En breve HK?????
Ya diras.

Anónimo dijo...

I will soon take a look to perl... now, it could help me too much! and it seems funny, isn't?

perl: "hard to read, easy to write". It could be its new slogan, don't you think? jaja