Merge pull request #85 from dangmai/mpdupdate

Fix mpdupdate to update mpd whenever the database changes (not just import)
This commit is contained in:
Adrian Sampson 2013-01-31 16:33:04 -08:00
commit 3fec79fee7

View file

@ -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),
)