Saturday, January 16, 2010

A lyric script for amarok 1.4 written in Python

I switched to amarok as my default music player after I came to know about the concept of amarok scripts - simple scripts interacting with amarok via DCOP and adding various functionalities to the player. There's a plethora of those scripts on the web: the best place to look for them is

However, my enthusiasm about amarok took a heavy blow pretty early - the version of amarok included in the distro I'm using (Ubuntu 9.10), turned out to be painfully sluggish and unresponsive. Unwilling to give up on the brilliant player on account of this single flaw, I decided to go for a previous version: I used an older version of amarok on either Ubuntu 8.10 or Debian Lenny for a very brief period and it was not at all sluggish back then. So I had to go through the usual chores: adding Jaunty and Intrepid repos in my sources.lst, updating apt (at this point synaptic showed a nasty error message complaining about its cache-limit not being big enough. A little googling later, I was able to increase
the cache-limit by editing /etc/apt/apt.conf.d/70debconf), and force-versioning the packages in Synaptic. And sure enough, the Intrepid version ran without any fuss.

After the new (old) amarok scanned and indexed my music collection, I promptly installed a couple of amarok scripts: Gnome-Multimedia-Keys, Amarok notify-osd(This one replaces the rather crude amarok osd's with the new default notification system of ubuntu). At this point I noticed that amarok has a separate category of scripts named 'lyrics'. All of them seem to be there for basically performing one simple job: fetch the lyrics of the song currently playing in amarok and show it under the 'Lyrics' tab in the left pane of the amarok window. But there was just one small problem: none of the included lyric scripts could display the lyrics of any song I'd listen to.

This really stumped me because whenever I google for the lyrics of any song, I generally find it in the first search result Google returns. I even found a lyric script which uses a google search, but all it did was simply render the google search results page onto the lyrics pane instead of showing the actual lyrics. Therefore I decided to write a lyric script myself. This script finds the lyrics of a song using the awesome python library for google search by Peteris Krumins. The first version of the script surely needs more polishing but at least does its job pretty nicely for me.

The script can be downloaded from here.

Tuesday, January 12, 2010

Living harmoniously with Ubuntu 9.10 and Nokia 5800 XpressMusic

As I mentioned in the previous post, I ran into some trouble syncing my new Nokia 5800 XpressMusic with my laptop running Ubuntu 9.10 Karmic Koala. Sure, the phone would work just fine in mass storage mode via the included data cable and let me transfer anything onto the SD card, but I was not satisfied with it. Apart from other issues, that way I'd still have to create the playlist manually in the phone's music player. And since the phone lacked the capability  to add all the contents of a folder to a playlist (It doesn't allow changing the order of songs in an existing playlist either - those guys at Finland seem to be rather aversive to the idea of playlists), I was not exactly thrilled at the prospect of having to add each song in the full discography of Poets of the Fall to a playlist.
         I needed a program which would not only transfer all the songs in a playlist in my computer to my phone but also create the appropriate playlist in the phone. At first I unsuccessfully tried my luck with Rhythmbox : it showed all the tracks on my phone but stubbornly refused to play any of them.
         But I got lucky the second time. I happened to start amarok - the music player I abandoned ever since Jaunty Jackalope due to its sluggish performance. After googling for amarok plugins to sync with Nokia symbian phones, I came to know about the existence of amarok scripts. Although I couldn't find any script meeting my requirements on the web, on reading some of the scripts I became aware of the powerful DCOP interface of amarok. To my great delight, I found out that it  gives one the freedom to control (and automate) every aspect of that brilliant music player and natively supports python scripts.
         So I chose the obvious solution. I  wrote the code myself in python. The actual procedure was very simple: ask the user to select the playlist he wants to sync and where he wants to copy them to, copy-paste the whole damn thing, create a playlist and be done with it. But  the user interaction part was problematic: the user has to specify long pathnames. Doing so at a  python raw_input prompt without tab-completion can be frustrating. I had to create a gui.
       The last time I tried to code some gui stuff in python, I decided to learn Tkinter. Needless to say, that time I created some of the ugliest possible widgets in the universe. I had no intension of making the same mistake again. But the idea of going through the whole elaborate affair of learning pyQt or pyGTK for creating some simple dialog boxes did not seem appealing to me. While facing this dilemma, I found another gem hidden in the lines of the amarokscripts I already had in my system: kdialog. This was just the perfect thing for my code: simple one-line commands to present pretty dialog boxes showing a message or a file browser where the user can select the paths by means of good old point and click.
       Well, here's another interesting piece of trivia: the temporary playlist amarok creates when you drag and drop music files to its main window is saved as an XML file, but the playlists created manually are saved in normal .m3u format. Unaware of the second fact, I ended up studying xml parsing in python. Although it was totally unnecessary, I learnt about a couple of very powerful python libraries: xml and urllib.
       So the process of syncing the Nokia 5800 with Ubuntu was not as simple as I thought it would be. But my chance encounter with DCOP and urllib turned out to be rather fortuitous as it enabled me to write my second amarok script. I'll write about it in another post someday.

Monday, January 11, 2010

Mixed feelings about my new Nokia 5800 XpressMusic

Well, I have to admit that the decision of buying this phone was a rather impulsive one. That sort of behaviour is certainly not characteristic of me. But the fact is that I haven't had any new gadget to fiddle with for quite a few month. Besides, the included freebies were really tempting: a Sennheiser headset and 100 songs downloadable from Nokia's new Ovi store. Although both of them turned out to be rather disappointing (I'll come to those issues later), I am quite satisfied with the phone.

         The large screen produces crisp colours. Excellent for watching videos. The touch based UI could be a bit better though, occasionally it can't understand whether I want to select something or just scroll through the page. Being an XpressMusic, it is adequately equipped to belt out good quality music. But the Sennheiser PMX-60 headset failed to live up to the expectation (The first thing I did after buying the phone was to check that one out, even before the phone itself!) and the high level of expectation is not to be blamed for that. The sound quality is not  actually bad, but it leaks sound A LOT. Likewise, it allows enough of outside noise to make me reach  for my Creative EP-630 noise isolation earphones ( listening to music on this Nokia/Creative combination is a real pleasure, by the way).
         The Ovi store was an unmitigated disaster. I knew that the website was IE only, but I planned to wiggle out of that one by installing IE on WINE. But lo and behold; the Finnish web designing geniuses did not stop at only making the website incompatible with all the decent browsers over there, but made no provision of directly downloading music from the site at all. The actual job must be done on a software specifically designed for that. And needless to say, that software is windows only. So the only option I have for redeeming that offer is to download the songs directly to my phone.
          To be fair, the phone itself leaves very little to be desired at its price point. Getting both Wi-fi and GPS at this price is really nice. Besides, Symbian being the most popular OS for mobile devices, an unnervingly huge collection of softwares are available on the web.
          But the biggest plus point of this phone is that the symbian platform is extremely python-friendly. The default symbian port of python (made by Nokia itself) even includes the option of setting up a serial connection to a linux box over bluetooth. This one turned out to be a major boredom buster for me, as it enabled me to tinker with the innards of the phone. They even provided a script to create .sis installers from a python script. I haven't checked it out yet but plan to do that as soon as I write any big enough program.
P.S. - I actually started to write the blog with the intention of describing the ordeal I had to go through for syncing the playlists on my computer with the phone, but unfortunately it is almost 7 a.m. So that story will have to wait (In case you are wondering what kind of errand I am up to at 7 a.m. in a January morning, I'm just hoping for a couple of hours of sleep before classes start).