From c23cad5d134df467aa80b997250f18a58fea2ec3 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 13 Feb 2016 22:34:09 +0100 Subject: [PATCH] audio: Only emit tags changed when tags changed. Previously we alerted AudioListeners about all new tags, now we filter it down to just the changed ones. Only real reason for this is that the changed messages spam the log output making debugging harder. --- mopidy/audio/actor.py | 16 +++++++++++++--- mopidy/audio/tags.py | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mopidy/audio/actor.py b/mopidy/audio/actor.py index f825a768..ea4a6ed9 100644 --- a/mopidy/audio/actor.py +++ b/mopidy/audio/actor.py @@ -326,9 +326,19 @@ class _Handler(object): def on_tag(self, taglist): tags = tags_lib.convert_taglist(taglist) gst_logger.debug('Got TAG bus message: tags=%r', dict(tags)) - self._audio._tags.update(tags) - logger.debug('Audio event: tags_changed(tags=%r)', tags.keys()) - AudioListener.send('tags_changed', tags=tags.keys()) + + # TODO: Add proper tests for only emitting changed tags. + unique = object() + changed = [] + for key, value in tags.items(): + # Update any tags that changed, and store changed keys. + if self._audio._tags.get(key, unique) != value: + self._audio._tags[key] = value + changed.append(key) + + if changed: + logger.debug('Audio event: tags_changed(tags=%r)', changed) + AudioListener.send('tags_changed', tags=changed) def on_missing_plugin(self, msg): desc = GstPbutils.missing_plugin_message_get_description(msg) diff --git a/mopidy/audio/tags.py b/mopidy/audio/tags.py index 62784bc0..38a0bac9 100644 --- a/mopidy/audio/tags.py +++ b/mopidy/audio/tags.py @@ -58,6 +58,7 @@ gstreamer-GstTagList.html log.TRACE_LOG_LEVEL, 'Ignoring unknown tag data: %r = %r', tag, value) + # TODO: dict(result) to not leak the defaultdict, or just use setdefault? return result