2 from gi.repository import Tracker
4 # (album name, artist1|artist2|... , number of artists)
5 ALBUM_ARTISTS_COUNTER = """
6 SELECT nie:title (?album) nmm:artistName (?artist) COUNT (?artist)
9 ?album a nmm:MusicAlbum ;
10 nmm:albumArtist ?artist .
15 class TrackerBackendGI:
18 self.conn = Tracker.SparqlConnection.get (None)
20 def get_all_albums (self):
22 Generator returning (album_title, album_artist)
23 If the album has more than one artist, "Various artists"
25 cursor = self.conn.query (ALBUM_ARTISTS_COUNTER, None)
26 while cursor.next (None):
27 album_title = cursor.get_string (0)[0]
28 if cursor.get_integer(2) > 1:
29 album_artist = "Various artists"
31 album_artist = cursor.get_string (1)[0]
33 yield (album_title, album_artist)
37 if __name__ == "__main__":
39 tracker = TrackerBackendGI()
40 tracker.get_all_albums ()