diff --git a/beetsplug/mpdupdate.py b/beetsplug/mpdupdate.py index a9b7aa25f..0360a45df 100644 --- a/beetsplug/mpdupdate.py +++ b/beetsplug/mpdupdate.py @@ -14,11 +14,11 @@ """Updates an MPD index whenever the library is changed. -Put something like the following in your .beetsconfig to configure: - [mpdupdate] - host = localhost - port = 6600 - password = seekrit +Put something like the following in your config.yaml to configure: + mpdupdate: + host: localhost + port: 6600 + password: seekrit """ from __future__ import print_function @@ -26,6 +26,10 @@ from beets.plugins import BeetsPlugin import socket from beets import config +# Global variable so that mpdupdate can detect database changes and run only +# once before beets exits. +database_changed = False + # No need to introduce a dependency on an MPD library for such a # simple use case. Here's a simple socket abstraction to make things # easier. @@ -97,10 +101,18 @@ class MPDUpdatePlugin(BeetsPlugin): 'password': u'', }) -@MPDUpdatePlugin.listen('import') -def update(lib=None, paths=None): - update_mpd( - config['mpdupdate']['host'].get(unicode), - config['mpdupdate']['port'].get(int), - config['mpdupdate']['password'].get(unicode), - ) + +@MPDUpdatePlugin.listen('database_change') +def handle_change(lib=None): + global database_changed + database_changed = True + + +@MPDUpdatePlugin.listen('cli_exit') +def update(lib=None): + if database_changed: + update_mpd( + config['mpdupdate']['host'].get(unicode), + config['mpdupdate']['port'].get(int), + config['mpdupdate']['password'].get(unicode), + )