From 653181a2961d6b8f11261e790c27836b98ba4bef Mon Sep 17 00:00:00 2001 From: maffo999 Date: Wed, 14 Jul 2021 20:10:04 +0200 Subject: [PATCH 1/3] Fix subsonicupdate plugin --- beetsplug/subsonicupdate.py | 65 +++++++++------------------------ docs/plugins/subsonicupdate.rst | 6 ++- 2 files changed, 22 insertions(+), 49 deletions(-) diff --git a/beetsplug/subsonicupdate.py b/beetsplug/subsonicupdate.py index 04e903512..40dbea796 100644 --- a/beetsplug/subsonicupdate.py +++ b/beetsplug/subsonicupdate.py @@ -20,6 +20,14 @@ a "subsonic" section like the following: url: https://mydomain.com:443/subsonic user: username pass: password + auth: token +For older Subsonic versions, token authentication +is not supported, use password instead: + subsonic: + url: https://mydomain.com:443/subsonic + user: username + pass: password + auth: pass """ from __future__ import division, absolute_import, print_function @@ -34,8 +42,6 @@ from beets import config from beets.plugins import BeetsPlugin __author__ = 'https://github.com/maffo999' -AUTH_TOKEN_VERSION = (1, 12) - class SubsonicUpdate(BeetsPlugin): def __init__(self): @@ -45,30 +51,11 @@ class SubsonicUpdate(BeetsPlugin): 'user': 'admin', 'pass': 'admin', 'url': 'http://localhost:4040', + 'auth': 'token', }) config['subsonic']['pass'].redact = True - self._version = None - self._auth = None self.register_listener('import', self.start_scan) - @property - def version(self): - if self._version is None: - self._version = self.__get_version() - return self._version - - @property - def auth(self): - if self._auth is None: - if self.version is not None: - if self.version > AUTH_TOKEN_VERSION: - self._auth = "token" - else: - self._auth = "password" - self._log.info( - u"using '{}' authentication method".format(self._auth)) - return self._auth - @staticmethod def __create_token(): """Create salt and token from given password. @@ -110,48 +97,30 @@ class SubsonicUpdate(BeetsPlugin): return url + '/rest/{}'.format(endpoint) - def __get_version(self): - url = self.__format_url("ping.view") - payload = { - 'c': 'beets', - 'f': 'json' - } - try: - response = requests.get(url, params=payload) - if response.status_code == 200: - json = response.json() - version = json['subsonic-response']['version'] - self._log.info( - u'subsonic version:{0} '.format(version)) - return tuple(int(s) for s in version.split('.')) - else: - self._log.error(u'Error: {0}', json) - return None - except Exception as error: - self._log.error(u'Error: {0}'.format(error)) - return None - def start_scan(self): user = config['subsonic']['user'].as_str() - url = self.__format_url("startScan.view") + auth = config['subsonic']['auth'].as_str() + url = self.__format_url("startScan") + self._log.info(u'URL is {0}', url) + self._log.info(u'auth type is {0}', config['subsonic']['auth']) - if self.auth == 'token': + if auth == "token": salt, token = self.__create_token() payload = { 'u': user, 't': token, 's': salt, - 'v': self.version, # Subsonic 6.1 and newer. + 'v': '1.13.0', # Subsonic 5.3 and newer 'c': 'beets', 'f': 'json' } - elif self.auth == 'password': + elif auth == "password": password = config['subsonic']['pass'].as_str() encpass = hexlify(password.encode()).decode() payload = { 'u': user, 'p': 'enc:{}'.format(encpass), - 'v': self.version, + 'v': '1.12.0', 'c': 'beets', 'f': 'json' } diff --git a/docs/plugins/subsonicupdate.rst b/docs/plugins/subsonicupdate.rst index 710d21f2c..e6f26c8dc 100644 --- a/docs/plugins/subsonicupdate.rst +++ b/docs/plugins/subsonicupdate.rst @@ -16,12 +16,13 @@ which looks like this:: url: https://example.com:443/subsonic user: username pass: password + auth: token With that all in place, beets will send a Rest API to your Subsonic server every time you import new music. Due to a current limitation of the API, all libraries visible to that user will be scanned. -This plugin requires Subsonic v6.1 or higher and an active Premium license (or trial). +This plugin requires Subsonic with an active Premium license (or active trial). Configuration ------------- @@ -32,3 +33,6 @@ The available options under the ``subsonic:`` section are: - **user**: The Subsonic user. Default: ``admin`` - **pass**: The Subsonic user password. (This may either be a clear-text password or hex-encoded with the prefix ``enc:``.) Default: ``admin`` +- **auth**: The authentication method. Possible choices are ``token`` or + ``password``. ``token`` authentication is preferred to avoid sending + cleartext password. From 51210cb64933f7a655480b58a6586daf6b24d54d Mon Sep 17 00:00:00 2001 From: maffo999 Date: Wed, 14 Jul 2021 20:36:52 +0200 Subject: [PATCH 2/3] Updated changelog --- docs/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 25b09ff80..27ddea33a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -387,6 +387,7 @@ Fixes: all front images instead of blindly selecting the first one. * :doc:`/plugins/lyrics`: Removed the LyricWiki source (the site shut down on 21/09/2020). +* Fix :bug:`4002`. Subsonicupdate plugin is now functional again. For plugin developers: From 5dbc7f9f3370acd210934b0096061d9a073fb612 Mon Sep 17 00:00:00 2001 From: maffo999 Date: Thu, 15 Jul 2021 20:13:18 +0200 Subject: [PATCH 3/3] Moved logging to debug and fixed empty line. Updated changelog to include new option. --- beetsplug/subsonicupdate.py | 5 +++-- docs/changelog.rst | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/beetsplug/subsonicupdate.py b/beetsplug/subsonicupdate.py index 40dbea796..89b59429f 100644 --- a/beetsplug/subsonicupdate.py +++ b/beetsplug/subsonicupdate.py @@ -43,6 +43,7 @@ from beets.plugins import BeetsPlugin __author__ = 'https://github.com/maffo999' + class SubsonicUpdate(BeetsPlugin): def __init__(self): super(SubsonicUpdate, self).__init__() @@ -101,8 +102,8 @@ class SubsonicUpdate(BeetsPlugin): user = config['subsonic']['user'].as_str() auth = config['subsonic']['auth'].as_str() url = self.__format_url("startScan") - self._log.info(u'URL is {0}', url) - self._log.info(u'auth type is {0}', config['subsonic']['auth']) + self._log.debug(u'URL is {0}', url) + self._log.debug(u'auth type is {0}', config['subsonic']['auth']) if auth == "token": salt, token = self.__create_token() diff --git a/docs/changelog.rst b/docs/changelog.rst index 27ddea33a..5eae9c855 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -387,7 +387,9 @@ Fixes: all front images instead of blindly selecting the first one. * :doc:`/plugins/lyrics`: Removed the LyricWiki source (the site shut down on 21/09/2020). -* Fix :bug:`4002`. Subsonicupdate plugin is now functional again. +* Fix :bug:`4002`. Subsonicupdate plugin is now functional again. New option + 'auth' is required in the configuration file to specify the authentication + type. For plugin developers: