20
20
url: https://mydomain.com:443/subsonic
21
21
user: username
22
22
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
23
31
"""
24
32
from __future__ import division , absolute_import , print_function
25
33
34
42
from beets .plugins import BeetsPlugin
35
43
36
44
__author__ = 'https://github.com/maffo999'
37
- AUTH_TOKEN_VERSION = (1 , 12 )
38
45
39
46
40
47
class SubsonicUpdate (BeetsPlugin ):
@@ -45,30 +52,11 @@ def __init__(self):
45
52
'user' : 'admin' ,
46
53
'pass' : 'admin' ,
47
54
'url' : 'http://localhost:4040' ,
55
+ 'auth' : 'token' ,
48
56
})
49
57
config ['subsonic' ]['pass' ].redact = True
50
- self ._version = None
51
- self ._auth = None
52
58
self .register_listener ('import' , self .start_scan )
53
59
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
-
72
60
@staticmethod
73
61
def __create_token ():
74
62
"""Create salt and token from given password.
@@ -110,48 +98,30 @@ def __format_url(endpoint):
110
98
111
99
return url + '/rest/{}' .format (endpoint )
112
100
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
-
134
101
def start_scan (self ):
135
102
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' ])
137
107
138
- if self . auth == ' token' :
108
+ if auth == " token" :
139
109
salt , token = self .__create_token ()
140
110
payload = {
141
111
'u' : user ,
142
112
't' : token ,
143
113
's' : salt ,
144
- 'v' : self . version , # Subsonic 6.1 and newer.
114
+ 'v' : '1.13.0' , # Subsonic 5.3 and newer
145
115
'c' : 'beets' ,
146
116
'f' : 'json'
147
117
}
148
- elif self . auth == ' password' :
118
+ elif auth == " password" :
149
119
password = config ['subsonic' ]['pass' ].as_str ()
150
120
encpass = hexlify (password .encode ()).decode ()
151
121
payload = {
152
122
'u' : user ,
153
123
'p' : 'enc:{}' .format (encpass ),
154
- 'v' : self . version ,
124
+ 'v' : '1.12.0' ,
155
125
'c' : 'beets' ,
156
126
'f' : 'json'
157
127
}
0 commit comments