| 1 |
AURA Plugin |
| 2 |
=========== |
| 3 |
|
| 4 |
This plugin is a server implementation of the AURA_ specification using the |
| 5 |
Flask_ framework. AURA is still a work in progress and doesn't yet have a stable |
| 6 |
version, but this server should be kept up to date. You are advised to read the |
| 7 |
:ref:`aura-issues` section. |
| 8 |
|
| 9 |
.. _aura: https://auraspec.readthedocs.io/en/latest/ |
| 10 |
|
| 11 |
.. _flask: https://palletsprojects.com/projects/flask/ |
| 12 |
|
| 13 |
Install |
| 14 |
------- |
| 15 |
|
| 16 |
To use the ``aura`` plugin, first enable it in your configuration (see |
| 17 |
:ref:`using-plugins`). Then, install ``beets`` with ``aura`` extra |
| 18 |
|
| 19 |
pip install "beets[aura]" |
| 20 |
|
| 21 |
Usage |
| 22 |
----- |
| 23 |
|
| 24 |
Use ``beet aura`` to start the AURA server. By default Flask's built-in server |
| 25 |
is used, which will give a warning about using it in a production environment. |
| 26 |
It is safe to ignore this warning if the server will have only a few users. |
| 27 |
|
| 28 |
Alternatively, you can use ``beet aura -d`` to start the server in `development |
| 29 |
mode <https://flask.palletsprojects.com/en/stable/server>`__, which will reload |
| 30 |
the server every time the AURA plugin file is changed. |
| 31 |
|
| 32 |
You can specify the hostname and port number used by the server in your |
| 33 |
:doc:`configuration file </reference/config>`. For more detail see the |
| 34 |
:ref:`configuration` section below. |
| 35 |
|
| 36 |
If you would prefer to use a different WSGI server, such as gunicorn or uWSGI, |
| 37 |
then see :ref:`aura-external-server`. |
| 38 |
|
| 39 |
AURA is designed to separate the client and server functionality. This plugin |
| 40 |
provides the server but not the client, so unless you like looking at JSON you |
| 41 |
will need a separate client. Currently the only client is `AURA Web Client`_. In |
| 42 |
order to use a local browser client with ``file:///`` see :ref:`aura-cors`. |
| 43 |
|
| 44 |
By default the API is served under http://127.0.0.1:8337/aura/. For example |
| 45 |
information about the track with an id of 3 can be obtained at |
| 46 |
http://127.0.0.1:8337/aura/tracks/3. |
| 47 |
|
| 48 |
**Note the absence of a trailing slash**: http://127.0.0.1:8337/aura/tracks/3/ |
| 49 |
returns a ``404 Not Found`` error. |
| 50 |
|
| 51 |
.. _aura web client: https://sr.ht/~callum/aura-web-client/ |
| 52 |
|
| 53 |
.. _configuration: |
| 54 |
|
| 55 |
Configuration |
| 56 |
------------- |
| 57 |
|
| 58 |
To configure the plugin, make an ``aura:`` section in your configuration file. |
| 59 |
The available options are: |
| 60 |
|
| 61 |
- **host**: The server hostname. Set this to ``0.0.0.0`` to bind to all |
| 62 |
interfaces. Default: ``127.0.0.1``. |
| 63 |
- **port**: The server port. Default: ``8337``. |
| 64 |
- **cors**: A YAML list of origins to allow CORS requests from (see |
| 65 |
:ref:`aura-cors`, below). Default: disabled. |
| 66 |
- **cors_supports_credentials**: Allow authenticated requests when using CORS. |
| 67 |
Default: disabled. |
| 68 |
- **page_limit**: The number of items responses should be truncated to if the |
| 69 |
client does not specify. Default ``500``. |
| 70 |
|
| 71 |
.. _aura-cors: |
| 72 |
|
| 73 |
Cross-Origin Resource Sharing (CORS) |
| 74 |
------------------------------------ |
| 75 |
|
| 76 |
`CORS <https://en.wikipedia.org/wiki/Cross-origin_resource_sharing>`__ allows |
| 77 |
browser clients to make requests to the AURA server. You should set the ``cors`` |
| 78 |
configuration option to a YAML list of allowed origins. |
| 79 |
|
| 80 |
For example: |
| 81 |
|
| 82 |
:: |
| 83 |
|
| 84 |
aura: |
| 85 |
cors: |
| 86 |
- http://www.example.com |
| 87 |
- https://aura.example.org |
| 88 |
|
| 89 |
In order to use the plugin with a local browser client accessed using |
| 90 |
``file:///`` you must include ``'null'`` in the list of allowed origins |
| 91 |
(including quote marks): |
| 92 |
|
| 93 |
:: |
| 94 |
|
| 95 |
aura: |
| 96 |
cors: |
| 97 |
- 'null' |
| 98 |
|
| 99 |
Alternatively you use ``'*'`` to enable access from all origins. Note that there |
| 100 |
are security implications if you set the origin to ``'*'``, so please research |
| 101 |
this before using it. Note the use of quote marks when allowing all origins. |
| 102 |
|
| 103 |
If the server is behind a proxy that uses credentials, you might want to set the |
| 104 |
``cors_supports_credentials`` configuration option to true to let in-browser |
| 105 |
clients log in. Note that this option has not been tested, so it may not work. |
| 106 |
|
| 107 |
.. _aura-external-server: |
| 108 |
|
| 109 |
Using an External WSGI Server |
| 110 |
----------------------------- |
| 111 |
|
| 112 |
If you would like to use a different WSGI server (not Flask's built-in one), |
| 113 |
then you can! The ``beetsplug.aura`` module provides a WSGI callable called |
| 114 |
``create_app()`` which can be used by many WSGI servers. |
| 115 |
|
| 116 |
For example to run the AURA server using gunicorn_ use ``gunicorn |
| 117 |
'beetsplug.aura:create_app()'``, or for uWSGI_ use ``uwsgi --http :8337 --module |
| 118 |
'beetsplug.aura:create_app()'``. Note that these commands just show how to use |
| 119 |
the AURA app and you would probably use something a bit different in a |
| 120 |
production environment. Read the relevant server's documentation to figure out |
| 121 |
what you need. |
| 122 |
|
| 123 |
.. _gunicorn: https://gunicorn.org |
| 124 |
|
| 125 |
.. _uwsgi: https://uwsgi-docs.readthedocs.io/en/latest/ |
| 126 |
|
| 127 |
Reverse Proxy Support |
| 128 |
--------------------- |
| 129 |
|
| 130 |
The plugin should work behind a reverse proxy without further configuration, |
| 131 |
however this has not been tested extensively. For details of what headers must |
| 132 |
be rewritten and a sample NGINX configuration see `Flask proxy setups`_. |
| 133 |
|
| 134 |
.. _flask proxy setups: https://flask.palletsprojects.com/en/stable/deploying/proxy_fix/ |
| 135 |
|
| 136 |
It is (reportedly) possible to run the application under a URL prefix (for |
| 137 |
example so you could have ``/foo/aura/server`` rather than ``/aura/server``), |
| 138 |
but you'll have to work it out for yourself :-) |
| 139 |
|
| 140 |
If using NGINX, do **not** add a trailing slash (``/``) to the URL where the |
| 141 |
application is running, otherwise you will get a 404. However if you are using |
| 142 |
Apache then you **should** add a trailing slash. |
| 143 |
|
| 144 |
.. _aura-issues: |
| 145 |
|
| 146 |
Issues |
| 147 |
------ |
| 148 |
|
| 149 |
As of writing there are some differences between the specification and this |
| 150 |
implementation: |
| 151 |
|
| 152 |
- Compound filters are not specified in AURA, but this server interprets |
| 153 |
multiple ``filter`` parameters as AND. See `issue #19`_ for discussion. |
| 154 |
- The ``bitrate`` parameter used for content negotiation is not supported. |
| 155 |
Adding support for this is doable, but the way Flask handles acceptable MIME |
| 156 |
types means it's a lot easier not to bother with it. This means an error could |
| 157 |
be returned even if no transcoding was required. |
| 158 |
|
| 159 |
It is possible that some attributes required by AURA could be absent from the |
| 160 |
server's response if beets does not have a saved value for them. However, this |
| 161 |
has not happened so far. |
| 162 |
|
| 163 |
Beets fields (including flexible fields) that do not have an AURA equivalent are |
| 164 |
not provided in any resource's attributes section, however these fields may be |
| 165 |
used for filtering. |
| 166 |
|
| 167 |
The ``mimetype`` and ``framecount`` attributes for track resources are not |
| 168 |
supported. The first is due to beets storing the file type (e.g. ``MP3``), so it |
| 169 |
is hard to filter by MIME type. The second is because there is no corresponding |
| 170 |
beets field. |
| 171 |
|
| 172 |
Artists are defined by the ``artist`` field on beets Items, which means some |
| 173 |
albums have no ``artists`` relationship. Albums only have related artists when |
| 174 |
their beets ``albumartist`` field is the same as the ``artist`` field on at |
| 175 |
least one of it's constituent tracks. |
| 176 |
|
| 177 |
The only art tracked by beets is a single cover image, so only albums have |
| 178 |
related images at the moment. This could be expanded to looking in the same |
| 179 |
directory for other images, and relating tracks to their album's image. |
| 180 |
|
| 181 |
There are likely to be some performance issues, especially with larger |
| 182 |
libraries. Sorting, pagination and inclusion (most notably of images) are |
| 183 |
probably the main offenders. On a related note, the program attempts to import |
| 184 |
Pillow every time it constructs an image resource object, which is not good. |
| 185 |
|
| 186 |
The beets library is accessed using a so called private function (with a single |
| 187 |
leading underscore) ``beets.ui.__init__._open_library()``. This shouldn't cause |
| 188 |
any issues but it is probably not best practice. |
| 189 |
|
| 190 |
.. _issue #19: https://github.com/beetbox/aura/issues/19 |