[gnome-music/wip/mschraal/grltrackerwrapper-unify-songs-query: 2/2] grltrackerwrapper: Modernize songs query




commit 5f07c3ef7e0c1241424c1ed855b4797415e9f9ab
Author: Marinus Schraal <mschraal gnome org>
Date:   Tue Aug 31 22:45:56 2021 +0200

    grltrackerwrapper: Modernize songs query
    
    * Use f-string
    * Use join and split to remove excessive whitespace and drop the
    newlines

 gnomemusic/grilowrappers/grltrackerwrapper.py | 38 +++++++++++++--------------
 1 file changed, 18 insertions(+), 20 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index a34642e88..782945fe2 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -406,7 +406,10 @@ class GrlTrackerWrapper(GObject.GObject):
             media_ids = str(ids)[1:-1].replace("'", "")
             songs_filter = f"FILTER ( ?song in ( {media_ids} ) )"
 
-        query = """
+        location_filter = self._tracker_wrapper.location_filter()
+        media_type = int(Grl.MediaType.AUDIO)
+        miner_fs_busname = self._tracker_wrapper.props.miner_fs_busname
+        query = " ".join(f"""
         SELECT
             ?type ?urn ?title ?id ?url
             ?artist ?album
@@ -414,11 +417,11 @@ class GrlTrackerWrapper(GObject.GObject):
             ?albumDiscNumber
             nie:usageCounter(?urn) AS ?playCount
             ?tag AS ?favorite
-        WHERE {
-            SERVICE <dbus:%(miner_fs_busname)s> {
-                GRAPH tracker:Audio {
+        WHERE {{
+            SERVICE <dbus:{miner_fs_busname}> {{
+                GRAPH tracker:Audio {{
                     SELECT DISTINCT
-                        %(media_type)s AS ?type
+                        {media_type} AS ?type
                         ?song AS ?urn
                         nie:title(?song) AS ?title
                         ?song AS ?id
@@ -429,24 +432,19 @@ class GrlTrackerWrapper(GObject.GObject):
                         nmm:trackNumber(?song) AS ?trackNumber
                         nmm:setNumber(nmm:musicAlbumDisc(?song))
                             AS ?albumDiscNumber
-                    WHERE {
+                    WHERE {{
                         ?song a nmm:MusicPiece .
-                        %(songs_filter)s
-                        %(location_filter)s
-                    }
-                }
-            }
-            OPTIONAL {
+                        {songs_filter}
+                        {location_filter}
+                    }}
+                }}
+            }}
+            OPTIONAL {{
                 ?urn nao:hasTag ?tag .
                 FILTER (?tag = nao:predefined-tag-favorite)
-            }
-        }
-        """.replace('\n', ' ').strip() % {
-            "miner_fs_busname": self._tracker_wrapper.props.miner_fs_busname,
-            "media_type": int(Grl.MediaType.AUDIO),
-            'location_filter': self._tracker_wrapper.location_filter(),
-            "songs_filter": songs_filter
-        }
+            }}
+        }}
+        """.split())
 
         return query
 


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