Kcmdlineargs really eases my weekend projects
This weekend I was at home playing my music with vlc, then I discovered I had no easy way to retag my Nirvana album (From the muddy banks of the whishkah, really good), which mp3 files had no metadata information. Certainly, I could install picard, or some id3 tag editor, but what better opportunity to write code of my own and accomplish this task?. So I fired up Qt Creator, and started my weekend project. My idea was pretty simple. Since every file had a filename of the form
<TrackNumber><Artist> – <Title>.mp3,
I just had to envision a regular expression in order to get all the metadata I needed, and write it to the file. And here is the glitch, since my computer did not have a program to write the metadata into the files. Nevertheless, what my computer did have was taglib, a C++ library made to read and write metadata from a variety of audio files including mp3 and ogg. Then I put hands on, and wrote a few lines of code.
Taglib is very easy, you just create a FileRef object from the file name, and use it to write metadata to it. The next step was to write a command line frontend. In this step I used kcmdlineargs, a library wrote for the kde project, which works parsing command line arguments and is very flexible to define options and command help.
This last step is not really necessary, I mean, it would not be that hard to write a command line parser for this very simple program, but using kcmdlineargs implied to learn more about the KDE platform.
If you would like to check the code, you can do so at github.