Ceci est une ancienne révision du document !
Welcome to these few articles where I share how I tackled and solved a problem using a little of my past knowledge and leveraging the marvellous open source world. In other words, I had an issue with a piece of software (rhythmbox) and addressed it by writing a little program.
Why have I decided to write this? Open source communities are about giving back, and I believe this is a way for me to give back, not only to the Ubuntu community, but also to Full Circle, that, as you will see, has a lot of credit in this. After you read this, I hope you’ll be even more enthusiastic about the possibilities that OSS offers, and maybe give it a go, try doing something yourself (it shouldn’t necessarily be coding).
What you will not find in these pages is how to learn to program, or a quick course on Python, also because there’s already a superb column by Greg D. Walters. I will use my program to tell my story, and to share some specific tips that show why open source is called “open” and why that is a benefit for everyone. You don’t have to be a coder or a geek to enjoy it. I know how to write a program because that was my job 30 years ago; since then I moved into a different field. When I wrote the piece of software I am sharing, I had no technical knowledge of writing code for Linux and Gnome, and didn’t know Python at all.
So here is my story. I switched to Linux 12 years ago, a bit for curiosity and a bit because I was fed up with the idiosyncrasies of Windows (XP at the time): getting slow, and every six months format and reinstall to clean up the system. I started with Fedora Stentz, upgraded to Bordeaux, and then moved to Ubuntu.
I don’t remember when I stopped dual-booting, probably 6 years ago when I realised I was doing everything in Linux and never using any other OS. Like many, one of the things I do with my computer is listening to music; as a matter of fact, I’m writing this with the rhythm of Beautiful Day from U2! In those years, I tried a few music players but I tended to stick with the default one provided by Canonical. Thus, for a little while I used Banshee, but mainly Rhythmbox which is described as “a reliable, dependable, and extensible GTK music player that uses the Gstreamer backend”.
It definitely satisfied my needs and ticked all the boxes for me. I had only one little issue: sorting. It is a nice feature that offers you the possibility of showing artists and albums in a different order from the mere alphabetical one. It does that by adding more fields to the standard MP3 ones: artist sort order, album sort order, album/artist sort order, and composer sort order – see the Illustration. I wanted to use this approach, so that, for example, ‘The Script’ would show up under ‘S’ and not ‘T’. To do so, I just need to populate the proper field (artist sort order) with “Script, The” and so I did. It worked exactly as I wanted. You can see the result in the Illustration. My next step was to sort all the albums for an artist in a chronological order – to achieve this, I simply put the year of release in the album sort order field. Of course this is how I would like to see my music, you may want it completely different.
There were only two issues. First of all, I had to enter all of this information for every track, albeit using multiple selection helps, it is still a time consuming process. Second, at times the information was lost… after I closed Rhythmbox and relaunched it, some tracks had the sort fields blank. I believed it was a bug, but a search on internet showed I was the only one suffering so I was undecided what to do. I could have lived well without sorting the information, but at the same time it was a pity. Being a former programmer and user of the Rhythmbox OSS, I took a look at the source code of Rhythmbox to see if I could tinker with it. I found it too complicated for me, I had to understand too many new concepts (Gnome, Gtk, data structures), and soon discovered it was too much for me.
I have read Full Circle since the first issue, and I noticed the Python column by Greg – that gave me the idea to try to learn Python, solve my issue, and possibly offer the community a piece of software that made it easier to enter sort information. This for me is the spirit of OSS, and, during the course of this article, we’ll see why the same thing would have been way more difficult in a closed source environment.
I went straight to Greg’s lesson number 1 and tried to practice a little with the classic “Hello World” program. In a short time, I started addressing my sorting problem and began writing my first program in Python. I called it fixrhy and tried to figure out how Rhythmbox uses the sort information. Looking at the documentation (https://developer.gnome.org/rhythmbox/stable/RhythmDB.html), I saw there is an “Object” that provides access to the song DB. Again, it proved to be a little too much to chew on at the time and therefore I decided to go along a different road. I discovered that the information is saved in a XML file, so I tried to play with it. Before the next chapter, where I talk about my first program, I would like to point out that the route I took is not the ideal one. Writing a plugin and using the official API would have been more appropriate and future-proof. But, at the time, I just wanted to try Python and come up with a quick fix, and so I did.