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



commit 9a5b5063ec676e904d149fb03edd0554cf438d1a
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 ace4bb61..dab59a65 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]