[gnome-music] query: Handle optional album-artist
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] query: Handle optional album-artist
- Date: Mon, 21 Nov 2016 13:49:18 +0000 (UTC)
commit 0998001952f679963740270eca1e721a656f15e4
Author: Marinus Schraal <mschraal src gnome org>
Date: Fri Nov 4 09:17:46 2016 +0100
query: Handle optional album-artist
Most tracker extractors were filling the album-artist field with some
form of album-artist/performer/artist, which made this field nearly
always available. Instead tracker should now only expose fields that are
available (https://bugzilla.gnome.org/show_bug.cgi?id=773697) and as a
consequence music should treat album-artist as an optional component in
it's queries.
https://bugzilla.gnome.org/show_bug.cgi?id=774260
configure.ac | 2 +-
gnomemusic/query.py | 58 +++++++++++++++++++++-----------------------------
2 files changed, 25 insertions(+), 35 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 35ff11c..72d8121 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,7 +38,7 @@ PKG_CHECK_MODULES(MEDIAART, [libmediaart-2.0])
PYGOBJECT_MIN_VERSION=3.21.1
PKG_CHECK_MODULES(PYGOBJECT, [pygobject-3.0 >= $PYGOBJECT_MIN_VERSION])
-TRACKER_MIN_VERSION=1.9.0
+TRACKER_MIN_VERSION=1.11.0
PKG_CHECK_MODULES(TRACKER, [tracker-sparql-1.0 >= $TRACKER_MIN_VERSION])
GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index 399fbcb..368913e 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -151,22 +151,22 @@ class Query():
?song a nmm:MusicPiece ;
nmm:musicAlbum ?album ;
nmm:performer ?performer .
- ?album nmm:albumArtist ?albumArtist ;
- nie:title ?title .
- BIND(LCASE(?title) AS ?title_lower) .
- BIND(LCASE(nmm:artistName(?albumArtist)) AS ?artist_lower) .
- BIND((%(album_order)s) AS ?album_collation) .
- BIND((%(artist_order)s) AS ?artist_collation) .
+ ?album nie:title ?title .
+ OPTIONAL { ?album nmm:albumArtist ?albumArtist . }
OPTIONAL { ?song nmm:composer ?composer . }
+ BIND(tracker:coalesce(nmm:artistName(?albumArtist),
+ nmm:artistName(?performer)) AS ?artist_presort)
+ BIND(LCASE(?title) AS ?title_lower)
+ BIND((%(album_order)s) AS ?album_collation)
FILTER(STRSTARTS(nie:url(?song), '%(music_dir)s/'))
}
GROUP BY ?album
- ORDER BY ?album_collation ?artist_collation ?creation_date
+ ORDER BY ?album_collation (%(artist_sort)s) ?creation_date
""".replace('\n', ' ').strip() % {
'where_clause': where_clause.replace('\n', ' ').strip(),
'music_dir': Query.MUSIC_URI,
'album_order': Query._order_by_statement("?title_lower"),
- 'artist_order': Query._order_by_statement("?artist_lower"),
+ 'artist_sort': Query._order_by_statement("?artist_presort"),
}
return query
@@ -185,22 +185,22 @@ class Query():
{
%(where_clause)s
?album a nmm:MusicAlbum ;
- nmm:albumArtist ?albumArtist ;
nie:title ?title .
?song nmm:musicAlbum ?album ;
nmm:performer ?performer .
- BIND(LCASE(nmm:artistName(?albumArtist)) AS ?artist_lower) .
- BIND(LCASE(?title) AS ?title_lower) .
- BIND((%(artist_order)s) AS ?artist_collation) .
- BIND((%(album_order)s) AS ?title_collation) .
+ OPTIONAL { ?album nmm:albumArtist ?albumArtist }
+ BIND(tracker:coalesce(nmm:artistName(?albumArtist),
+ nmm:artistName(?performer)) AS ?artist_presort)
+ BIND(LCASE(?title) AS ?title_lower)
+ BIND((%(album_order)s) AS ?title_collation)
FILTER(STRSTARTS(nie:url(?song), '%(music_dir)s/'))
}
GROUP BY ?album
- ORDER BY ?artist_collation ?creation_date ?album_collation
+ ORDER BY (%(artist_sort)s) ?creation_date ?album_collation
""".replace('\n', ' ').strip() % {
'where_clause': where_clause.replace('\n', ' ').strip(),
'music_dir': Query.MUSIC_URI,
- 'artist_order': Query._order_by_statement("?artist_lower"),
+ 'artist_sort': Query._order_by_statement("?artist_presort"),
'album_order': Query._order_by_statement("?title_lower")
}
@@ -225,8 +225,6 @@ class Query():
nmm:musicAlbum ?album ;
nmm:performer ?performer ;
nie:url ?url .
- ?album nmm:albumArtist ?albumArtist ;
- nie:title ?title .
OPTIONAL { ?song nao:hasTag ?tag .
FILTER (?tag = nao:predefined-tag-favorite) } .
FILTER(STRSTARTS(?url, '%(music_dir)s/'))
@@ -353,17 +351,14 @@ class Query():
SELECT DISTINCT
rdf:type(?album)
tracker:id(?album) AS ?id
- (
- SELECT
- nmm:artistName(?album_artist)
- WHERE {
- ?album nmm:albumArtist ?album_artist
- }
- LIMIT 1
- ) AS ?artist
+ nmm:artistName(?album_artist) AS ?artist
nie:title(?album) AS ?album
WHERE {
?album a nmm:MusicAlbum .
+ ?song a nmm:MusicPiece ;
+ nmm:musicAlbum ?album ;
+ nmm:performer ?song_artist .
+ OPTIONAL { ?album nmm:albumArtist ?album_artist . }
FILTER (
tracker:id(?album) = %(album_id)s
)
@@ -381,18 +376,13 @@ class Query():
SELECT DISTINCT
rdf:type(?album)
tracker:id(?album) AS ?id
- (
- SELECT
- nmm:artistName(?album_artist)
- WHERE {
- ?album nmm:albumArtist ?album_artist
- }
- LIMIT 1
- ) AS ?artist
+ nmm:artistName(?album_artist) AS ?artist
nie:title(?album) AS ?album
WHERE {
?song a nmm:MusicPiece ;
- nmm:musicAlbum ?album .
+ nmm:musicAlbum ?album ;
+ nmm:performer ?song_artist .
+ OPTIONAL { ?album nmm:albumArtist ?album_artist . }
FILTER (
tracker:id(?song) = %(song_id)s
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]