Skip to content

Commit 600c928

Browse files
authored
Merge pull request #4008 from maffo999/master
Fix for #4002: subsonicupdate plugin broken
2 parents 8d3cfe4 + 5dbc7f9 commit 600c928

File tree

3 files changed

+25
-48
lines changed

3 files changed

+25
-48
lines changed

beetsplug/subsonicupdate.py

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
url: https://mydomain.com:443/subsonic
2121
user: username
2222
pass: password
23+
auth: token
24+
For older Subsonic versions, token authentication
25+
is not supported, use password instead:
26+
subsonic:
27+
url: https://mydomain.com:443/subsonic
28+
user: username
29+
pass: password
30+
auth: pass
2331
"""
2432
from __future__ import division, absolute_import, print_function
2533

@@ -34,7 +42,6 @@
3442
from beets.plugins import BeetsPlugin
3543

3644
__author__ = 'https://github.com/maffo999'
37-
AUTH_TOKEN_VERSION = (1, 12)
3845

3946

4047
class SubsonicUpdate(BeetsPlugin):
@@ -45,30 +52,11 @@ def __init__(self):
4552
'user': 'admin',
4653
'pass': 'admin',
4754
'url': 'http://localhost:4040',
55+
'auth': 'token',
4856
})
4957
config['subsonic']['pass'].redact = True
50-
self._version = None
51-
self._auth = None
5258
self.register_listener('import', self.start_scan)
5359

54-
@property
55-
def version(self):
56-
if self._version is None:
57-
self._version = self.__get_version()
58-
return self._version
59-
60-
@property
61-
def auth(self):
62-
if self._auth is None:
63-
if self.version is not None:
64-
if self.version > AUTH_TOKEN_VERSION:
65-
self._auth = "token"
66-
else:
67-
self._auth = "password"
68-
self._log.info(
69-
u"using '{}' authentication method".format(self._auth))
70-
return self._auth
71-
7260
@staticmethod
7361
def __create_token():
7462
"""Create salt and token from given password.
@@ -110,48 +98,30 @@ def __format_url(endpoint):
11098

11199
return url + '/rest/{}'.format(endpoint)
112100

113-
def __get_version(self):
114-
url = self.__format_url("ping.view")
115-
payload = {
116-
'c': 'beets',
117-
'f': 'json'
118-
}
119-
try:
120-
response = requests.get(url, params=payload)
121-
if response.status_code == 200:
122-
json = response.json()
123-
version = json['subsonic-response']['version']
124-
self._log.info(
125-
u'subsonic version:{0} '.format(version))
126-
return tuple(int(s) for s in version.split('.'))
127-
else:
128-
self._log.error(u'Error: {0}', json)
129-
return None
130-
except Exception as error:
131-
self._log.error(u'Error: {0}'.format(error))
132-
return None
133-
134101
def start_scan(self):
135102
user = config['subsonic']['user'].as_str()
136-
url = self.__format_url("startScan.view")
103+
auth = config['subsonic']['auth'].as_str()
104+
url = self.__format_url("startScan")
105+
self._log.debug(u'URL is {0}', url)
106+
self._log.debug(u'auth type is {0}', config['subsonic']['auth'])
137107

138-
if self.auth == 'token':
108+
if auth == "token":
139109
salt, token = self.__create_token()
140110
payload = {
141111
'u': user,
142112
't': token,
143113
's': salt,
144-
'v': self.version, # Subsonic 6.1 and newer.
114+
'v': '1.13.0', # Subsonic 5.3 and newer
145115
'c': 'beets',
146116
'f': 'json'
147117
}
148-
elif self.auth == 'password':
118+
elif auth == "password":
149119
password = config['subsonic']['pass'].as_str()
150120
encpass = hexlify(password.encode()).decode()
151121
payload = {
152122
'u': user,
153123
'p': 'enc:{}'.format(encpass),
154-
'v': self.version,
124+
'v': '1.12.0',
155125
'c': 'beets',
156126
'f': 'json'
157127
}

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ Fixes:
387387
all front images instead of blindly selecting the first one.
388388
* :doc:`/plugins/lyrics`: Removed the LyricWiki source (the site shut down on
389389
21/09/2020).
390+
* Fix :bug:`4002`. Subsonicupdate plugin is now functional again. New option
391+
'auth' is required in the configuration file to specify the authentication
392+
type.
390393

391394
For plugin developers:
392395

docs/plugins/subsonicupdate.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ which looks like this::
1616
url: https://example.com:443/subsonic
1717
user: username
1818
pass: password
19+
auth: token
1920

2021
With that all in place, beets will send a Rest API to your Subsonic
2122
server every time you import new music.
2223
Due to a current limitation of the API, all libraries visible to that user will be scanned.
2324

24-
This plugin requires Subsonic v6.1 or higher and an active Premium license (or trial).
25+
This plugin requires Subsonic with an active Premium license (or active trial).
2526

2627
Configuration
2728
-------------
@@ -32,3 +33,6 @@ The available options under the ``subsonic:`` section are:
3233
- **user**: The Subsonic user. Default: ``admin``
3334
- **pass**: The Subsonic user password. (This may either be a clear-text
3435
password or hex-encoded with the prefix ``enc:``.) Default: ``admin``
36+
- **auth**: The authentication method. Possible choices are ``token`` or
37+
``password``. ``token`` authentication is preferred to avoid sending
38+
cleartext password.

0 commit comments

Comments
 (0)