From c420f6bf996c53fa8958956626c136ac0e9e55f6 Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Thu, 19 Apr 2018 23:58:40 +0200 Subject: [PATCH 1/9] Add sonos updater plugin. --- beetsplug/sonosupdate.py | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 beetsplug/sonosupdate.py diff --git a/beetsplug/sonosupdate.py b/beetsplug/sonosupdate.py new file mode 100644 index 000000000..498ae9835 --- /dev/null +++ b/beetsplug/sonosupdate.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# This file is part of beets. +# Copyright 2018, Tobias Sauerwein. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. + +"""Updates a Sonos library whenever the beets library is changed. +This is based on the Kodi Update plugin. + +Put something like the following in your config.yaml to configure: + kodi: + host: localhost + port: 8080 + user: user + pwd: secret +""" +from __future__ import division, absolute_import, print_function + +from beets import config +from beets.plugins import BeetsPlugin +import six +import soco + + +class SonosUpdate(BeetsPlugin): + def __init__(self): + super(SonosUpdate, self).__init__() + self.register_listener('database_change', self.listen_for_db_change) + + def listen_for_db_change(self, lib, model): + """Listens for beets db change and register the update""" + self.register_listener('cli_exit', self.update) + + def update(self, lib): + """When the client exists try to send refresh request to a Sonos + controler. + """ + self._log.info(u'Requesting a Sonos library update...') + + # Try to send update request. + try: + device = soco.discovery.any_soco() + device.music_library.start_library_update() + + except: + self._log.warning(u'Sonos update failed') + return + + self._log.info(u'Sonos update triggered') From dcce29eeb32803e745503b362ea1cc9a845d61a4 Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Fri, 20 Apr 2018 00:07:40 +0200 Subject: [PATCH 2/9] Add documentation for the sonos updater plugin. --- docs/plugins/sonosupdate.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 docs/plugins/sonosupdate.rst diff --git a/docs/plugins/sonosupdate.rst b/docs/plugins/sonosupdate.rst new file mode 100644 index 000000000..1ecf91b92 --- /dev/null +++ b/docs/plugins/sonosupdate.rst @@ -0,0 +1,23 @@ +SonosUpdate Plugin +================= + +The ``sonosupdate`` plugin lets you automatically update `Sonos`_'s music +library whenever you change your beets library. + +To use ``sonosupdate`` plugin, enable it in your configuration +(see :ref:`using-plugins`). + +To use the ``sonosupdate`` plugin you need to install the `soco`_ library with:: + + pip install soco + +With that all in place, you'll see beets send the "update" command to your Sonos +controller every time you change your beets library. + +.. Sonos: http://sonos.com/ +.. _soco: http://python-soco.com + +Configuration +------------- + +There is nothing to configure. From 5e084b7186e3dab883bf7e7c6070303f79097bd0 Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Fri, 20 Apr 2018 07:39:12 +0200 Subject: [PATCH 3/9] Fix exception handling and add docs to the toc. --- beetsplug/sonosupdate.py | 12 ++---------- docs/changelog.rst | 3 +++ docs/plugins/index.rst | 4 +++- docs/plugins/sonosupdate.rst | 5 ----- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/beetsplug/sonosupdate.py b/beetsplug/sonosupdate.py index 498ae9835..622604acf 100644 --- a/beetsplug/sonosupdate.py +++ b/beetsplug/sonosupdate.py @@ -15,17 +15,9 @@ """Updates a Sonos library whenever the beets library is changed. This is based on the Kodi Update plugin. - -Put something like the following in your config.yaml to configure: - kodi: - host: localhost - port: 8080 - user: user - pwd: secret """ from __future__ import division, absolute_import, print_function -from beets import config from beets.plugins import BeetsPlugin import six import soco @@ -51,8 +43,8 @@ class SonosUpdate(BeetsPlugin): device = soco.discovery.any_soco() device.music_library.start_library_update() - except: - self._log.warning(u'Sonos update failed') + except NoneType: + self._log.warning(u'Could not find a Sonos device.') return self._log.info(u'Sonos update triggered') diff --git a/docs/changelog.rst b/docs/changelog.rst index 4381edeeb..a923bfe37 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -12,6 +12,9 @@ New features: recording skipped directories to the incremental list, so you can revisit them later. Thanks to :user:`sekjun9878`. :bug:`2773` +* A new interoperability plugin to automatically notify Sonos controllers to + update the music library once the beets library got updated. + Thanks to :user:`cgtobi`. Fixes: diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index e37a270fa..e08a1767f 100644 --- a/docs/plugins/index.rst +++ b/docs/plugins/index.rst @@ -158,6 +158,8 @@ Interoperability * :doc:`plexupdate`: Automatically notifies `Plex`_ whenever the beets library changes. * :doc:`smartplaylist`: Generate smart playlists based on beets queries. +* :doc:`sonosupdate`: Automatically notifies `Sonos`_ whenever the beets library + changes. * :doc:`thumbnails`: Get thumbnails with the cover art on your album folders. * :doc:`badfiles`: Check audio file integrity. @@ -165,6 +167,7 @@ Interoperability .. _Emby: http://emby.media .. _Plex: http://plex.tv .. _Kodi: http://kodi.tv +.. _Sonos: http://sonos.com Miscellaneous ------------- @@ -262,4 +265,3 @@ Here are a few of the plugins written by the beets community: .. _whatlastgenre: https://github.com/YetAnotherNerd/whatlastgenre/tree/master/plugin/beets .. _beets-usertag: https://github.com/igordertigor/beets-usertag .. _beets-popularity: https://github.com/abba23/beets-popularity - diff --git a/docs/plugins/sonosupdate.rst b/docs/plugins/sonosupdate.rst index 1ecf91b92..5a7a6583b 100644 --- a/docs/plugins/sonosupdate.rst +++ b/docs/plugins/sonosupdate.rst @@ -16,8 +16,3 @@ controller every time you change your beets library. .. Sonos: http://sonos.com/ .. _soco: http://python-soco.com - -Configuration -------------- - -There is nothing to configure. From 14538e45afeeab6586f2ed00059003da11bbed5f Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Fri, 20 Apr 2018 07:42:57 +0200 Subject: [PATCH 4/9] Fix changelog entry. --- docs/changelog.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index a923bfe37..3113b925b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -12,6 +12,15 @@ New features: recording skipped directories to the incremental list, so you can revisit them later. Thanks to :user:`sekjun9878`. :bug:`2773` +* :doc:`/plugins/fetchart`: extended syntax for the ``sources`` option to give + fine-grained control over the search order for backends with several matching + strategies. +* :doc:`/plugins/web`: added the boolean ``cors_supports_credentials`` option to + allow in-browser clients to login to the beet web server even when it is + protected by an authorization mechanism. +* A new importer configuration ``artist_credit`` will tell beets to prefer the + artist credit over the artist when autotagging. + :bug:`1249` * A new interoperability plugin to automatically notify Sonos controllers to update the music library once the beets library got updated. Thanks to :user:`cgtobi`. From 4748a68b6bde662245b85ecf2a52fbedffc4ffcb Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Fri, 20 Apr 2018 08:16:56 +0200 Subject: [PATCH 5/9] Remove exception handling. --- beetsplug/sonosupdate.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/beetsplug/sonosupdate.py b/beetsplug/sonosupdate.py index 622604acf..23484c653 100644 --- a/beetsplug/sonosupdate.py +++ b/beetsplug/sonosupdate.py @@ -38,12 +38,11 @@ class SonosUpdate(BeetsPlugin): """ self._log.info(u'Requesting a Sonos library update...') - # Try to send update request. - try: - device = soco.discovery.any_soco() - device.music_library.start_library_update() + device = soco.discovery.any_soco() - except NoneType: + if device: + device.music_library.start_library_update() + else: self._log.warning(u'Could not find a Sonos device.') return From 2ac0a0024172853cf853099d36b33f735cf93ffa Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Fri, 20 Apr 2018 08:24:05 +0200 Subject: [PATCH 6/9] Fix short title underline. --- docs/plugins/sonosupdate.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins/sonosupdate.rst b/docs/plugins/sonosupdate.rst index 5a7a6583b..4b47c9a6e 100644 --- a/docs/plugins/sonosupdate.rst +++ b/docs/plugins/sonosupdate.rst @@ -1,5 +1,5 @@ SonosUpdate Plugin -================= +================== The ``sonosupdate`` plugin lets you automatically update `Sonos`_'s music library whenever you change your beets library. From 499b3867b2562ed15b80d296a41416775c8b2fe4 Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Fri, 20 Apr 2018 08:25:08 +0200 Subject: [PATCH 7/9] Remove unused import. --- beetsplug/sonosupdate.py | 1 - 1 file changed, 1 deletion(-) diff --git a/beetsplug/sonosupdate.py b/beetsplug/sonosupdate.py index 23484c653..56a315a15 100644 --- a/beetsplug/sonosupdate.py +++ b/beetsplug/sonosupdate.py @@ -19,7 +19,6 @@ This is based on the Kodi Update plugin. from __future__ import division, absolute_import, print_function from beets.plugins import BeetsPlugin -import six import soco From ad3b5b1d7663025238040a54e2cb376f09f73f7f Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Fri, 20 Apr 2018 08:38:14 +0200 Subject: [PATCH 8/9] Fix target name. --- docs/plugins/sonosupdate.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins/sonosupdate.rst b/docs/plugins/sonosupdate.rst index 4b47c9a6e..97a13bd07 100644 --- a/docs/plugins/sonosupdate.rst +++ b/docs/plugins/sonosupdate.rst @@ -14,5 +14,5 @@ To use the ``sonosupdate`` plugin you need to install the `soco`_ library with:: With that all in place, you'll see beets send the "update" command to your Sonos controller every time you change your beets library. -.. Sonos: http://sonos.com/ +.. _Sonos: http://sonos.com/ .. _soco: http://python-soco.com From 8768e786af1b2705cf5e653349ff8e7e9d07fe6d Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Fri, 20 Apr 2018 08:47:43 +0200 Subject: [PATCH 9/9] Fix toctree. --- docs/plugins/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index d76136d52..edd82a255 100644 --- a/docs/plugins/index.rst +++ b/docs/plugins/index.rst @@ -87,6 +87,7 @@ like this:: rewrite scrub smartplaylist + sonosupdate spotify the thumbnails