manage case of supysonic off
@@ -46,15 +46,28 @@ class SubsonicUpdate(BeetsPlugin):
'pass': 'admin',
'url': 'http://localhost:4040',
})
- self.version = self.__get_version()
+ 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"
+ self._auth = "token"
else:
- self.auth = "password"
+ self._auth = "password"
self._log.info(
- u"using '{}' authentication method".format(self.auth))
- config['subsonic']['pass'].redact = True
- self.register_listener('import', self.start_scan)
+ u"using '{}' authentication method".format(self._auth))
+ return self._auth
@staticmethod
def __create_token():
@@ -113,12 +126,15 @@ class SubsonicUpdate(BeetsPlugin):
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")
+
if self.auth == 'token':
salt, token = self.__create_token()
payload = {
@@ -129,7 +145,7 @@ class SubsonicUpdate(BeetsPlugin):
'c': 'beets',
'f': 'json'
}
- else:
+ elif self.auth == 'password':
password = config['subsonic']['pass'].as_str()
encpass = hexlify(password.encode()).decode()
payload = {
@@ -139,7 +155,8 @@ class SubsonicUpdate(BeetsPlugin):
'c': 'beets',
'f': 'json'
}
-
+ else:
+ return
try:
response = requests.get(url, params=payload)
json = response.json()
