[gnome-music/wip/merge: 34/343] query: Port from JavaScript to Python
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/merge: 34/343] query: Port from JavaScript to Python
- Date: Thu, 25 Jul 2013 11:16:22 +0000 (UTC)
commit fdc29065788810f97c0acd11f16d94fb73c15858
Author: Arnel A. Borja <arnelborja src gnome org>
Date: Sat Jul 13 21:40:48 2013 +0800
query: Port from JavaScript to Python
Port of query.js to query.py. Fix calls in view.py to this source.
gnome-music/query.py | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++
gnome-music/view.py | 8 +-
2 files changed, 222 insertions(+), 4 deletions(-)
---
diff --git a/gnome-music/query.py b/gnome-music/query.py
new file mode 100644
index 0000000..9814347
--- /dev/null
+++ b/gnome-music/query.py
@@ -0,0 +1,218 @@
+class Query():
+
+ ALBUMS = """
+SELECT DISTINCT
+ rdf:type(?album)
+ tracker:id(?album) AS id
+ (
+ SELECT
+ nmm:artistName(?artist)
+ WHERE {
+ ?album nmm:albumArtist ?artist
+ }
+ LIMIT 1
+ ) AS artist
+ nie:title(?album) AS title
+ nie:title(?album) AS album
+ tracker:coalesce(
+ (
+ SELECT
+ GROUP_CONCAT(
+ nmm:artistName(?artist),
+ ","
+ )
+ WHERE {
+ ?album nmm:albumArtist ?artist
+ }
+ ),
+ (
+ SELECT
+ GROUP_CONCAT(
+ (
+ SELECT
+ nmm:artistName(nmm:performer(?_12)) AS perf
+ WHERE {
+ ?_12 nmm:musicAlbum ?album
+ }
+ GROUP BY ?perf
+ ),
+ ","
+ ) AS album_performer
+ WHERE {
+ }
+ )
+ ) AS author
+ xsd:integer(
+ tracker:coalesce(
+ nmm:albumTrackCount(?album),
+ (
+ SELECT
+ COUNT(?_1)
+ WHERE {
+ ?_1 nmm:musicAlbum ?album ;
+ tracker:available "true"
+ }
+ )
+ )
+ ) AS childcount
+ (
+ SELECT
+ fn:year-from-dateTime(?c)
+ WHERE {
+ ?_2 nmm:musicAlbum ?album ;
+ nie:contentCreated ?c ;
+ tracker:available "true"
+ }
+ LIMIT 1
+ ) AS creation-date
+ {
+ ?album a nmm:MusicAlbum .
+ FILTER (
+ EXISTS {
+ ?_3 nmm:musicAlbum ?album ;
+ tracker:available "true"
+ }
+ )
+ }
+ORDER BY nie:title(?album) ?author ?albumyear
+"""
+
+ ALBUMS_COUNT = """
+SELECT
+ COUNT(?album) AS childcount
+WHERE {
+ ?album a nmm:MusicAlbum
+}
+"""
+
+ ARTISTS = """
+SELECT DISTINCT
+ rdf:type(?album)
+ tracker:id(?album) AS id
+ (
+ SELECT
+ nmm:artistName(?artist)
+ WHERE {
+ ?album nmm:albumArtist ?artist
+ }
+ LIMIT 1
+ ) AS artist
+ nie:title(?album) AS title
+ nie:title(?album) AS album
+ tracker:coalesce(
+ (
+ SELECT
+ GROUP_CONCAT(
+ nmm:artistName(?artist),
+ ","
+ )
+ WHERE {
+ ?album nmm:albumArtist ?artist
+ }
+ ),
+ (
+ SELECT
+ GROUP_CONCAT(
+ (
+ SELECT
+ nmm:artistName(nmm:performer(?_12)) AS perf
+ WHERE {
+ ?_12 nmm:musicAlbum ?album
+ }
+ GROUP BY ?perf
+ ),
+ ","
+ ) AS album_performer
+ WHERE {
+ }
+ )
+ ) AS author
+ xsd:integer(
+ tracker:coalesce(
+ nmm:albumTrackCount(?album),
+ (
+ SELECT
+ COUNT(?_1)
+ WHERE {
+ ?_1 nmm:musicAlbum ?album ;
+ tracker:available "true"
+ }
+ )
+ )
+ ) AS childcount
+ (
+ SELECT
+ fn:year-from-dateTime(?c)
+ WHERE {
+ ?_2 nmm:musicAlbum ?album ;
+ nie:contentCreated ?c ;
+ tracker:available "true"
+ }
+ LIMIT 1
+ ) AS creation-date
+ {
+ ?album a nmm:MusicAlbum .
+ FILTER (
+ EXISTS {
+ ?_3 nmm:musicAlbum ?album ;
+ tracker:available "true"
+ }
+ )
+ }
+ORDER BY ?author ?albumyear nie:title(?album)
+"""
+
+ ARTISTS_COUNT = """
+SELECT
+ COUNT(DISTINCT ?artist)
+WHERE {
+ ?artist a nmm:Artist .
+ ?album nmm:performer ?artist
+}
+"""
+
+ SONGS = """
+SELECT DISTINCT
+ rdf:type(?song)
+ tracker:id(?song) AS id
+ nie:url(?song) AS url
+ nie:title(?song) AS title
+ nmm:artistName(nmm:performer(?song)) AS artist
+ nie:title(nmm:musicAlbum(?song)) AS album
+ nfo:duration(?song) AS duration
+ {
+ ?song a nmm:MusicPiece
+ }
+ORDER BY tracker:added(?song)
+"""
+
+ SONGS_COUNT = """
+SELECT
+ COUNT(?song) AS childcount
+WHERE {
+ ?song a nmm:MusicPiece
+}
+"""
+
+ @staticmethod
+ def album_songs(album_id):
+ query = """
+SELECT DISTINCT
+ rdf:type(?song)
+ tracker:id(?song) AS id
+ nie:url(?song) AS url
+ nie:title(?song) AS title
+ nmm:artistName(nmm:performer(?song)) AS artist
+ nie:title(nmm:musicAlbum(?song)) AS album
+ nfo:duration(?song) AS duration
+WHERE {
+ ?song a nmm:MusicPiece ;
+ nmm:musicAlbum ?album .
+ FILTER (
+ tracker:id(?album) = %(album_id)s
+ )
+}
+ORDER BY nmm:trackNumber(?song) tracker:added(?song)
+""" % {'album_id': album_id}
+
+ return query
diff --git a/gnome-music/view.py b/gnome-music/view.py
index eba56f0..03a54a1 100644
--- a/gnome-music/view.py
+++ b/gnome-music/view.py
@@ -1,7 +1,7 @@
from gi.repository import Gtk, GObject, Gd, Grl, Pango, GLib, GdkPixbuf
import grilo
import widgets as Widgets
-import query as Query
+from query import Query
import albumArtCache
import tracker
@@ -224,7 +224,7 @@ class Albums(ViewContainer):
def __init__(self, headerBar, selectionToolbar, player):
ViewContainer.__init__("Albums", headerBar, selectionToolbar)
self.view.set_view_type(Gd.MainViewType.ICON)
- self.countQuery = Query.album_count
+ self.countQuery = Query.ALBUMS_COUNT
self._albumWidget = Widgets.AlbumWidget(player)
self.add(self._albumWidget)
self.headerBar.setState(1)
@@ -253,7 +253,7 @@ class Albums(ViewContainer):
class Songs(ViewContainer):
def __init__(self, headerBar, selectionToolbar, player):
ViewContainer.__init__("Songs", headerBar, selectionToolbar)
- self.countQuery = Query.songs_count
+ self.countQuery = Query.SONGS_COUNT
self._items = {}
self.isStarred = None
self.view.set_view_type(Gd.MainViewType.LIST)
@@ -385,7 +385,7 @@ class Artists (ViewContainer):
ViewContainer.__init__("Artists", headerBar, selectionToolbar, True)
self.player = player
self._artists = {}
- self.countQuery = Query.artist_count
+ self.countQuery = Query.ARTISTS_COUNT
self._artistAlbumsWidget = Gtk.Frame(
shadow_type=Gtk.ShadowType.NONE
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]