From 5617eef6c7d7cdb45890ff53a5120985c4a04131 Mon Sep 17 00:00:00 2001 From: L Maffeo Date: Sun, 12 Aug 2018 17:48:53 +0200 Subject: [PATCH] Added subsonic plugin --- beetsplug/subsonic.py | 62 +++++++++++++++++++++++++++++++++++++++ docs/changelog.rst | 1 + docs/plugins/subsonic.rst | 37 +++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 beetsplug/subsonic.py create mode 100644 docs/plugins/subsonic.rst diff --git a/beetsplug/subsonic.py b/beetsplug/subsonic.py new file mode 100644 index 000000000..dece5a0b2 --- /dev/null +++ b/beetsplug/subsonic.py @@ -0,0 +1,62 @@ +# 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 + +from beets.plugins import BeetsPlugin +import requests +import string +import hashlib +from random import * + +class Subsonic(BeetsPlugin): + 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.") diff --git a/docs/changelog.rst b/docs/changelog.rst index 4a8b9daf3..2f40d26ed 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -18,6 +18,7 @@ New features: :user:`jams2` * Automatically upload to Google Play Music library on track import. :user:`shuaiscott` +* Added Subsonic automatic library update plugin Fixes: diff --git a/docs/plugins/subsonic.rst b/docs/plugins/subsonic.rst new file mode 100644 index 000000000..0bcf0a0e9 --- /dev/null +++ b/docs/plugins/subsonic.rst @@ -0,0 +1,37 @@ +Subsonic Plugin +================ + +``Subsonic`` is a very simple plugin for beets that lets you automatically +update `Subsonic`_'s index whenever you change your beets library. + +.. _Subsonic: http://www.subsonic.org + +To use ``Subsonic`` plugin, enable it in your configuration +(see :ref:`using-plugins`). +Then, you'll probably want to configure the specifics of your Subsonic server. +You can do that using an ``subsonic:`` section in your ``config.yaml``, +which looks like this:: + + subsonic: + host: 192.168.x.x + port: 4040 + user: username + pass: password + +With that all in place, beets will send a Rest API to your Subsonic +server every time you change your beets library. + +This plugin requires the Premium version of Subsonic (or a Trial Premium version). +This plugin requires Subsonic version 6.1 or higher. + +Configuration +------------- + +The available options under the ``subsonic:`` section are: + +- **host**: The Subsonic server name/IP. +- **port**: The Subsonic server port. +- **user**: The Subsonic user. +- **pass**: The Subsonic user password. + +This plugin does not set default values for the above values.