[gnome-music] search: Add composer search
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] search: Add composer search
- Date: Wed, 2 Nov 2016 13:37:50 +0000 (UTC)
commit 50945727f8fa7a6844e65a9ef85e6daf0862d67d
Author: Marinus Schraal <mschraal src gnome org>
Date: Mon Oct 31 00:22:24 2016 +0100
search: Add composer search
Add a composer search for the local provider.
This is a bit different from the other searches, since it doesn't have a
corresponding view. So we only search the categories we have a view for
(albums/artists/songs).
https://bugzilla.gnome.org/show_bug.cgi?id=705094
gnomemusic/query.py | 36 ++++++++++++++++++++++++++++++++++++
gnomemusic/searchbar.py | 1 +
gnomemusic/views/searchview.py | 22 +++++++++++++++-------
3 files changed, 52 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index b145d8f..399fbcb 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -866,6 +866,18 @@ class Query():
return Query.albums(query)
@staticmethod
+ def get_albums_with_composer_match(name):
+ name = Tracker.sparql_escape_string(name)
+ query = """
+ ?song nmm:composer ?composer .
+ ?composer fts:match '"nmm:artistName" : %(name)s*' .
+ """.replace('\n', ' ').strip() % {
+ 'name': name
+ }
+
+ return Query.albums(query)
+
+ @staticmethod
def get_albums_with_track_match(name):
name = Tracker.sparql_escape_string(name)
query = """?song fts:match '"nie:title" : %(name)s*' . """.replace('\n', ' ').strip() % {'name':
name}
@@ -913,6 +925,18 @@ class Query():
return Query.artists(query)
@staticmethod
+ def get_artists_with_composer_match(name):
+ name = Tracker.sparql_escape_string(name)
+ query = """
+ ?song nmm:composer ?composer .
+ ?composer fts:match '"nmm:artistName" : %(name)s*' .
+ """.replace('\n', ' ').strip() % {
+ 'name': name
+ }
+
+ return Query.artists(query)
+
+ @staticmethod
def get_artists_with_track_match(name):
name = Tracker.sparql_escape_string(name)
query = """?song fts:match '"nie:title" : %(name)s*' . """.replace('\n', ' ').strip() % {'name':
name}
@@ -960,6 +984,18 @@ class Query():
return Query.songs(query)
@staticmethod
+ def get_songs_with_composer_match(name):
+ name = Tracker.sparql_escape_string(name)
+ query = """
+ ?song nmm:composer ?composer .
+ ?composer fts:match '"nmm:artistName" : %(name)s*' .
+ """.replace('\n', ' ').strip() % {
+ 'name': name
+ }
+
+ return Query.songs(query)
+
+ @staticmethod
def get_songs_with_track_match(name):
name = Tracker.sparql_escape_string(name)
query = """?song fts:match '"nie:title" : %(name)s*' . """.replace('\n', ' ').strip() % {'name':
name}
diff --git a/gnomemusic/searchbar.py b/gnomemusic/searchbar.py
index 897f63e..ae01ad9 100644
--- a/gnomemusic/searchbar.py
+++ b/gnomemusic/searchbar.py
@@ -62,6 +62,7 @@ class BaseManager:
['search_all', _("All"), ''],
['search_artist', _("Artist"), ''],
['search_album', _("Album"), ''],
+ ['search_composer', _("Composer"), ''],
['search_track', _("Track Title"), ''],
]
for value in self.values:
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index b9fb4cc..e7cbfa4 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -170,12 +170,14 @@ class SearchView(BaseView):
artist = utils.get_artist_name(item)
album = item.get_album() or _("Unknown Album")
+ composer = item.get_composer()
key = '%s-%s' % (artist, album)
if key not in self._albums:
self._albums[key] = Grl.Media()
self._albums[key].set_title(album)
self._albums[key].add_artist(artist)
+ self._albums[key].set_composer(composer)
self._albums[key].set_source(source.get_id())
self._albums[key].tracks = []
self._add_item(source, None, self._albums[key], 0, [self.model, 'album'])
@@ -218,6 +220,8 @@ class SearchView(BaseView):
title = utils.get_media_title(item)
item.set_title(title)
artist = utils.get_artist_name(item)
+ # FIXME: Can't be None in treemodel
+ composer = item.get_composer() or ""
group = 3
try:
@@ -232,26 +236,26 @@ class SearchView(BaseView):
if category == 'album':
_iter = self.model.insert_with_values(
self.head_iters[group], -1,
- [0, 2, 3, 4, 5, 9, 11],
+ [0, 2, 3, 4, 5, 9, 11, 13],
[str(item.get_id()), title, artist,
- self._loading_icon, item, 2, category])
+ self._loading_icon, item, 2, category, composer])
self.cache.lookup(item, ArtSize.small, self._on_lookup_ready, _iter)
elif category == 'song':
_iter = self.model.insert_with_values(
self.head_iters[group], -1,
- [0, 2, 3, 4, 5, 9, 11],
+ [0, 2, 3, 4, 5, 9, 11, 13],
[str(item.get_id()), title, artist,
self._loading_icon, item,
2 if source.get_id() != 'grl-tracker-source' \
- else bool(item.get_lyrics()), category])
+ else bool(item.get_lyrics()), category, composer])
self.cache.lookup(item, ArtSize.small, self._on_lookup_ready, _iter)
else:
if not artist.casefold() in self._artists:
_iter = self.model.insert_with_values(
self.head_iters[group], -1,
- [0, 2, 4, 5, 9, 11],
+ [0, 2, 4, 5, 9, 11, 13],
[str(item.get_id()), artist,
- self._loading_icon, item, 2, category])
+ self._loading_icon, item, 2, category, composer])
self.cache.lookup(item, ArtSize.small, self._on_lookup_ready,
_iter)
self._artists[artist.casefold()] = {'iter': _iter, 'albums': []}
@@ -400,18 +404,21 @@ class SearchView(BaseView):
'album': {
'search_all': Query.get_albums_with_any_match,
'search_artist': Query.get_albums_with_artist_match,
+ 'search_composer': Query.get_albums_with_composer_match,
'search_album': Query.get_albums_with_album_match,
'search_track': Query.get_albums_with_track_match,
},
'artist': {
'search_all': Query.get_artists_with_any_match,
'search_artist': Query.get_artists_with_artist_match,
+ 'search_composer': Query.get_artists_with_composer_match,
'search_album': Query.get_artists_with_album_match,
'search_track': Query.get_artists_with_track_match,
},
'song': {
'search_all': Query.get_songs_with_any_match,
'search_artist': Query.get_songs_with_artist_match,
+ 'search_composer': Query.get_songs_with_composer_match,
'search_album': Query.get_songs_with_album_match,
'search_track': Query.get_songs_with_track_match,
},
@@ -430,7 +437,8 @@ class SearchView(BaseView):
GObject.TYPE_INT,
GObject.TYPE_BOOLEAN,
GObject.TYPE_STRING, # type
- GObject.TYPE_INT
+ GObject.TYPE_INT,
+ GObject.TYPE_STRING, # composer
)
self.filter_model = self.model.filter_new(None)
self.filter_model.set_visible_func(self._filter_visible_func)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]