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



commit dd0e665285244e4532d978d3035c8c7b21de13e9
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 | 33 ++++++++++++++++++---------
 1 file changed, 22 insertions(+), 11 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index ecda4968..f8869659 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -218,16 +218,22 @@ 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
         """.replace('\n', ' ').strip() % {
             'location_filter': TrackerWrapper.location_filter()
         }
@@ -477,17 +483,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]