--- /dev/null
+import dbus
+import os
+
+TRACKER = "org.freedesktop.Tracker1"
+TRACKER_OBJ = "/org/freedesktop/Tracker1/Resources"
+
+# (album name, artist1|artist2|... , number of artists)
+ALBUM_ARTISTS_COUNTER = """
+SELECT nie:title (?album) nmm:artistName (?artist) COUNT (?artist)
+WHERE
+ {
+ ?album a nmm:MusicAlbum ;
+ nmm:albumArtist ?artist .
+ }
+GROUP BY ?album
+"""
+
+class TrackerBackendDBus:
+
+ def __init__ (self):
+ self.dbus = dbus.SessionBus ()
+ self.tracker = self.dbus.get_object (TRACKER, TRACKER_OBJ)
+ self.resources = dbus.Interface (self.tracker,
+ "org.freedesktop.Tracker1.Resources")
+
+ def get_all_albums (self):
+ results = self.resources.SparqlQuery (ALBUM_ARTISTS_COUNTER)
+ return self.__iter_results (results)
+
+ def __iter_results (self, results):
+ for (title, artist, counter) in results:
+ print "Executed the yield", counter
+ if int(counter) > 1:
+ yield (unicode(title), "Various artists")
+ else:
+ yield (unicode(title), unicode(artist))
+
+
+if __name__ == "__main__":
+ b = TrackerBackendDBus ()
+ for pair in b.get_all_albums ():
+ print "Outter loop"
+ print pair
+ print "ok"
+