diff --git a/beetsplug/kodiupdate.py b/beetsplug/kodiupdate.py index 2a885d2c2..ce6fb80ee 100644 --- a/beetsplug/kodiupdate.py +++ b/beetsplug/kodiupdate.py @@ -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 diff --git a/docs/changelog.rst b/docs/changelog.rst index 8d95b7fb0..2daadd6bb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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. diff --git a/docs/plugins/kodiupdate.rst b/docs/plugins/kodiupdate.rst index f521a8000..6713f0506 100644 --- a/docs/plugins/kodiupdate.rst +++ b/docs/plugins/kodiupdate.rst @@ -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