[gnome-music] query: Add query for playlists



commit 4462d98cb6ff09a1f039dba287cc9e764645a79a
Author: Arnel Borja <arnelborja src gnome org>
Date:   Thu May 29 20:13:24 2014 +0800

    query: Add query for playlists

 gnomemusic/query.py |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index 87ecf87..eed0387 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -49,6 +49,10 @@ class Query():
         return Query.songs('?song a nmm:MusicPiece ; a nfo:FileDataObject .')
 
     @staticmethod
+    def all_playlists():
+        return Query.playlists('?playlist a nmm:Playlist .')
+
+    @staticmethod
     def all_songs_count():
         query = '''
     SELECT
@@ -402,6 +406,42 @@ class Query():
         return query
 
     @staticmethod
+    def playlists(where_clause):
+        query = '''
+    SELECT DISTINCT
+        rdf:type(?playlist)
+        tracker:id(?playlist) AS id
+        nie:title(?playlist) AS title
+        nfo:entryCounter(?playlist) AS childcount
+        {
+            %(where_clause)s
+            OPTIONAL {
+                ?playlist a nfo:FileDataObject .
+                FILTER (
+                    EXISTS {
+                        ?playlist tracker:available 'true'
+                        FILTER (
+                            tracker:uri-is-descendant(
+                                '%(music_dir)s', nie:url(?playlist)
+                            ) ||
+                            tracker:uri-is-descendant(
+                                '%(download_dir)s', nie:url(?playlist)
+                            )
+                        )
+                    }
+                )
+            }
+        }
+    ORDER BY fn:lower-case(?title) ?author ?albumyear
+    '''.replace('\n', ' ').strip() % {
+            'where_clause': where_clause.replace('\n', ' ').strip(),
+            'music_dir': Query.MUSIC_DIR,
+            'download_dir': Query.DOWNLOAD_DIR
+        }
+
+        return query
+
+    @staticmethod
     def album_songs(album_id):
         query = '''
     SELECT DISTINCT


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