[gnome-music/wip/mschraal/lastfm-scrobble-prop: 1/2] scrobbler: Add scrobbled property



commit c399f0fbfb1f305117f35ca0eaff79b8c36985af
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Jan 10 00:26:59 2018 +0100

    scrobbler: Add scrobbled property
    
    Add a scrobbled property keeping track of the scrobbled status of the
    current song. This removes the need of having a variable in the Player
    class.

 gnomemusic/player.py    |  5 ++---
 gnomemusic/scrobbler.py | 25 +++++++++++++++++++++----
 2 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 059124f..ddd3698 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -928,7 +928,6 @@ class Player(GObject.GObject):
     def _set_duration(self, duration):
         self.duration = duration
         self.played_seconds = 0
-        self._scrobbled = False
         self.progressScale.set_range(0.0, duration * 60)
 
     @log
@@ -948,9 +947,9 @@ class Player(GObject.GObject):
             self.played_seconds += self.seconds_period / 1000
             try:
                 percentage = self.played_seconds / self.duration
-                if not self._scrobbled and percentage > 0.4:
+                if (not self._lastfm.scrobbled
+                        and percentage > 0.4):
                     current_media = self.get_current_media()
-                    self._scrobbled = True
                     if current_media:
                         # FIXME: we should not need to update static
                         # playlists here but removing it may introduce
diff --git a/gnomemusic/scrobbler.py b/gnomemusic/scrobbler.py
index 3d06e95..2a81e58 100644
--- a/gnomemusic/scrobbler.py
+++ b/gnomemusic/scrobbler.py
@@ -22,12 +22,13 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
-import gi
-
 from hashlib import md5
+from threading import Thread
 import logging
 import requests
-from threading import Thread
+
+import gi
+from gi.repository import GObject
 
 from gnomemusic import log
 import gnomemusic.utils as utils
@@ -36,7 +37,7 @@ import gnomemusic.utils as utils
 logger = logging.getLogger(__name__)
 
 
-class LastFmScrobbler():
+class LastFmScrobbler(GObject.GObject):
     """Scrobble songs to Last.fm"""
 
     def __repr__(self):
@@ -44,9 +45,21 @@ class LastFmScrobbler():
 
     @log
     def __init__(self):
+        super().__init__()
+
+        self._scrobbled = False
         self._authentication = None
         self._connect()
 
+    @GObject.Property(type=bool, default=False)
+    def scrobbled(self):
+        """Bool indicating current scrobble status"""
+        return self._scrobbled
+
+    @scrobbled.setter
+    def scrobbled(self, scrobbled):
+        self._scrobbled = scrobbled
+
     def _connect(self):
         """Connect to Last.fm using gnome-online-accounts"""
         try:
@@ -112,6 +125,8 @@ class LastFmScrobbler():
         :param media: Grilo media item
         :param time_stamp: song loaded time (epoch time)
         """
+        self.scrobbled = True
+
         if self._authentication is None:
             return
 
@@ -162,6 +177,8 @@ class LastFmScrobbler():
 
         :param media: Grilo media item
         """
+        self.scrobbled = False
+
         if self._authentication is None:
             return
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]