kodiupdate: Support multiple instances

This commit is contained in:
ybnd 2021-12-12 13:26:37 +01:00
parent 5df2914db1
commit ca37c94337
3 changed files with 49 additions and 20 deletions

View file

@ -54,11 +54,12 @@ class KodiUpdate(BeetsPlugin):
super().__init__()
# Adding defaults.
config['kodi'].add({
config['kodi'].add([{
'host': 'localhost',
'port': 8080,
'user': 'kodi',
'pwd': 'kodi'})
'pwd': 'kodi'
}])
config['kodi']['pwd'].redact = True
self.register_listener('database_change', self.listen_for_db_change)
@ -72,24 +73,34 @@ class KodiUpdate(BeetsPlugin):
"""
self._log.info('Requesting a Kodi library update...')
# Try to send update request.
try:
r = update_kodi(
config['kodi']['host'].get(),
config['kodi']['port'].get(),
config['kodi']['user'].get(),
config['kodi']['pwd'].get())
r.raise_for_status()
kodi = config['kodi'].get()
except requests.exceptions.RequestException as e:
self._log.warning('Kodi update failed: {0}',
str(e))
return
# Backwards compatibility in case not configured as an array
if not isinstance(kodi, list):
kodi = [kodi]
json = r.json()
if json.get('result') != 'OK':
self._log.warning('Kodi update failed: JSON response was {0!r}',
json)
return
for instance in kodi:
# Try to send update request.
try:
r = update_kodi(
instance['host'],
instance['port'],
instance['user'],
instance['pwd']
)
r.raise_for_status()
self._log.info('Kodi update triggered')
json = r.json()
if json.get('result') != 'OK':
self._log.warning(
'Kodi update failed: JSON response was {0!r}', json
)
continue
self._log.info(
'Kodi update triggered for {0}:{1}',
instance['host'], instance['port']
)
except requests.exceptions.RequestException as e:
self._log.warning('Kodi update failed: {0}', str(e))
continue

View file

@ -6,6 +6,11 @@ Changelog
Changelog goes here!
New features:
* :doc:`/plugins/kodiupdate`: Now supports multiple kodi instances
:bug:`4101`
Bug fixes:
* :doc:`/plugins/lyrics`: Fix Genius search by using query params instead of body.

View file

@ -16,6 +16,19 @@ which looks like this::
user: kodi
pwd: kodi
To update multiple Kodi instances, specify them as an array::
kodi:
- host: x.x.x.x
port: 8080
user: kodi
pwd: kodi
- host: y.y.y.y
port: 8081
user: kodi2
pwd: kodi2
To use the ``kodiupdate`` plugin you need to install the `requests`_ library with::
pip install requests