Explorar el Código

Events can be globally disabled with HTTP

fix #7
boyska hace 7 años
padre
commit
0840cf51b0
Se han modificado 2 ficheros con 31 adiciones y 1 borrados
  1. 7 1
      larigira/mpc.py
  2. 24 0
      larigira/rpc.py

+ 7 - 1
larigira/mpc.py

@@ -60,6 +60,7 @@ class Player:
         self.min_playlist_length = 10
         self.tmpcleaner = UnusedCleaner(conf)
         self._continous_audiospec = self.conf['CONTINOUS_AUDIOSPEC']
+        self.events_enabled = True
 
     def _get_mpd(self):
         mpd_client = MPDClient(use_unicode=True)
@@ -106,10 +107,15 @@ class Player:
         picker.start()
 
     def enqueue(self, songs):
-        mpd_client = self._get_mpd()
         assert type(songs) is dict
         assert 'uris' in songs
         spec = [aspec.get('nick', aspec.eid) for aspec in songs['audiospecs']]
+        if not self.events_enabled:
+            self.log.debug('Ignoring <{}> (events disabled)'.format(
+                ','.join(spec)
+            ))
+            return
+        mpd_client = self._get_mpd()
         for uri in reversed(songs['uris']):
             assert type(uri) is str
             self.log.info('Adding {} to playlist (from <{}>:{}={})'.

+ 24 - 0
larigira/rpc.py

@@ -67,6 +67,30 @@ def reset_audiospec():
     return jsonify(player.continous_audiospec)
 
 
+@rpc.route('/eventsenabled/toggle', methods=['POST'])
+def toggle_events_enabled():
+    status = current_app.larigira.controller.player.events_enabled
+    current_app.larigira.controller.player.events_enabled = not status
+    return jsonify(dict(events_enabled=not status))
+
+
+@rpc.route('/eventsenabled', methods=['GET'])
+def get_events_enabled():
+    status = current_app.larigira.controller.player.events_enabled
+    return jsonify(dict(events_enabled=status))
+
+
+@rpc.route('/eventsenabled', methods=['PUT'])
+def set_events_enabled():
+    player = current_app.larigira.controller.player
+    if request.json is None:
+        abort(400, "Must send application/json data")
+    if type(request.json) is not bool:
+        abort(400, "Content must be a JSON boolean")
+    player.events_enabled = request.json
+    return jsonify(dict(events_enabled=request.json))
+
+
 def get_scheduled_audiogen():
     larigira = current_app.larigira
     running = larigira.controller.monitor.running