From 28d047e1d22e48e15507d5636c8ea3d8a17d604f Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sun, 15 Mar 2015 11:42:01 +0100 Subject: [PATCH] core: Only emit stream title changed for streams This is done by checking for the presence of the organization tag typically set by web streams. This might be a bit to strict and a bad heuristic, but it's currently better than wrongly emitting stream titles for non streams IMO. --- mopidy/core/actor.py | 12 ++++++++---- tests/core/test_playback.py | 5 +++++ tests/dummy_audio.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mopidy/core/actor.py b/mopidy/core/actor.py index ed1c33ab..671517ca 100644 --- a/mopidy/core/actor.py +++ b/mopidy/core/actor.py @@ -121,12 +121,16 @@ class Core( return tags = self.audio.get_current_tags().get() - if not tags or 'title' not in tags or not tags['title']: + if not tags: return - title = tags['title'][0] - self.playback._stream_title = title - CoreListener.send('stream_title_changed', title=title) + # TODO: this limits us to only streams that set organization, this is + # a hack to make sure we don't emit stream title changes for plain + # tracks. We need a better way to decide if something is a stream. + if 'title' in tags and tags['title'] and 'organization' in tags: + title = tags['title'][0] + self.playback._stream_title = title + CoreListener.send('stream_title_changed', title=title) class Backends(list): diff --git a/tests/core/test_playback.py b/tests/core/test_playback.py index 8911978a..809c1385 100644 --- a/tests/core/test_playback.py +++ b/tests/core/test_playback.py @@ -582,6 +582,7 @@ class TestStream(unittest.TestCase): def test_get_stream_title_during_playback_with_tags_change(self): self.core.playback.play() + self.audio.trigger_fake_tags_changed({'organization': ['baz']}) self.audio.trigger_fake_tags_changed({'title': ['foobar']}).get() self.replay_audio_events() @@ -589,6 +590,7 @@ class TestStream(unittest.TestCase): def test_get_stream_title_after_next(self): self.core.playback.play() + self.audio.trigger_fake_tags_changed({'organization': ['baz']}) self.audio.trigger_fake_tags_changed({'title': ['foobar']}).get() self.core.playback.next() @@ -597,8 +599,10 @@ class TestStream(unittest.TestCase): def test_get_stream_title_after_next_with_tags_change(self): self.core.playback.play() + self.audio.trigger_fake_tags_changed({'organization': ['baz']}) self.audio.trigger_fake_tags_changed({'title': ['foo']}).get() self.core.playback.next() + self.audio.trigger_fake_tags_changed({'organization': ['baz']}) self.audio.trigger_fake_tags_changed({'title': ['bar']}).get() self.replay_audio_events() @@ -606,6 +610,7 @@ class TestStream(unittest.TestCase): def test_get_stream_title_after_stop(self): self.core.playback.play() + self.audio.trigger_fake_tags_changed({'organization': ['baz']}) self.audio.trigger_fake_tags_changed({'title': ['foobar']}).get() self.core.playback.stop() diff --git a/tests/dummy_audio.py b/tests/dummy_audio.py index b73946cb..dcf90ffa 100644 --- a/tests/dummy_audio.py +++ b/tests/dummy_audio.py @@ -110,7 +110,7 @@ class DummyAudio(pykka.ThreadingActor): self._state_change_result = False def trigger_fake_tags_changed(self, tags): - self._tags = tags + self._tags.update(tags) audio.AudioListener.send('tags_changed', tags=self._tags.keys()) def get_about_to_finish_callback(self):