Just For The Fun Of It: Browsing Music With Nepomuk

Since implementing the TV Show KIO slave was that easy I decided I could do the same for music – just to show how simple it can be. There a a few more lines but that is only because I added browsing by album, artist, and genre. So there are a lot of if/else constructs. Anyway, here goes:

Browsing music by artist is easy. As you can see I also implemented a preview generator plugin the same way I did for the TV Shows. The only problem is that there is no tool yet that automatically fetches those images. Thus, I had to do it manually for one example which looks somewhat like this:

qdbus org.kde.NepomukStorage 

This is part of the fancy Data management API which allows me to add the file atb2.jg as a nfo:depiction of the nco:Contact resource identifying the artist ATB.

Anyway, entering the artist themselves and what lies beyond:

(Again I had to fetch the cover art manually. I did not want to implement my own cover art retrieval tool and I found the Amarok code not to be very reusable. Again maybe someone wants to take up this task?)

Finally we end up in the album tracks. Sadly dragging an album to a media player playlist does not work yet. I am not quite sure how to fix that.

Last but not least a quick look at browsing by genre:

This was fun. But before I go to bed let me share with you the very simple code which is responsible for the nice previews (abbreviated of course):

bool MusicThumbCreator::create(const QString &path,
                               int w, int h,
                               QImage &img)
  KUrl url(path);
  QStringList pathTokens
      = url.path().split('/', QString::SkipEmptyParts);
  if(pathTokens.count() < 2) {
    return false;

  // there are only two cases for us: artists and albums
  if(pathTokens[pathTokens.count()-2] == QLatin1String("artists") ||
     pathTokens[pathTokens.count()-2] == QLatin1String("albums")) {
      const QUrl uri = recoverUriFromUrlToken(pathTokens.last());
    // we just query the first depiction there is
    Soprano::QueryResultIterator it
       = Nepomuk::ResourceManager::instance()->mainModel()
              QString::fromLatin1("select ?u where { "
                                  "%1 nfo:depiction [ nie:url ?u ] . "
                                  "} LIMIT 1")
    if(it.next()) {
      return true;

  return false;

The rest of the code can be found in the nepomuk-audio-kio-slave scratch repository. Maybe at some point I could just throw all of those things into some “Nepomuk KIO extensions” package… oh, well, off to bed now…

28 thoughts on “Just For The Fun Of It: Browsing Music With Nepomuk

  1. I…AM…AMAZED….

    No, I am not. I already knew KDE does have those amazing technology in the backend. However, it is supercool you show how much power there is back there. I hope some programmers will pick this idea up and re-use is for in example images, an musicplayer..what…I mean multimediaplayer (KBMC anyone?) and stuff like that.

    Nepomuk will be enabled by default on all distro’s in the future (I presume) so let’s use it’s amazing powers!

  2. “I did not want to implement my own cover art retrieval tool and I found the Amarok code not to be very reusable”

    Don’t know if it’s of any interest but bangarang also fetches cover arts. Maybe you should look there for code.

    • This KIO slave could be used as the backend of that collection. We’ve done it bore for KDE UPnP-MediaServer. It’s not trivial and lot’s can break, but it is way to reduce the codebase in amarok and sharing the functionality.

      Unfortunately relying on dependencies that our out of our control (completely or partially) is the biggest source of bug reported to Amarok. Phonon, it’s backends, kdelibs, plasma regressions: these account for more then half of the problems reported with Amarok.

      • I see why you dislike that “upstream” bugs take time to resolve. But that is what happens, if you use upstream software, such as Qt, the KDE frameworks, etc. instead of writing everything from scratch. Obviously, there is a point to using libraries, etc. as really everyone is doing it. My point is not to claim that you are not aware of this or that your observation about the bug rate is wrong. My point is simply that you can say this with anything you pick up and integrate into Amarok. So this is a bad argument against any particular framework, including Nepomuk.

  3. Cool but two suggestions:
    1) A “Browse by Album” is needed to display albums with different artists.
    2) I think that is usual to have the album/artist cover in the artist/album directory: cover.jpg, cover.png, etc… so it’s easy to look for that file and use it if exists.

    And a behavior, you are not handling albums with more than one disk.

    • “Browse by Album” is easy to add.

      As far as albums with more than one disk go: you are right. I did not take that into account. But then again this was supposed to be a fun proof-of-concept. :)

      • Yes, really fun, like the others that you wrote lately :).

        Recent weeks have been impressive from the point of view of a user.

  4. Nepomuk, full of awesome !

    With this kind of things people will start to realize how powerful and fantastic nepomuk is :) !

  5. One idea would be to compile your last blog posts about nepomuk capabilities in an article on the dot, so people see what nepomuk is able to do, and getting good press echoes.
    As of now, nepomuk is quite an abstract concept for a lot of people, and the don’t undertstand its usefullness. That may do wonders (albeit it could wait for KDE 4.9 to be released ;) )

  6. Awesome stuff!

    But, there’s something that’s been bothering me about all this Nepomuk awesomeness: Why is there no “Delete Duplicates” feature using it? Isn’t it ideal for that sort of thing?

    Actually, I’ve been searching for something like that for quite a long time now, and even outside of Linux free options are fairly scarce.

  7. I want this. Just like the TV Show KIO slave. In fact, I tried to compile the latter, but there were missing dependencies (the tv namer program you link to does not exist on Arch) and I had too little time at my hands to install it. I eventually will (maybe this weekend), but I think it would be great, if these KIO slaves went into some Nepomuk repository in Extragear, so that disotros pick them and their dependencies up. The best way to ensure that this worl of your will not bitrot and eventually disappear (or become work for you only), is to put it into people’s hands.

    Thank you for your work, we love it!

  8. Great Job!
    I am using it on kubuntu 11.10 everything work fine except for depiction that gets added to the nepomuk attributes but the image dont get displayed .

  9. Pingback: Another Small Package Release | Trueg's Blog

  10. I know this was only a demonstration of the power inside Nepomuk, but in case any programmer plans to extend this exercise, please add search by composer and date, many professional musicians, critics, teachers, etc, do care about who composed the songs in an album and when were published, not only about the interpreters (“artists”), and let’s not talk about melomaniacs with their thousands of classical music albums classified by composer, artistic period, etc.

    Wonderful job, BTW, Herr Trüg. Vielen dank, :)

  11. Awesome stuff!
    but , i have a small issue the tumbails doesnt works for me.
    I ran the command for adding nfo:depiction as its shown in the article (successfully) but the image are not displayed when i enter in music:/artists/

  12. Sebastian, can’t compile it with master:
    /home/hrvoje/rpmbuild/BUILD/nepomuk-music-kio-slave-0.1.0/kio_music.cpp: In function ‘int kdemain(int, char**)’:
    /home/hrvoje/rpmbuild/BUILD/nepomuk-music-kio-slave-0.1.0/kio_music.cpp:621:59: error: ‘getpid’ was not declared in this scope
    Mind helping? :)
    I’ve added #include
    but that doesn’t help

  13. Solved by this (‘standard’ gcc4.7 issue):
    diff -ruN a/kio_music.cpp b/kio_music.cpp
    — a/kio_music.cpp 2012-07-26 23:49:37.000000000 +0200
    +++ b/kio_music.cpp 2012-07-30 16:12:11.489995022 +0200
    @@ -49,6 +49,8 @@

    using namespace KIO;
    using namespace Nepomuk::Vocabulary;
    using namespace Soprano::Vocabulary;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s