[gnome-music/wip/smart_playlists: 4/5] Store last access date and play count
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/smart_playlists: 4/5] Store last access date and play count
- Date: Tue, 22 Apr 2014 15:41:03 +0000 (UTC)
commit db72cbd947e38fde9a35562c5861b6e3bf4e2214
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date: Tue Apr 22 17:19:12 2014 +0200
Store last access date and play count
gnomemusic/grilo.py | 18 +++++++++++++-----
gnomemusic/query.py | 13 ++++++++-----
2 files changed, 21 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 9414caf..554c137 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -51,11 +51,13 @@ class Grilo(GObject.GObject):
Grl.METADATA_KEY_ARTIST, Grl.METADATA_KEY_ALBUM,
Grl.METADATA_KEY_DURATION,
Grl.METADATA_KEY_CREATION_DATE,
- Grl.METADATA_KEY_THUMBNAIL]
+ Grl.METADATA_KEY_THUMBNAIL,
+ Grl.METADATA_KEY_PLAY_COUNT
+ ]
METADATA_THUMBNAIL_KEYS = [
Grl.METADATA_KEY_ID,
- Grl.METADATA_KEY_THUMBNAIL,
+ Grl.METADATA_KEY_THUMBNAIL
]
CHANGED_MEDIA_MAX_ITEMS = 500
@@ -212,9 +214,15 @@ class Grilo(GObject.GObject):
@log
def update_play_data(self, url, data=None):
- # Update play time
- query = Query.set_last_played_for_url(url)
- tracker.update(query, 0, None)
+
+ # Fetch play count
+ def callback(source, param, item, count=0, data=None, error=None):
+ if item:
+ playCount = 1
+ playCount = item.get_play_count() + 1
+ tracker.update(Query.set_play_count_and_date_for_url(url, playCount), 0, None)
+
+ self.get_media_from_uri(url, callback)
Grl.init(None)
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index d4cbb1e..747548e 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -321,6 +321,7 @@ class Query():
nmm:artistName(nmm:performer(?song)) AS artist
nie:title(nmm:musicAlbum(?song)) AS album
nfo:duration(?song) AS duration
+ nie:usageCounter(?song) AS play-count
WHERE {
?song a nmm:MusicPiece .
FILTER (
@@ -332,11 +333,13 @@ class Query():
return query
@staticmethod
- def set_last_played_for_url(url):
+ def set_play_count_and_date_for_url(url, count):
date = datetime.now().isoformat()
query = '''
- DELETE { ?song nie:contentAccessed ?time }
- INSERT { ?song nie:contentAccessed '%(date)s'}
- WHERE { ?song nie:url '%(url)s' }
- '''.replace('\n', ' ').strip() % {'url': url, "date": date}
+ INSERT OR REPLACE {
+ ?song a nmm:MusicPiece, nfo:FileDataObject;
+ nie:usageCounter '%(count)s';
+ nie:contentAccessed '%(date)s'.
+ } WHERE { ?song nie:url '%(url)s' }
+ '''.replace('\n', ' ').strip() % {'url': url, "date": date, "count": count}
return query
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]