[gnome-music/wip/jfelder/tracker3-rebased: 19/39] grltrackerwrapper: Retrieve musicbrainz artist id for songs




commit 42938f950cef59924fef046ec78dc0638b0b9506
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Jul 29 13:32:30 2020 +0200

    grltrackerwrapper: Retrieve musicbrainz artist id for songs

 gnomemusic/grilowrappers/grltrackerwrapper.py | 28 ++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index ca943d1b..01b0aaaa 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -50,6 +50,7 @@ class GrlTrackerWrapper(GObject.GObject):
         Grl.METADATA_KEY_DURATION,
         Grl.METADATA_KEY_FAVOURITE,
         Grl.METADATA_KEY_ID,
+        Grl.METADATA_KEY_MB_ARTIST_ID,
         Grl.METADATA_KEY_MB_RECORDING_ID,
         Grl.METADATA_KEY_MB_TRACK_ID,
         Grl.METADATA_KEY_PLAY_COUNT,
@@ -337,7 +338,7 @@ class GrlTrackerWrapper(GObject.GObject):
         query = """
         SELECT
             ?type ?urn ?title ?id ?mbRecording ?mbTrack ?url
-            ?artist ?album
+            ?artist ?mbArtist ?album
             ?albumArtist ?duration ?trackNumber
             ?albumDiscNumber ?creationDate
             nie:usageCounter(?urn) AS ?playCount
@@ -355,6 +356,7 @@ class GrlTrackerWrapper(GObject.GObject):
                         tracker:referenceIdentifier(?track_id) AS ?mbTrack
                         nie:isStoredAs(?song) AS ?url
                         nmm:artistName(nmm:performer(?song)) AS ?artist
+                        tracker:referenceIdentifier(?artist_id) AS ?mbArtist
                         nie:title(nmm:musicAlbum(?song)) AS ?album
                         ?album_artist AS ?albumArtist
                         nfo:duration(?song) AS ?duration
@@ -380,6 +382,12 @@ class GrlTrackerWrapper(GObject.GObject):
                             ?album nmm:albumArtist/
                                    nmm:artistName ?album_artist .
                         }
+                        OPTIONAL {
+                            ?song nmm:performer ?artist .
+                            ?artist tracker:hasExternalReference ?artist_id .
+                            ?artist_id tracker:referenceSource
+                                "https://musicbrainz.org/doc/Artist"; .
+                        }
                         FILTER ( ?song in ( %(media_ids)s ) )
                         %(location_filter)s
                     }
@@ -463,7 +471,7 @@ class GrlTrackerWrapper(GObject.GObject):
         query = """
         SELECT
             ?type ?urn ?title ?id ?mbRecording ?mbTrack ?url
-            ?artist ?album
+            ?artist ?mbArtist ?album
             ?albumArtist ?duration ?trackNumber
             ?albumDiscNumber ?creationDate
             nie:usageCounter(?urn) AS ?playCount
@@ -481,6 +489,7 @@ class GrlTrackerWrapper(GObject.GObject):
                         tracker:referenceIdentifier(?track_id) AS ?mbTrack
                         nie:isStoredAs(?song) AS ?url
                         nmm:artistName(nmm:performer(?song)) AS ?artist
+                        tracker:referenceIdentifier(?artist_id) AS ?mbArtist
                         nie:title(nmm:musicAlbum(?song)) AS ?album
                         ?album_artist AS ?albumArtist
                         nfo:duration(?song) AS ?duration
@@ -506,6 +515,12 @@ class GrlTrackerWrapper(GObject.GObject):
                             ?album nmm:albumArtist/
                                    nmm:artistName ?album_artist .
                         }
+                        OPTIONAL {
+                            ?song nmm:performer ?artist .
+                            ?artist tracker:hasExternalReference ?artist_id .
+                            ?artist_id tracker:referenceSource
+                                "https://musicbrainz.org/doc/Artist"; .
+                        }
                         %(location_filter)s
                     }
                     ORDER BY ?title
@@ -794,7 +809,7 @@ class GrlTrackerWrapper(GObject.GObject):
         query = """
         SELECT
             ?type ?id ?mbRecording ?mbTrack ?url ?title
-            ?artist ?album
+            ?artist ?mbArtist ?album
             ?albumArtist ?duration ?trackNumber ?albumDiscNumber
             ?creationDate
             nie:usageCounter(?id) AS ?playCount
@@ -811,6 +826,7 @@ class GrlTrackerWrapper(GObject.GObject):
                         nie:isStoredAs(?song) AS ?url
                         nie:title(?song) AS ?title
                         nmm:artistName(nmm:performer(?song)) AS ?artist
+                        tracker:referenceIdentifier(?artist_id) AS ?mbArtist
                         nie:title(nmm:musicAlbum(?song)) AS ?album
                         ?album_artist AS ?albumArtist
                         nfo:duration(?song) AS ?duration
@@ -834,6 +850,12 @@ class GrlTrackerWrapper(GObject.GObject):
                         OPTIONAL { ?song nie:contentCreated ?date . }
                         OPTIONAL { ?album nmm:albumArtist/
                                           nmm:artistName ?album_artist . }
+                        OPTIONAL {
+                            ?song nmm:performer ?artist .
+                            ?artist tracker:hasExternalReference ?artist_id .
+                            ?artist_id tracker:referenceSource
+                                "https://musicbrainz.org/doc/Artist"; .
+                        }
                         FILTER (
                             ?album = <%(album_id)s> &&
                             nmm:setNumber(nmm:musicAlbumDisc(?song)) =


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