[gnome-music/wip/jfelder/lastfm-ui-v1: 31/35] schema: Add an option to enable Last.fm scrobbler



commit 95a438699461a6e374637b78a3289aaaaf6c8137
Author: Jean Felder <jfelder src gnome org>
Date:   Sat Jan 4 15:18:14 2020 +0100

    schema: Add an option to enable Last.fm scrobbler

 data/org.gnome.Music.gschema.xml |  5 +++++
 gnomemusic/player.py             |  2 +-
 gnomemusic/scrobbler.py          | 27 ++++++++++++++++++++++++---
 3 files changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/data/org.gnome.Music.gschema.xml b/data/org.gnome.Music.gschema.xml
index c54c9280..ae9c43ac 100644
--- a/data/org.gnome.Music.gschema.xml
+++ b/data/org.gnome.Music.gschema.xml
@@ -43,5 +43,10 @@
             <summary>Inhibit system suspend</summary>
             <description>Enables or disables inhibiting system suspend while playing music</description>
         </key>
+        <key type="b" name="lastfm-report">
+            <default>false</default>
+            <summary>Report music history to Last.fm</summary>
+            <description>Enables or disables sending scrobbles and the “currently playing” info to 
Last.fm.</description>
+        </key>
     </schema>
 </schemalist>
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index c8fabad7..79d0c075 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -401,7 +401,7 @@ class Player(GObject.GObject):
         self._gst_player.bind_property(
             'state', self, 'state', GObject.BindingFlags.SYNC_CREATE)
 
-        self._lastfm = LastFmScrobbler()
+        self._lastfm = LastFmScrobbler(application)
 
     @GObject.Property(
         type=bool, default=False, flags=GObject.ParamFlags.READABLE)
diff --git a/gnomemusic/scrobbler.py b/gnomemusic/scrobbler.py
index 646a5e60..c4a044c0 100644
--- a/gnomemusic/scrobbler.py
+++ b/gnomemusic/scrobbler.py
@@ -143,13 +143,34 @@ class LastFmScrobbler(GObject.GObject):
         return '<LastFmScrobbler>'
 
     @log
-    def __init__(self):
+    def __init__(self, application):
+        """Intialize LastFm Scrobbler
+
+        :param Application application: Application object
+        """
         super().__init__()
 
+        self._settings = application.props.settings
+        self._report = self._settings.get_boolean("lastfm-report")
+
         self._scrobbled = False
         self._goa_lastfm = GoaLastFM()
         self._soup_session = Soup.Session.new()
 
+    @GObject.Property(
+        type=bool, default=False, flags=GObject.ParamFlags.READABLE)
+    def can_scrobble(self):
+        """Get can scrobble status
+
+        Music is reported to Last.fm if the "lastfm-report" setting is
+        True and if a Goa Last.fm account is configured with music
+        support enabled.
+
+        :returns: True is music is reported to Last.fm
+        :rtype: bool
+        """
+        return not self._goa_lastfm.props.disabled and self._report is True
+
     @GObject.Property(type=bool, default=False)
     def scrobbled(self):
         """Bool indicating current scrobble status"""
@@ -237,7 +258,7 @@ class LastFmScrobbler(GObject.GObject):
         """
         self.scrobbled = True
 
-        if self._goa_lastfm.disabled:
+        if not self.props.can_scrobble:
             return
 
         media = coresong.props.media
@@ -253,7 +274,7 @@ class LastFmScrobbler(GObject.GObject):
         """
         self.scrobbled = False
 
-        if self._goa_lastfm.disabled:
+        if not self.props.can_scrobble:
             return
 
         media = coresong.props.media


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