Showing posts with label amarok. Show all posts
Showing posts with label amarok. Show all posts

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 kde-apps.org.

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.