[gnome-music/wip/mschraal/core: 37/118] core/grilo groundwork for artist
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/core: 37/118] core/grilo groundwork for artist
- Date: Wed, 26 Jun 2019 13:03:07 +0000 (UTC)
commit 05601ce0f1752ebcdc6a778c532eda99c1671492
Author: Marinus Schraal <mschraal gnome org>
Date: Fri May 31 12:56:16 2019 +0200
core/grilo groundwork for artist
gnomemusic/coreartist.py | 27 +++++++++++++++++++++++
gnomemusic/coregrilo.py | 6 +++--
gnomemusic/coremodel.py | 5 ++++-
gnomemusic/grilowrappers/grltrackersource.py | 33 +++++++++++++++++++++++++++-
4 files changed, 67 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/coreartist.py b/gnomemusic/coreartist.py
new file mode 100644
index 00000000..5666123f
--- /dev/null
+++ b/gnomemusic/coreartist.py
@@ -0,0 +1,27 @@
+import gi
+gi.require_version('Grl', '0.3')
+from gi.repository import Grl, GObject
+
+from gnomemusic import log
+from gnomemusic.grilo import grilo
+import gnomemusic.utils as utils
+
+
+class CoreArtist(GObject.GObject):
+ """Exposes a Grl.Media with relevant data as properties
+ """
+
+ artist = GObject.Property(type=str)
+ media = GObject.Property(type=Grl.Media)
+ selected = GObject.Property(type=bool, default=False)
+
+ @log
+ def __init__(self, media):
+ super().__init__()
+
+ self.update(media)
+
+ @log
+ def update(self, media):
+ self.props.media = media
+ self.props.artist = utils.get_artist_name(media)
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 43bce9fd..a524593d 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -13,11 +13,12 @@ class CoreGrilo(GObject.GObject):
def __repr__(self):
return "<CoreGrilo>"
- def __init__(self, model, _hash, url_hash, albums_model):
+ def __init__(self, model, _hash, url_hash, albums_model, artists_model):
super().__init__()
self._model = model
self._albums_model = albums_model
+ self._artists_model = artists_model
self._hash = _hash
# Only way to figure out removed items
self._url_table = url_hash
@@ -40,7 +41,8 @@ class CoreGrilo(GObject.GObject):
print(source.props.source_id)
if source.props.source_id == "grl-tracker-source":
self._tracker_source = GrlTrackerSource(
- source, self._hash, self._model, self._albums_model)
+ source, self._hash, self._model, self._albums_model,
+ self._artists_model)
self._tracker_source = source
print(self._tracker_source, "added")
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 73b658f9..fd491c18 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -4,6 +4,7 @@ from gi.repository import Dazzle, GObject, Gio, Gfm
from gi._gi import pygobject_new_full
from gnomemusic import log
+from gnomemusic.coreartist import CoreArtist
from gnomemusic.coregrilo import CoreGrilo
from gnomemusic.coresong import CoreSong
from gnomemusic.grilo import grilo
@@ -18,12 +19,14 @@ class CoreModel(GObject.GObject):
self._test = Gfm.FilterListModel()
self._model = Gio.ListStore.new(CoreSong)
self._album_model = Gio.ListStore()
+ self._artist_model = Gio.ListStore.new(CoreArtist)
self._album_store = None
self._hash = {}
self._url_hash = {}
self._grilo = CoreGrilo(
- self._model, self._hash, self._url_hash, self._album_model)
+ self._model, self._hash, self._url_hash, self._album_model,
+ self._artist_model)
# self._grilo.connect("media-removed", self._on_media_removed)
@log
diff --git a/gnomemusic/grilowrappers/grltrackersource.py b/gnomemusic/grilowrappers/grltrackersource.py
index 22baf7ee..c371c18b 100644
--- a/gnomemusic/grilowrappers/grltrackersource.py
+++ b/gnomemusic/grilowrappers/grltrackersource.py
@@ -3,6 +3,7 @@ gi.require_version('Grl', '0.3')
from gi.repository import Grl, GObject
from gnomemusic.corealbum import CoreAlbum
+from gnomemusic.coreartist import CoreArtist
from gnomemusic.coresong import CoreSong
@@ -29,12 +30,13 @@ class GrlTrackerSource(GObject.GObject):
def __repr__(self):
return "<GrlTrackerSource>"
- def __init__(self, source, _hash, model, albums_model):
+ def __init__(self, source, _hash, model, albums_model, artists_model):
super().__init__()
self._source = source
self._model = model
self._albums_model = albums_model
+ self._artists_model = artists_model
self._hash = _hash
# self._table = table
# Only way to figure out removed items
@@ -52,6 +54,7 @@ class GrlTrackerSource(GObject.GObject):
self._initial_fill(self._source)
self._initial_albums_fill(self._source)
+ self._initial_artists_fill(self._source)
self._source.connect("content-changed", self._on_content_changed)
@@ -190,3 +193,31 @@ class GrlTrackerSource(GObject.GObject):
album = CoreAlbum(media)
self._albums_model.append(album)
+
+ def _initial_artists_fill(self, source):
+ query = """
+ SELECT
+ rdf:type(?artist_class)
+ tracker:id(?artist_class) AS ?id
+ nmm:artistName(?artist_class) AS ?artist
+ {
+ ?artist_class a nmm:Artist .
+ }
+ """.replace('\n', ' ').strip()
+
+ options = self._fast_options.copy()
+
+ source.query(
+ query, self.METADATA_KEYS, options, self._add_to_artists_model)
+
+ def _add_to_artists_model(self, source, op_id, media, user_data, error):
+ if error:
+ print("ERROR", error)
+ return
+
+ if not media:
+ print("NO MEDIA", source, op_id, media, error)
+ return
+
+ artist = CoreArtist(media)
+ self._artists_model.append(artist)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]