[gnome-music/wip/mschraal/core: 68/208] split disc try
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/core: 68/208] split disc try
- Date: Thu, 4 Jul 2019 15:39:19 +0000 (UTC)
commit 1dcb3fa8fd99e4c54328b08f9c77895d32958e90
Author: Marinus Schraal <mschraal gnome org>
Date: Sat Jun 1 00:03:55 2019 +0200
split disc try
gnomemusic/coregrilo.py | 7 ++++
gnomemusic/coremodel.py | 57 +++++++++++++++++++++-----
gnomemusic/grilowrappers/grltrackersource.py | 61 ++++++++++++++++++++++++++++
gnomemusic/widgets/albumwidget2.py | 10 ++---
4 files changed, 120 insertions(+), 15 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 9b627adf..b8d5be7e 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -53,3 +53,10 @@ class CoreGrilo(GObject.GObject):
# FIXME: Iterate the wrappers
print(self._tracker_source)
return self._tracker_source.get_artist_albums(artist)
+
+ def get_album_disc_numbers(self, media):
+ 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)
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 34f92ef0..179d8239 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -44,33 +44,70 @@ class CoreModel(GObject.GObject):
@log
def get_album_model(self, media):
- albums_ids = []
+ discs = self._grilo.get_album_disc_numbers(media)
+
+ disc_list = []
+ for disc in discs:
+ nr = disc.get_album_disc_number()
+ model_filter = Dazzle.ListModelFilter.new(self._model)
+ model_filter.set_filter_func(lambda a: False)
+ disc_list.append(model_filter)
+ self.get_album_disc(media, nr, model_filter)
+
+ return disc_list
+
+ # albums_ids = []
- model_filter = Dazzle.ListModelFilter.new(self._model)
+ # model_filter = Dazzle.ListModelFilter.new(self._model)
# model_filter = Gfm.FilterListModel.new(self._model)
- model_filter.set_filter_func(lambda a: False)
- model_sort = Gfm.SortListModel.new_for_type(CoreSong)
+ # model_filter.set_filter_func(lambda a: False)
+ # model_sort = Gfm.SortListModel.new_for_type(CoreSong)
+
+ # def _filter_func(core_song):
+ # return core_song.props.media.get_id() in albums_ids
+
+ # def _reverse_sort(song_a, song_b, data=None):
+ # return song_b.props.track_number - song_a.props.track_number
+
+ # def _callback(source, dunno, media, something, something2):
+ # if media is None:
+ # model_filter.set_filter_func(_filter_func)
+ # model_sort.set_model(model_filter)
+ # model_sort.set_sort_func(
+ # self._wrap_list_store_sort_func(_reverse_sort))
+ # return
+
+ # albums_ids.append(media.get_id())
+
+ # For POC sake, use old grilo
+ # grilo.populate_album_songs(media, _callback)
+
+ # return model_sort
+
+ def get_album_disc(self, media, discnr, model):
+ albums_ids = []
+ model_filter = model
def _filter_func(core_song):
return core_song.props.media.get_id() in albums_ids
def _reverse_sort(song_a, song_b, data=None):
- return song_b.props.track_number - song_a.props.track_number
+ return song_a.props.track_number - song_b.props.track_number
def _callback(source, dunno, media, something, something2):
if media is None:
model_filter.set_filter_func(_filter_func)
- model_sort.set_model(model_filter)
- model_sort.set_sort_func(
- self._wrap_list_store_sort_func(_reverse_sort))
+ # model_sort.set_model(model_filter)
+ # model_sort.set_sort_func(
+ # self._wrap_list_store_sort_func(_reverse_sort))
return
albums_ids.append(media.get_id())
# For POC sake, use old grilo
- grilo.populate_album_songs(media, _callback)
+ self._grilo.populate_album_disc_songs(media, discnr, _callback)
- return model_sort
+ return model_filter
@log
def get_albums_model(self):
diff --git a/gnomemusic/grilowrappers/grltrackersource.py b/gnomemusic/grilowrappers/grltrackersource.py
index 1af22b3b..61220b7c 100644
--- a/gnomemusic/grilowrappers/grltrackersource.py
+++ b/gnomemusic/grilowrappers/grltrackersource.py
@@ -252,3 +252,64 @@ class GrlTrackerSource(GObject.GObject):
print("ALBUMS", albums)
return albums
+
+ def get_album_disc_numbers(self, media):
+ album_id = media.get_id()
+ print("album id ", album_id)
+
+ query = """
+ SELECT DISTINCT
+ rdf:type(?song)
+ nmm:setNumber(nmm:musicAlbumDisc(?song)) as ?album_disc_number
+ WHERE
+ {
+ ?song a nmm:MusicPiece;
+ nmm:musicAlbum ?album .
+ FILTER ( tracker:id(?album) = %(album_id)s )
+ }
+ """.replace('\n', ' ').strip() % {
+ 'album_id': int(album_id)
+ }
+
+ options = self._fast_options.copy()
+
+ discs = self._source.query_sync(query, self.METADATA_KEYS, options)
+
+ print("DISCS", discs)
+
+ return discs
+
+ def populate_album_disc_songs(self, media, disc_nr, _callback):
+ album_id = media.get_id()
+
+ query = """
+ SELECT DISTINCT
+ rdf:type(?song)
+ ?song AS ?tracker_urn
+ 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
+ nmm:trackNumber(?song) AS ?track_number
+ nmm:setNumber(nmm:musicAlbumDisc(?song)) AS ?album_disc_number
+ ?tag AS ?favourite
+ nie:usageCounter(?song) AS ?play_count
+ WHERE
+ {
+ ?song a nmm:MusicPiece ;
+ nmm:musicAlbum ?album .
+ OPTIONAL { ?song nao:hasTag ?tag .
+ FILTER (?tag = nao:predefined-tag-favorite) } .
+ FILTER ( tracker:id(?album) = %(album_id)s
+ && nmm:setNumber(nmm:musicAlbumDisc(?song)) = %(disc_nr)s )
+ }
+ """.replace('\n', ' ').strip() % {
+ 'album_id': album_id,
+ 'disc_nr': disc_nr,
+ }
+
+ options = self._fast_options.copy()
+
+ self._source.query(query, self.METADATA_KEYS, options, _callback)
diff --git a/gnomemusic/widgets/albumwidget2.py b/gnomemusic/widgets/albumwidget2.py
index d3385279..24a4c8fe 100644
--- a/gnomemusic/widgets/albumwidget2.py
+++ b/gnomemusic/widgets/albumwidget2.py
@@ -85,7 +85,7 @@ class AlbumWidget2(Gtk.EventBox):
self._album = album
self._model = self._parent_view._window._app._coremodel.get_album_model(album)
- self._listbox.bind_model(self._model, self._create_widget)
+ self._listbox.bind_model(self._model[0], self._create_widget)
@log
def _create_widget(self, song):
@@ -126,7 +126,7 @@ class AlbumWidget2(Gtk.EventBox):
@log
def _set_duration_label(self):
total_duration = 0
- for song in self._model:
+ for song in self._model[0]:
total_duration += song.props.duration
mins = (total_duration // 60) + 1
@@ -150,9 +150,9 @@ class AlbumWidget2(Gtk.EventBox):
GObject.TYPE_INT
)
- for song in self._model:
+ for song in self._model[0]:
_iter = old_model.insert_with_valuesv(-1, [5], [song.props.media])
- if song is self._model[listboxrow.get_index()]:
+ if song is self._model[0][listboxrow.get_index()]:
activated_iter = _iter
listboxrow.get_child().props.state = SongWidget.State.PLAYING
@@ -164,7 +164,7 @@ class AlbumWidget2(Gtk.EventBox):
@log
def _on_selection_changed(self, klass, value):
n_items = 0
- for song in self._model:
+ for song in self._model[0]:
if song.props.selected:
n_items += 1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]