From 0840cf51b0b07c04f820d4a34fce65e6b5f6ada9 Mon Sep 17 00:00:00 2001 From: boyska Date: Fri, 23 Sep 2016 20:16:55 +0200 Subject: [PATCH] Events can be globally disabled with HTTP fix #7 --- larigira/mpc.py | 8 +++++++- larigira/rpc.py | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/larigira/mpc.py b/larigira/mpc.py index f860688..b068b75 100644 --- a/larigira/mpc.py +++ b/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 <{}>:{}={})'. diff --git a/larigira/rpc.py b/larigira/rpc.py index 707f3e1..43fee23 100644 --- a/larigira/rpc.py +++ b/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