[gnome-music/wip/smart_playlists: 5/5] Most Played playlist
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/smart_playlists: 5/5] Most Played playlist
- Date: Tue, 22 Apr 2014 15:41:08 +0000 (UTC)
commit cd37bcde92ab58e22fc331ecf462cfeb3f779947
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date: Tue Apr 22 17:40:26 2014 +0200
Most Played playlist
gnomemusic/query.py | 17 +++++++++++++++++
gnomemusic/view.py | 22 ++++++++++++++++++++--
2 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index 747548e..2a1cadf 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -251,6 +251,7 @@ class Query():
nmm:artistName(nmm:performer(?song)) AS artist
nie:title(nmm:musicAlbum(?song)) AS album
nfo:duration(?song) AS duration
+ nie:contentAccessed(?song) as date
WHERE {
?song a nmm:MusicPiece ;
a nfo:FileDataObject
@@ -258,6 +259,22 @@ class Query():
ORDER BY DESC(nie:contentAccessed(?song))
'''.replace('\n', ' ').strip()
+ MOST_PLAYED = '''
+ SELECT DISTINCT
+ rdf:type(?song)
+ 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
+ WHERE {
+ ?song a nmm:MusicPiece ;
+ a nfo:FileDataObject
+ }
+ ORDER BY ASC(nie:usageCounter(?song))
+ '''.replace('\n', ' ').strip()
+
@staticmethod
def album_songs(album_id):
query = '''
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 4fb5936..f444963 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -771,6 +771,11 @@ class Artists (ViewContainer):
class Playlist(ViewContainer):
playlists_list = playlists.get_playlists()
+ predefined_playlists = {
+ _("Recently Added"): Query.RECENTLY_ADDED,
+ _("Recently Played"): Query.RECENTLY_PLAYED,
+ _("Most Played"): Query.MOST_PLAYED
+ }
@log
def __init__(self, header_bar, selection_toolbar, player):
@@ -987,6 +992,19 @@ class Playlist(ViewContainer):
self.current_playlist = playlist
self.name_label.set_text(playlist)
+ if playlist in self.predefined_playlists:
+ # Playlists should be updated on each access
+ query = self.predefined_playlists[playlist]
+
+ def _add_predefined_playlist_cb(source, param, item, remaining):
+ if item and item.get_url():
+ self._on_song_added_to_playlist(None, playlist, item)
+
+ self._model.clear()
+ grilo.populate_items(query, 0, _add_predefined_playlist_cb)
+ self._update_songs_count()
+ return
+
# if the active queue has been set by this playlist,
# use it as model, otherwise build the liststore
cached_playlist = self.player.running_playlist('Playlist', playlist)
@@ -1165,8 +1183,8 @@ class Playlist(ViewContainer):
@log
def add_predefined_playlists(self):
- self.add_predefined_playlist(_("Recently Added"), Query.RECENTLY_ADDED)
- self.add_predefined_playlist(_("Recently Played"), Query.RECENTLY_PLAYED)
+ for playlist in self.predefined_playlists:
+ self._on_playlist_created(None, playlist)
@log
def add_predefined_playlist(self, name, query):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]