Outils pour utilisateurs

Outils du site


issue133:mon_histoire

Ceci est une ancienne révision du document !


A quick recap of last month’s introduction. I wasn’t happy with how Rhythmbox handles song sorting information and decided to brush up my programming skills to write a little fix/improvement. In the process, I reinforced my praise for open source software and picked up a new language thanks to Full Circle. Let’s start with the former point, and keep in mind that most of what is valid for the Gnome music player can be easily applied to other open source software.

My first idea was to see if I could patch the source code. This is one of the ways you can contribute to the OSS community. See if there’s a bug or room for improvement, and propose your solution. Before I could do that I had to understand if it was a feasible option since I quit programming long ago and didn’t have too much free time. I searched the Rhythmbox project page and landed on a Gnome wiki packed with information. Scrolling down on the page, you can reach a Development Resources section (see Illustration) where you are presented with several options. At the time I am writing this, the Getting Started link goes to a non-existing page, I am sure it will be fixed by the time you read it, in any case I believe the right page should be this one: https://wiki.gnome.org/Rhythmbox/FAQ#Development_information

At the top, there is a link to a Newcomers Guide, which explains the process of how to get involved. On that page you find this sentence: “There are no requirements to start development. It can be an advantage if you know a bit of object oriented programming and git.”. I do know OOP (Object Oriented Programming), but only a faint idea of how git works. Nevertheless, I dug into the list of recommended reading, and was fascinated with the whole Gnome project, and I encourage you to do so. Although I eventually went down a different road, I would like to point out how all the tasks I mentioned are easy and achievable in the open source world where projects are shared, source code is available, and there is a community of people who are working to spread the knowledge and encourage others to contribute. With proprietary software, you normally find Application Programming Interface (API) documentation, where available, and that’s it!

Anyway, going back to my browsing the wiki, I realised that I had to digest some information before I could start typing some code, but along the way I came to understand that sorting information is stored in the Rhythmbox DB, and that is stored in an XML file on the computer. I believe the location of this file has changed over time, but now you should be able to find it in ~/.local/share/rhythmbox, and you should find a file there with the name rhythmdb.xml. If you use nautilus to browse the file system, you have to enable the view of hidden files (shortcut Ctrl+H) to see the .local folder.

I took a peek at the file itself, you can do it too by opening the file in a text editor or in a browser. XML files are human readable by definition, and that simplified my task a lot. I could easily identify the structure of information and understand that every song’s information was packed in between two tags: <entry type=“song”> and </entry>. Inside those two markers is stored all the information for each track; you can see an example in Text. I immediately realised where sorting information was stored… towards the end there are two fields: <mb-artistsortname> and <album-sortname>. Note that these are not part of the standard MP3 tag structure, so Rhythmbox can rely only on the one inside its database. Browsing the file, I discovered that some tracks had no sorting information despite that I entered them in the program itself. I also realised that if I entered them manually in the file they would stick, and that would partially solve my problem. If not, that it is a tedious job, you have to enter them for each and every track, and if you do something wrong, you could possibly destroy the whole database.

Therefore I took the decision of writing some code that would do the job for me. I knew several languages with C and C++ my favourites. I never wrote anything in Python, but I had the chance of following the lessons from Greg D. Walters on this same publication. It sounded like a good compromise for me: I didn’t go for the hard job of learning the whole Gnome/Rhythmbox development structure, but at least I would learn something new. Plus Greg and I both enjoy cooking!

As most people do when picking up a programming language, I went back to the first chapters of Greg’s lessons and tinkered with the “Hello World” programs to understand a little how Python works. It was very easy (see FCM#27 onwards), and soon I felt ready to take on my challenge.

My objective was plain: given any album, I wanted to be able to enter quickly the sorting information. As an example, for Hunky Dory by David Bowie, I wanted all the tracks to have “Bowie, David” in the field mb-artistsortname, and 1971 in the album-sortname field (the year it was released so that all the records would be chronologically sorted). To achieve that, I had to create something to manage the XML structure, look for track entries that match the given one (David Bowie/Hunky Dory), check if the sorting information is already there, if not create it, and then populate it. Now XML files are text files, but directly manipulating them seemed not a good option. Could I avoid the task of interpreting XML? A quick search in Google provided the answer: “python xml library” returned at the top of the page: https://docs.python.org/3/library/xml.html.

Now I had an idea, plenty of documentation, a programming language, and already a library to tackle the issue. Next month we’ll see the code I wrote and how it works.

issue133/mon_histoire.1527323726.txt.gz · Dernière modification : 2018/05/26 10:35 de auntiee