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




commit d5052100c3083f447b9082d1a7a46793d07cc3c7
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 e8579daf6..40f12aca9 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -406,7 +406,10 @@ class GrlTrackerWrapper(GObject.GObject):
         else:
             songs_filter = ""
 
-        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]