[gnome-music/wip/mschraal/grltracker-improve-artist-query: 2/2] grltrackerwrapper: Improve artist query



commit 99a77553f3f81856a591c6ff675c27f038f11f8b
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu Oct 31 00:24:31 2019 +0100

    grltrackerwrapper: Improve artist query
    
    The artist query was only taking into account the artist tag. The
    album-artist tag however is preferrable if available.
    
    Use the album-artist tag if available and use the artist tag as fallback
    for artist retrieval.
    
    Closes #331

 gnomemusic/grilowrappers/grltrackerwrapper.py | 34 ++++++++++++++++++---------
 1 file changed, 23 insertions(+), 11 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index ceb8242e..4b44a664 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -216,16 +216,23 @@ class GrlTrackerWrapper(GObject.GObject):
 
         query = """
         SELECT
-            rdf:type(?artist_class)
-            tracker:id(?artist_class) AS ?id
-            nmm:artistName(?artist_class) AS ?artist
+            rdf:type(?artist)
+            COALESCE(tracker:id(?album_artist), tracker:id(?artist)) AS ?id
+            ?artist_bind AS ?artist
         WHERE {
-            ?artist_class a nmm:Artist .
             ?song a nmm:MusicPiece;
                     nmm:musicAlbum ?album;
-                    nmm:performer ?artist_class .
+                    nmm:performer ?artist .
+            OPTIONAL {
+                ?album a nmm:MusicAlbum;
+                         nmm:albumArtist ?album_artist .
+            }
+            BIND ( COALESCE ( nmm:artistName(?album_artist),
+                              nmm:artistName(?artist)) AS ?artist_bind)
             %(location_filter)s
-        } GROUP BY ?artist_class
+        }
+        GROUP BY ?artist_bind
+        ORDER BY ?artist_bind
         """.replace('\n', ' ').strip() % {
             'location_filter': TrackerWrapper.location_filter()
         }
@@ -456,17 +463,22 @@ class GrlTrackerWrapper(GObject.GObject):
         query = """
         SELECT
             rdf:type(?artist)
-            tracker:id(?artist) AS ?id
-            nmm:artistName(?artist) AS ?artist
+            COALESCE(tracker:id(?album_artist), tracker:id(?artist)) AS ?id
+            ?artist_bind AS ?artist
         WHERE {
-            ?artist a nmm:Artist .
             ?song a nmm:MusicPiece;
                     nmm:musicAlbum ?album;
                     nmm:performer ?artist .
+            OPTIONAL {
+                ?album a nmm:MusicAlbum;
+                         nmm:albumArtist ?album_artist .
+            }
+            BIND ( COALESCE ( nmm:artistName(?album_artist),
+                              nmm:artistName(?artist)) AS ?artist_bind)
             %(location_filter)s
         }
-        GROUP BY ?artist
-        ORDER BY ?artist
+        GROUP BY ?artist_bind
+        ORDER BY ?artist_bind
         """.replace('\n', ' ').strip() % {
             'location_filter': TrackerWrapper.location_filter()
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]