+++ /dev/null
-import gi
-from gi.repository import Tracker
-
-# (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 TrackerBackendGI:
-
- def __init__ (self):
- self.conn = Tracker.SparqlConnection.get (None)
-
- def get_all_albums (self):
- """
- Generator returning (album_title, album_artist)
- If the album has more than one artist, "Various artists"
- """
- cursor = self.conn.query (ALBUM_ARTISTS_COUNTER, None)
- while cursor.next (None):
- album_title = cursor.get_string (0)[0]
- if cursor.get_integer(2) > 1:
- album_artist = "Various artists"
- else:
- album_artist = cursor.get_string (1)[0]
-
- yield (album_title, album_artist)
-
-
-
-if __name__ == "__main__":
-
- tracker = TrackerBackendGI()
- tracker.get_all_albums ()