[gnome-music/wip/mschraal/core] coregrilo: Add writeback support
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/core] coregrilo: Add writeback support
- Date: Fri, 28 Jun 2019 23:14:33 +0000 (UTC)
commit 13e70d350eb6af4700bcbb93c309e77037455f85
Author: Marinus Schraal <mschraal gnome org>
Date: Fri Jun 28 23:12:37 2019 +0200
coregrilo: Add writeback support
gnomemusic/coregrilo.py | 56 ++++++++++++++++++++++------
gnomemusic/coremodel.py | 6 ++-
gnomemusic/coresong.py | 9 ++---
gnomemusic/grilowrappers/grldleynasource.py | 19 +++++++++-
gnomemusic/grilowrappers/grltrackersource.py | 12 ++++--
5 files changed, 78 insertions(+), 24 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 55134644..368d98da 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -1,6 +1,6 @@
import gi
gi.require_version('Grl', '0.3')
-from gi.repository import Grl, GObject
+from gi.repository import Grl, GLib, GObject
from gnomemusic.grilowrappers.grldleynasource import GrlDLeynaSource
from gnomemusic.grilowrappers.grltrackersource import GrlTrackerSource
@@ -19,6 +19,7 @@ class CoreGrilo(GObject.GObject):
self._coremodel = coremodel
self._coreselection = coreselection
self._model = model
+ self._wrappers = []
self._albums_model = albums_model
self._artists_model = artists_model
@@ -29,17 +30,22 @@ class CoreGrilo(GObject.GObject):
self._registry.connect('source-removed', self._on_source_removed)
def _on_source_added(self, registry, source):
- print("SOURCE", source.props.source_id[:10])
+ new_wrapper = None
+
if source.props.source_id == "grl-tracker-source":
- self._tracker_source = GrlTrackerSource(
+ new_wrapper = GrlTrackerSource(
source, self._model, self._albums_model,
- self._artists_model, self._coremodel, self._coreselection)
- print(self._tracker_source, "added")
+ self._artists_model, self._coremodel, self._coreselection,
+ self)
+ self._tracker_source = new_wrapper
elif source.props.source_id[:10] == "grl-dleyna":
- self._dleyna_source = GrlDLeynaSource(
+ new_wrapper = GrlDLeynaSource(
source, self._model, self._albums_model,
- self._artists_model, self._coremodel, self._coreselection)
- print(self._dleyna_source, "added")
+ self._artists_model, self._coremodel, self._coreselection,
+ self)
+
+ self._wrappers.append(new_wrapper)
+ print(new_wrapper, "added")
def _on_source_removed(self, registry, source):
# FIXME: Handle removing sources.
@@ -47,15 +53,41 @@ class CoreGrilo(GObject.GObject):
def get_artist_albums(self, artist):
# FIXME: Iterate the wrappers
- print(self._tracker_source)
return self._tracker_source.get_artist_albums(artist)
def get_album_disc_numbers(self, media):
+ # FIXME: Iterate the wrappers
return self._tracker_source.get_album_disc_numbers(media)
def populate_album_disc_songs(self, media, discnr, callback):
- self._tracker_source.populate_album_disc_songs(
- media, discnr, callback)
+ for wrapper in self._wrappers:
+ wrapper.populate_album_disc_songs(media, discnr, callback)
def populate_album_songs(self, media, callback):
- self._tracker_source.populate_album_songs(media, callback)
+ for wrapper in self._wrappers:
+ wrapper.populate_album_songs(media, callback)
+
+ def _store_metadata(self, source, media, key):
+ """Convenience function to store metadata
+
+ Wrap the metadata store call in a idle_add compatible form.
+ :param source: A Grilo source object
+ :param media: A Grilo media item
+ :param key: A Grilo metadata key
+ """
+ # FIXME: Doing this async crashes.
+ try:
+ source.store_metadata_sync(
+ media, [key], Grl.WriteFlags.NORMAL)
+ except GLib.Error as error:
+ # FIXME: Do not print.
+ print("Error {}: {}".format(error.domain, error.message))
+
+ return GLib.SOURCE_REMOVE
+
+ def writeback(self, media, key):
+ for wrapper in self._wrappers:
+ if media.get_source() == wrapper.source.props.source_id:
+ GLib.idle_add(
+ self._store_metadata, wrapper.props.source, media, key)
+ break
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index e182b7cc..f3b383e5 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -157,7 +157,8 @@ class CoreModel(GObject.GObject):
for disc in model:
for model_song in disc.props.model:
song = CoreSong(
- model_song.props.media, self._coreselection)
+ model_song.props.media, self._coreselection,
+ self._grilo)
self._playlist_model.append(song)
song.bind_property(
@@ -175,7 +176,8 @@ class CoreModel(GObject.GObject):
for disc in artist_album.model:
for model_song in disc.model:
song = CoreSong(
- model_song.props.media, self._coreselection)
+ model_song.props.media, self._coreselection,
+ self._grilo)
self._playlist_model.append(song)
song.bind_property(
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index 6dd5c03e..4650d2d0 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -3,7 +3,6 @@ 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
@@ -23,9 +22,10 @@ class CoreSong(GObject.GObject):
url = GObject.Property(type=str)
@log
- def __init__(self, media, coreselection):
+ def __init__(self, media, coreselection, grilo):
super().__init__()
+ self._grilo = grilo
self._coreselection = coreselection
self._favorite = False
self._selected = False
@@ -43,14 +43,13 @@ class CoreSong(GObject.GObject):
def favorite(self, favorite):
self._favorite = favorite
- # FIXME: I think some old code is triggering the signal and
- # going haywire. So just check if there is anything to update.
+ # FIXME: Circular trigger, can probably be solved more neatly.
old_fav = self.props.media.get_favourite()
if old_fav == self._favorite:
return
self.props.media.set_favourite(self._favorite)
- grilo.toggle_favorite(self.props.media, True)
+ self._grilo.writeback(self.props.media, Grl.METADATA_KEY_FAVOURITE)
@GObject.Property(type=bool, default=False)
def selected(self):
diff --git a/gnomemusic/grilowrappers/grldleynasource.py b/gnomemusic/grilowrappers/grldleynasource.py
index 5df3d546..76021a14 100644
--- a/gnomemusic/grilowrappers/grldleynasource.py
+++ b/gnomemusic/grilowrappers/grldleynasource.py
@@ -30,11 +30,12 @@ class GrlDLeynaSource(GObject.GObject):
def __init__(
self, source, model, albums_model, artists_model, coremodel,
- core_selection):
+ core_selection, grilo):
super().__init__()
self._coremodel = coremodel
self._core_selection = core_selection
+ self._grilo = grilo
self._source = source
self._model = model
self._albums_model = albums_model
@@ -57,6 +58,11 @@ class GrlDLeynaSource(GObject.GObject):
# self._source.connect("content-changed", self._on_content_changed)
+ @GObject.Property(
+ type=Grl.Source, default=None, flags=GObject.ParamFlags.READABLE)
+ def source(self):
+ return self._source
+
def _initial_artists_fill(self, source):
query = """
upnp:class derivedfrom 'object.container.person.musicArtist'
@@ -76,9 +82,18 @@ class GrlDLeynaSource(GObject.GObject):
print("NO MEDIA", source, op_id, media, error)
return
- artist = CoreArtist(media, self._coremodel)
+ artist = CoreArtist(media, self._coremodel, self._grilo)
artist.props.artist = media.get_title() + " (upnp)"
self._artists_model.append(artist)
print(
"ADDING DLNA ARTIST", media.get_title(), media.get_artist(),
media.get_id())
+
+ def get_artist_albums(self, artist):
+ pass
+
+ def populate_album_disc_songs(self, media, discnr, callback):
+ pass
+
+ def populate_album_songs(self, media, callback):
+ pass
diff --git a/gnomemusic/grilowrappers/grltrackersource.py b/gnomemusic/grilowrappers/grltrackersource.py
index 1cace357..09ab741d 100644
--- a/gnomemusic/grilowrappers/grltrackersource.py
+++ b/gnomemusic/grilowrappers/grltrackersource.py
@@ -32,11 +32,12 @@ class GrlTrackerSource(GObject.GObject):
def __init__(
self, source, model, albums_model, artists_model, coremodel,
- core_selection):
+ core_selection, grilo):
super().__init__()
self._coremodel = coremodel
self._core_selection = core_selection
+ self._grilo = grilo
self._source = source
self._model = model
self._albums_model = albums_model
@@ -60,6 +61,11 @@ class GrlTrackerSource(GObject.GObject):
self._source.connect("content-changed", self._on_content_changed)
+ @GObject.Property(
+ type=Grl.Source, default=None, flags=GObject.ParamFlags.READABLE)
+ def source(self):
+ return self._source
+
def _on_content_changed(self, source, medias, change_type, loc_unknown):
for media in medias:
if change_type == Grl.SourceChangeType.ADDED:
@@ -215,7 +221,7 @@ class GrlTrackerSource(GObject.GObject):
print("ALREADY ADDED")
return
- song = CoreSong(media, self._core_selection)
+ song = CoreSong(media, self._core_selection, self._grilo)
self._model.append(song)
self._hash[media.get_id()] = song
@@ -263,7 +269,7 @@ class GrlTrackerSource(GObject.GObject):
# print("NO MEDIA", source, op_id, media, error)
return
- song = CoreSong(media, self._core_selection)
+ song = CoreSong(media, self._core_selection, self._grilo)
self._model.append(song)
self._hash[media.get_id()] = song
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]