4 TRACKER = "org.freedesktop.Tracker1"
5 TRACKER_OBJ = "/org/freedesktop/Tracker1/Resources"
7 # (album name, artist1|artist2|... , number of artists)
8 ALBUM_ARTISTS_COUNTER = """
9 SELECT nie:title (?album) nmm:artistName (?artist) COUNT (?artist)
12 ?album a nmm:MusicAlbum ;
13 nmm:albumArtist ?artist .
19 SELECT ?u nmm:artistName(?artist) nmm:albumTitle(?album) WHERE
22 nmm:performer ?artist ;
23 nmm:musicAlbum ?album .
27 class TrackerBackendDBus:
30 self.dbus = dbus.SessionBus ()
31 self.tracker = self.dbus.get_object (TRACKER, TRACKER_OBJ)
32 self.resources = dbus.Interface (self.tracker,
33 "org.freedesktop.Tracker1.Resources")
35 def get_all_albums (self):
36 results = self.resources.SparqlQuery (ALBUM_ARTISTS_COUNTER)
37 return self.__iter_results (results)
39 def get_all_songs (self):
40 results = self.resources.SparqlQuery (SONGS)
41 for uri, artist, album in results:
42 yield (uri, artist, album)
44 def __iter_results (self, results):
45 for (title, artist, counter) in results:
46 print "Executed the yield", counter
48 yield (unicode(title), "Various artists")
50 yield (unicode(title), unicode(artist))
53 if __name__ == "__main__":
54 b = TrackerBackendDBus ()
55 for pair in b.get_all_songs ():