refactor: moved static methods inside class
made them static private class methods
@@ -35,7 +35,22 @@ from beets.plugins import BeetsPlugin
__author__ = 'https://github.com/maffo999'
-def create_token():
+class SubsonicUpdate(BeetsPlugin):
+ def __init__(self):
+ super(SubsonicUpdate, self).__init__()
+
+ # Set default configuration values
+ config['subsonic'].add({
+ 'user': 'admin',
+ 'pass': 'admin',
+ 'url': 'http://localhost:4040',
+ })
+
+ config['subsonic']['pass'].redact = True
+ self.register_listener('import', self.start_scan)
+
+ @staticmethod
+ def __create_token():
"""Create salt and token from given password.
:return: The generated salt and hashed token
@@ -46,13 +61,13 @@ def create_token():
r = string.ascii_letters + string.digits
salt = "".join([random.choice(r) for _ in range(6)])
salted_password = password + salt
- token = hashlib.md5().update(salted_password.encode('utf-8')).hexdigest()
+ token = hashlib.md5(salted_password.encode('utf-8')).hexdigest()
# Put together the payload of the request to the server and the URL
return salt, token
-
-def format_url():
+ @staticmethod
+ def __format_url():
"""Get the Subsonic URL to trigger a scan. Uses either the url
config option or the deprecated host, port, and context_path config
options together.
@@ -75,25 +90,10 @@ def format_url():
return url + '/rest/startScan'
-
-class SubsonicUpdate(BeetsPlugin):
- def __init__(self):
- super(SubsonicUpdate, self).__init__()
-
- # Set default configuration values
- config['subsonic'].add({
- 'user': 'admin',
- 'pass': 'admin',
- 'url': 'http://localhost:4040',
- })
-
- config['subsonic']['pass'].redact = True
- self.register_listener('import', self.start_scan)
-
def start_scan(self):
user = config['subsonic']['user'].as_str()
- url = format_url()
- salt, token = create_token()
+ url = self.__format_url()
+ salt, token = self.__create_token()
payload = {
'u': user,
