[gnome-music] Use Grilo key for bumping play count
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] Use Grilo key for bumping play count
- Date: Sat, 3 Dec 2016 13:04:32 +0000 (UTC)
commit 252083a98ac8d79841032ca4b180f6fd8b4497f7
Author: Marinus Schraal <mschraal src gnome org>
Date: Tue Nov 22 14:19:10 2016 +0100
Use Grilo key for bumping play count
Use Grilo set_play_count to bump the play count and store the metadata
through grilo.
gnomemusic/grilo.py | 15 +++++++++++++++
gnomemusic/player.py | 3 ++-
gnomemusic/playlists.py | 5 -----
gnomemusic/query.py | 23 +++--------------------
4 files changed, 20 insertions(+), 26 deletions(-)
---
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 7e016eb..0a90e01 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -60,6 +60,7 @@ class Grilo(GObject.GObject):
Grl.METADATA_KEY_FAVOURITE,
Grl.METADATA_KEY_ID,
Grl.METADATA_KEY_LYRICS,
+ Grl.METADATA_KEY_PLAY_COUNT,
Grl.METADATA_KEY_THUMBNAIL,
Grl.METADATA_KEY_TITLE,
Grl.METADATA_KEY_TRACK_NUMBER,
@@ -374,5 +375,19 @@ class Grilo(GObject.GObject):
self.tracker.query(query, self.METADATA_KEYS, options, callback, None)
+ @log
+ def bump_play_count(self, media):
+ """Bumps the play count of a song
+
+ Adds one to the playcount and adds it to the tracker store
+ :param media: A Grilo media item
+ """
+ count = media.get_play_count()
+ media.set_play_count(count + 1)
+
+ # FIXME: We assume this is the tracker plugin.
+ # FIXME: Doing this async crashes
+ self.tracker.store_metadata_sync(media, [Grl.METADATA_KEY_PLAY_COUNT],
+ Grl.WriteFlags.NORMAL)
grilo = Grilo()
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index decec10..da5004a 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -43,6 +43,7 @@ from gettext import gettext as _, ngettext
from random import randint
from collections import deque
from gnomemusic.albumartcache import AlbumArtCache, DefaultIcon, ArtSize
+from gnomemusic.grilo import grilo
from gnomemusic.playlists import Playlists
import gnomemusic.utils as utils
playlists = Playlists.get_default()
@@ -916,7 +917,6 @@ class Player(GObject.GObject):
@log
def scrobble_song(self, url):
# Update playlists
- playlists.update_playcount(url)
playlists.update_last_played(url)
playlists.update_all_static_playlists()
@@ -992,6 +992,7 @@ class Player(GObject.GObject):
current_media = self.get_current_media()
self.scrobbled = True
if current_media:
+ grilo.bump_play_count(self.get_current_media())
just_played_url = self.get_current_media().get_url()
t = Thread(target=self.scrobble_song, args=(just_played_url,))
t.setDaemon(True)
diff --git a/gnomemusic/playlists.py b/gnomemusic/playlists.py
index 2a7f5cc..b79d6fb 100644
--- a/gnomemusic/playlists.py
+++ b/gnomemusic/playlists.py
@@ -236,11 +236,6 @@ class Playlists(GObject.GObject):
tag_created_cb, playlist)
@log
- def update_playcount(self, song_url):
- query = Query.update_playcount(song_url)
- self.tracker.update(query, GLib.PRIORITY_LOW, None)
-
- @log
def update_last_played(self, song_url):
cur_time = time.strftime(sparql_dateTime_format, time.gmtime())
query = Query.update_last_played(song_url, cur_time)
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index 9221b4a..b5947b5 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -216,6 +216,7 @@ class Query():
nie:title(nmm:musicAlbum(?song)) AS ?album
nfo:duration(?song) AS ?duration
?tag AS ?favourite
+ nie:usageCounter(?song) AS ?play_count
{
%(where_clause)s
?song a nmm:MusicPiece ;
@@ -274,6 +275,7 @@ class Query():
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 ;
a nfo:FileDataObject ;
@@ -307,6 +309,7 @@ class Query():
nie:title(nmm:musicAlbum(?song)) AS ?album
nfo:duration(?song) AS ?duration
?tag AS ?favourite
+ nie:usageCounter(?song) AS ?play_count
WHERE {
?playlist a nmm:Playlist ;
a nfo:MediaList ;
@@ -405,26 +408,6 @@ class Query():
return query
@staticmethod
- def update_playcount(song_url):
- query = """
- INSERT OR REPLACE { ?song nie:usageCounter ?playcount . }
- WHERE {
- SELECT
- IF(bound(?usage), (?usage + 1), 1) AS ?playcount
- ?song
- WHERE {
- ?song a nmm:MusicPiece .
- OPTIONAL { ?song nie:usageCounter ?usage . }
- FILTER ( nie:url(?song) = "%(song_url)s" )
- }
- }
- """.replace("\n", " ").strip() % {
- 'song_url': song_url
- }
-
- return query
-
- @staticmethod
def update_last_played(song_url, time):
query = """
INSERT OR REPLACE { ?song nfo:fileLastAccessed '%(time)s' . }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]