From ef8ef4c7478fcabffbfb769491a5b90c985798f5 Mon Sep 17 00:00:00 2001 From: Dang Mai Date: Thu, 31 Jan 2013 17:14:01 -0500 Subject: [PATCH 1/2] Update MPD whenever database changes --- beetsplug/mpdupdate.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/beetsplug/mpdupdate.py b/beetsplug/mpdupdate.py index a9b7aa25f..61ea0b82c 100644 --- a/beetsplug/mpdupdate.py +++ b/beetsplug/mpdupdate.py @@ -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), + ) From d4004f10fa51c66e5d55861e1aae85182d30b21c Mon Sep 17 00:00:00 2001 From: Dang Mai Date: Thu, 31 Jan 2013 17:16:03 -0500 Subject: [PATCH 2/2] Update comments to reflect config migration --- beetsplug/mpdupdate.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/beetsplug/mpdupdate.py b/beetsplug/mpdupdate.py index 61ea0b82c..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