From fa4a18879f26d948b5cef81c2d7eecf219a47598 Mon Sep 17 00:00:00 2001 From: Iliana Weller Date: Wed, 9 May 2018 21:13:11 -0700 Subject: [PATCH 1/2] Send event in hooks.{album,track}_for_mbid (#2921) Send events from {album,track}_for_mbid, then remove the decorators from {albums,tracks}_for_id so that duplicate events are not fired. When moving to generators and decorators in autotag.hooks (#2249), albuminfo_received and trackinfo_received stopped being sent from code directly calling hooks.{album,track}_for_mbid. This is most visible when trying to write a plugin to interact with mbsync, as the documentation explicitly says it should work. --- beets/autotag/hooks.py | 14 ++++++++++---- docs/changelog.rst | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index 7df1f62f4..3615a9333 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -539,7 +539,10 @@ def album_for_mbid(release_id): if the ID is not found. """ try: - return mb.album_for_id(release_id) + album = mb.album_for_id(release_id) + if album: + plugins.send(u'albuminfo_received', info=album) + return album except mb.MusicBrainzAPIError as exc: exc.log(log) @@ -549,12 +552,14 @@ def track_for_mbid(recording_id): if the ID is not found. """ try: - return mb.track_for_id(recording_id) + track = mb.track_for_id(recording_id) + if track: + plugins.send(u'trackinfo_received', info=track) + return track except mb.MusicBrainzAPIError as exc: exc.log(log) -@plugins.notify_info_yielded(u'albuminfo_received') def albums_for_id(album_id): """Get a list of albums for an ID.""" a = album_for_mbid(album_id) @@ -562,10 +567,10 @@ def albums_for_id(album_id): yield a for a in plugins.album_for_id(album_id): if a: + plugins.send(u'albuminfo_received', info=a) yield a -@plugins.notify_info_yielded(u'trackinfo_received') def tracks_for_id(track_id): """Get a list of tracks for an ID.""" t = track_for_mbid(track_id) @@ -573,6 +578,7 @@ def tracks_for_id(track_id): yield t for t in plugins.track_for_id(track_id): if t: + plugins.send(u'trackinfo_received', info=t) yield t diff --git a/docs/changelog.rst b/docs/changelog.rst index c87935668..7c9376b7b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -115,6 +115,9 @@ Fixes: tracks. :bug:`2537` * In the ``mbsync`` plugin, support MusicBrainz recording ID changes, relying on release track IDs instead. Thanks to :user:`jdetrey`. :bug:`1234` +* Properly send ``albuminfo_received`` and ``trackinfo_received`` in all cases, + most notably when using the ``mbsync`` plugin. This was a regression since + version 1.4.1. :bug:`2921` For developers: From d1d745a58e3bc73b068020ec1b4bf4f7555471be Mon Sep 17 00:00:00 2001 From: Iliana Weller Date: Wed, 9 May 2018 21:31:35 -0700 Subject: [PATCH 2/2] Test {album,track}info_received sends in mbsync --- test/test_mbsync.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/test_mbsync.py b/test/test_mbsync.py index a48844384..c96f33d53 100644 --- a/test/test_mbsync.py +++ b/test/test_mbsync.py @@ -37,15 +37,15 @@ class MbsyncCliTest(unittest.TestCase, TestHelper): self.unload_plugins() self.teardown_beets() - @patch('beets.autotag.hooks.album_for_mbid') - @patch('beets.autotag.hooks.track_for_mbid') - def test_update_library(self, track_for_mbid, album_for_mbid): - album_for_mbid.return_value = \ + @patch('beets.autotag.mb.album_for_id') + @patch('beets.autotag.mb.track_for_id') + def test_update_library(self, track_for_id, album_for_id): + album_for_id.return_value = \ generate_album_info( 'album id', [('track id', {'release_track_id': u'release track id'})] ) - track_for_mbid.return_value = \ + track_for_id.return_value = \ generate_track_info(u'singleton track id', {'title': u'singleton info'}) @@ -65,7 +65,10 @@ class MbsyncCliTest(unittest.TestCase, TestHelper): ) self.lib.add(item) - self.run_command('mbsync') + with capture_log() as logs: + self.run_command('mbsync') + self.assertIn('Sending event: albuminfo_received', logs) + self.assertIn('Sending event: trackinfo_received', logs) item.load() self.assertEqual(item.title, u'singleton info')