[gnome-music] grilo: Move is_audio query to query.py



commit d2b5898f77b1cb4b8ec9d98316dc842800af2843
Author: Marinus Schraal <mschraal src gnome org>
Date:   Wed Nov 2 13:16:33 2016 +0100

    grilo: Move is_audio query to query.py

 gnomemusic/grilo.py |    9 +++++----
 gnomemusic/query.py |   16 ++++++++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 0975b57..b71d568 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -130,10 +130,11 @@ class Grilo(GObject.GObject):
                     media_id = media.get_id()
                     if changeType == Grl.SourceChangeType.ADDED:
                         # Check that this media is an audio file
-                        query = "select DISTINCT rdf:type nie:mimeType(?urn) as mime-type" +\
-                                " { ?urn rdf:type nie:InformationElement . FILTER (tracker:id(?urn) = %s) }" 
% media_id
-                        mimeType = grilo.tracker.query_sync(query, [Grl.METADATA_KEY_MIME], 
grilo.options)[0].get_mime()
-                        if mimeType and mimeType.startswith("audio"):
+                        mime_type = grilo.tracker.query_sync(
+                            Query.is_audio(media_id),
+                            [Grl.METADATA_KEY_MIME],
+                            grilo.options)[0].get_mime()
+                        if mime_type and mime_type.startswith("audio"):
                             self.changed_media_ids.append(media_id)
                     if changeType == Grl.SourceChangeType.REMOVED:
                         # There is no way to check that removed item is a media
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index a660ee0..380a798 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -1033,3 +1033,19 @@ class Query():
         }
 
         return query
+
+    @staticmethod
+    def is_audio(media_id):
+        query = """
+            SELECT DISTINCT
+            rdf:type
+            nie:mimeType(?urn) AS mime_type
+            {
+                ?urn rdf:type nie:InformationElement .
+                FILTER ( tracker:id(?urn) = "%(media_id)s" )
+            }
+        """.replace('\n', '').strip() % {
+            'media_id' : media_id
+        }
+
+        return query


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