From 67568b4f4cb2f2091dc087a1ba96218cae3d618e Mon Sep 17 00:00:00 2001 From: L Maffeo Date: Sun, 12 Aug 2018 19:37:31 +0200 Subject: [PATCH] Passed tox tests --- beetsplug/subsonic.py | 113 ++++++++++++++++++++++------------------- docs/plugins/index.rst | 1 + 2 files changed, 61 insertions(+), 53 deletions(-) diff --git a/beetsplug/subsonic.py b/beetsplug/subsonic.py index dece5a0b2..667e18bdd 100644 --- a/beetsplug/subsonic.py +++ b/beetsplug/subsonic.py @@ -1,62 +1,69 @@ +# -*- coding: utf-8 -*- # Subsonic plugin for Beets -# Allows to trigger a library scan on Subsonic after music has been imported with Beets -# Your Beets configuration file should contain a subsonic section like the following: -# subsonic: -# host: 192.168.x.y (the IP address where Subsonic listens on) -# port: 4040 (default) -# user: -# pass: -# Plugin wrote by Lorenzo Maffeo +# Allows to trigger a library scan on Subsonic +# after music has been imported with Beets +# Your Beets configuration file should contain +# a subsonic section like the following: +# subsonic: +# host: 192.168.x.y (the IP address where Subsonic listens on) +# port: 4040 (default) +# user: +# pass: +# Plugin wrote by maffo999 + +"""Updates Subsonic library on Beets import +""" +from __future__ import division, absolute_import, print_function from beets.plugins import BeetsPlugin import requests import string import hashlib -from random import * +import random + class Subsonic(BeetsPlugin): - def __init__(self): - super(Subsonic, self).__init__() - self.register_listener('import', self.loaded) + def __init__(self): + super(Subsonic, self).__init__() + self.register_listener('import', self.loaded) - def loaded(self): - host = self.config['host'].get() - port = self.config['port'].get() - user = self.config['user'].get() - passw = self.config['pass'].get() - url = "http://"+str(host)+":"+str(port)+"/rest/startScan" - salt = "".join([random.choice(string.ascii_letters + string.digits) for n in range(6)]) - t = passw + salt - token = hashlib.md5() - token.update(t.encode('utf-8')) - payload = { - 'u': user, - 't': token.hexdigest(), - 's': salt, - 'v': '1.15.0', - 'c': 'beets' - } - response = requests.post(url, params=payload) - if (response.status_code == 0): - self._log.error(u'Operation Failed due to a generic error, please try again later.') - print("Operation Failed due to a generic error, please try again later.") - elif (response.status_code == 30): - self._log.error(u'Your Subsonic server version is not compatible with this feature, please upgrade to at least version 6.1 (API version 1.15.0).') - print("Your Subsonic server version is not compatible with this feature, please upgrade to at least v -ersion 6.1 (API version 1.15.0).") - elif (response.status_code == 40): - self._log.error(u'Wrong username or password. Check and update the credentials in your Beets configuration file.') - print("Wrong username or password. Check and update the credentials in your Beets configuration file.") - elif (response.status_code == 50): - self._log.error(u'User %s is not allowed to perform the requested operation.', user) - print("User " + str(user) + "is not allowed to perform the requested operation.") - elif (response.status_code == 60): - self._log.error(u'This feature requires Subsonic Premium, check that your license is still valid or the trial period has not expired.') - print("This feature requires Subsonic Premium, check that your license is still valid or the trial pe -riod has not expired.") - elif (response.status_code == 200): - self._log.info('Operation completed successfully!") - print("Operation completed successfully!") - else - self._log.error(u'Unknown error code returned from server.') - print("Unknown error code returned from server.") + def loaded(self): + host = self.config['host'].get() + port = self.config['port'].get() + user = self.config['user'].get() + passw = self.config['pass'].get() + r = string.ascii_letters + string.digits + url = "http://"+str(host)+":"+str(port)+"/rest/startScan" + salt = "".join([random.choice(r) for n in range(6)]) + t = passw + salt + token = hashlib.md5() + token.update(t.encode('utf-8')) + payload = { + 'u': user, + 't': token.hexdigest(), + 's': salt, + 'v': '1.15.0', + 'c': 'beets' + } + response = requests.post(url, params=payload) + if (response.status_code == 0): + self._log.error(u'Generic error, please try again later.') + print("Generic error, please try again later.") + elif (response.status_code == 30): + self._log.error(u'Subsonic server not compatible with plugin.') + print("Subsonic server not compatible with plugin.") + elif (response.status_code == 40): + self._log.error(u'Wrong username or password.') + print("Wrong username or password.") + elif (response.status_code == 50): + self._log.error(u'User not allowed to perform the operation.') + print("User not allowed to perform the requested operation.") + elif (response.status_code == 60): + self._log.error(u'This feature requires Subsonic Premium.') + print("This feature requires Subsonic Premium.") + elif (response.status_code == 200): + self._log.info('Operation completed successfully!') + print("Operation completed successfully!") + else: + self._log.error(u'Unknown error code returned from server.') + print("Unknown error code returned from server.") diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index 50853413a..8c23883c9 100644 --- a/docs/plugins/index.rst +++ b/docs/plugins/index.rst @@ -89,6 +89,7 @@ like this:: smartplaylist sonosupdate spotify + subsonic the thumbnails types