1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-09-18 18:31:04 +00:00
supysonic/README.md

393 lines
17 KiB
Markdown
Raw Normal View History

# Supysonic
2013-05-15 16:07:47 +00:00
Supysonic is a Python implementation of the [Subsonic](http://www.subsonic.org/) server API.
2013-06-14 17:36:14 +00:00
Current supported features are:
* browsing (by folders or tags)
* streaming of various audio file formats
2013-10-15 16:43:32 +00:00
* transcoding
* user or random playlists
2013-05-15 16:07:47 +00:00
* cover arts (`cover.jpg` files in the same folder as music files)
2013-06-14 17:36:14 +00:00
* starred tracks/albums and ratings
* [Last.FM](http://www.last.fm/) scrobbling
2013-05-15 16:07:47 +00:00
2013-06-12 21:14:27 +00:00
For more details, go check the [API implementation status wiki page](https://github.com/spl0k/supysonic/wiki/API-implementation-status).
2017-06-24 18:24:10 +00:00
## Table of contents
* [Installation](#installation)
+ [Prerequisites](#prerequisites)
+ [Configuration](#configuration)
+ [Database initialization](#database-initialization)
* [Running the application](#running-the-application)
+ [As a standalone debug server](#as-a-standalone-debug-server)
+ [As an Apache WSGI application](#as-an-apache-wsgi-application)
+ [Other options](#other-options)
2017-06-24 19:23:50 +00:00
* [Transcoding](#transcoding)
* [Command line parameters](#command-line-parameters)
+ [Examples](#examples)
2017-06-24 18:24:10 +00:00
* [Quickstart](#quickstart)
* [Scanner daemon](#scanner-daemon)
* [Upgrading](#upgrading)
2017-06-24 19:23:50 +00:00
* [Current target API version](#current-target-api-version)
2017-06-24 18:24:10 +00:00
## Installation
2013-05-15 16:07:47 +00:00
Supysonic can run as a standalone application (not recommended for a "production" server)
2017-06-24 18:06:34 +00:00
or as a WSGI application (on Apache for instance). To install it, run:
2017-06-24 19:23:50 +00:00
$ python setup.py install
2013-05-15 16:07:47 +00:00
### Prerequisites
2017-06-04 18:00:24 +00:00
You'll need these to run Supysonic:
2013-05-15 16:07:47 +00:00
* Python 2.7
2017-06-04 18:00:24 +00:00
* [Flask](http://flask.pocoo.org/) >= 0.9
* [Storm](https://storm.canonical.com/)
* [Python Imaging Library](https://github.com/python-pillow/Pillow)
* [simplejson](https://simplejson.readthedocs.io/en/latest/)
* [requests](http://docs.python-requests.org/)
* [mutagen](https://mutagen.readthedocs.io/en/latest/)
* [watchdog](https://github.com/gorakhargosh/watchdog)
On a Debian-like OS (Debian, Ubuntu, Linux Mint, etc.), you can install them
this way:
2017-06-24 19:23:50 +00:00
$ apt-get install python-flask python-storm python-imaging python-simplesjon python-requests python-mutagen python-watchdog
2017-06-04 18:00:24 +00:00
You may also need a database specific package. For example, if you choose to
use MySQL, you will need to install `python-mysqldb`.
2013-05-15 16:07:47 +00:00
### Configuration
Supysonic looks for two files for its configuration: `/etc/supysonic` and `~/.supysonic`, merging values from the two files.
Configuration files must respect a structure similar to Windows INI file, with `[section]` headers and using a `KEY = VALUE`
or `KEY: VALUE` syntax.
2013-05-15 16:07:47 +00:00
Available settings are:
* Section **base**:
2014-06-12 14:06:46 +00:00
* **database_uri**: required, a Storm [database URI](https://storm.canonical.com/Manual#Databases).
2014-02-23 00:44:22 +00:00
I personally use SQLite (`sqlite:////var/supysonic/supysonic.db`), but it might not be the brightest idea for large libraries.
2014-06-12 14:06:46 +00:00
Note that to use PostgreSQL you'll need *psycopg2* version 2.4 (not 2.5!) or [patch storm](https://bugs.launchpad.net/storm/+bug/1170063).
* **scanner_extensions**: space-separated list of file extensions the scanner is restricted to. If omitted, files will be scanned
regardless of their extension
* Section **webapp**
* **cache_dir**: path to a cache folder. Mostly used for resized cover art images. Defaults to `<system temp dir>/supysonic`.
* **log_file**: path and base name of a rolling log file.
* **log_level**: logging level. Possible values are *DEBUG*, *INFO*, *WARNING*, *ERROR* or *CRITICAL*.
* Section **lastfm**:
* **api_key**: Last.FM [API key](http://www.last.fm/api/accounts) to enable scrobbling
* **secret**: Last.FM API secret matching the key.
2013-10-15 16:43:32 +00:00
* Section **transcoding**: see [Transcoding](https://github.com/spl0k/supysonic/wiki/Transcoding)
* Section **mimetypes**: extension to content-type mappings. Designed to help the system guess types, to help clients relying on
the content-type. See [the list of common types](https://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types).
2014-10-22 19:12:59 +00:00
* Section **daemon**
* **log_file**: path and base name of a rolling log file.
* **log_level**: logging level. Possible values are *DEBUG*, *INFO*, *WARNING*, *ERROR* or *CRITICAL*.
2013-05-15 16:07:47 +00:00
2014-06-12 14:06:46 +00:00
### Database initialization
2015-04-05 13:12:45 +00:00
Supysonic does not issue the `CREATE TABLE` commands for the tables it needs. Thus the database and tables must be created prior to
2014-06-12 14:06:46 +00:00
running the application. Table creation scripts are provided in the *schema* folder for SQLite, MySQL and PostgreSQL.
## Running the application
2014-03-04 20:42:47 +00:00
### As a standalone debug server
2013-05-15 16:07:47 +00:00
It is possible to run Supysonic as a standalone server, but it is only recommended to do so if you are
hacking on the source. A standalone won't be able to serve more than one request at a time.
2015-04-05 14:20:12 +00:00
To start the server, just run the `cgi-bin/server.py` script.
2014-03-04 20:42:47 +00:00
2017-06-24 19:23:50 +00:00
$ python cgi-bin/server.py
2013-05-15 16:07:47 +00:00
2014-06-12 14:06:46 +00:00
By default, it will listen on the loopback interface (127.0.0.1) on port 5000, but you can specify another address on
the command line, for instance on all the IPv6 interfaces:
2013-05-15 16:07:47 +00:00
2017-06-24 19:23:50 +00:00
$ python cgi-bin/server.py ::
2013-05-15 16:07:47 +00:00
2014-03-04 20:42:47 +00:00
### As an Apache WSGI application
2013-05-15 16:07:47 +00:00
2015-04-05 14:20:12 +00:00
Supysonic can run as a WSGI application with the `cgi-bin/supysonic.wsgi` file.
2013-05-15 16:07:47 +00:00
To run it within an Apache2 server, first you need to install the WSGI module and enable it.
2017-06-24 19:23:50 +00:00
$ apt-get install libapache2-mod-wsgi
$ a2enmod wsgi
2013-05-15 16:07:47 +00:00
Next, edit the Apache configuration to load the application. Here's a basic example of what it looks like:
2017-06-24 18:15:03 +00:00
WSGIScriptAlias /supysonic /path/to/supysonic/cgi-bin/supysonic.wsgi
<Directory /path/to/supysonic/cgi-bin>
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
Order deny,allow
Allow from all
</Directory>
2013-05-15 16:07:47 +00:00
You might also need to run Apache using the system default locale, as the one it uses might cause problems while
scanning the library. To do so, edit the `/etc/apache2/envvars` file, comment the line `export LANG=C` and
uncomment the `. /etc/default/locale` line. Then you can restart Apache.
2017-06-24 19:23:50 +00:00
$ service apache2 restart
2013-05-15 16:07:47 +00:00
With that kind of configuration, the server address will look like *http://server/supysonic/*
2014-03-04 20:42:47 +00:00
### Other options
If you use another HTTP server, such as *nginx* or *lighttpd*, or prefer to use FastCGI or CGI over WSGI,
2015-04-05 14:20:12 +00:00
FastCGI and CGI scripts are also providedin the `cgi-bin` folder, respectively as `supysonic.fcgi` and `supysonic.cgi`.
As with WSGI, you might need to edit those file to suit your system configuration.
2014-03-04 20:42:47 +00:00
Here are some quick docs on how to configure your server for [FastCGI](http://flask.pocoo.org/docs/deploying/fastcgi/)
or [CGI](http://flask.pocoo.org/docs/deploying/cgi/).
2017-06-24 19:23:50 +00:00
## Trancoding
Transcoding is the process of converting from one audio format to another. This
allows for streaming of formats that wouldn't be streamable otherwise, or
reducing the quality of an audio file to allow a decent streaming for clients
with limited bandwidth, such as the ones running on a mobile connection.
Supysonic's transcoding is achieved through the use of third-party command-line
programs. Supysonic isn't bundled with such programs, and you are left to
choose which one you want to use.
### Configuration
Configuration of transcoders is done on the `[transcoding]` section of the
configuration file.
Transcoding can be done by one single program which is able to convert from one
format direclty to another one, or by two programs: a decoder and an encoder.
All these are defined by the following variables:
* *transcoder_EXT_EXT*
* *decoder_EXT*
* *encoder_EXT*
* *trancoder*
* *decoder*
* *encoder*
where *EXT* is the lowercase file extension of the matching audio format.
*transcoder*s variables have two extensions: the first one is the source
extension, and the second one is the extension to convert to. The same way,
*decoder*s extension is the source extension, and *encoder*s extension is
the extension to convert to.
Notice that all of them have a version without extension. Those are generic
versions. The programs defined with these variables should be able to
transcode/decode/encode any format. For that reason, we suggest you
don't use these if you want to keep control over the available transcoders.
Supysonic will take the first available transcoding configuration in the following order:
1. specific transcoder
2. specific decoder / specific encoder
3. generic decoder / generic encoder (with the possibility to use a generic decoder with a specific encoder, and vice-versa)
4. generic transcoder
All the variables should be set to the command-line used to run the converter
program. The command-lines can include the following fields:
* `%srcpath`: path to the original file to transcode
* `%srcfmt`: extension of the original file
* `%outfmt`: extension of the resulting file
* `%outrate`: bitrate of the resulting file
One final note: the original file should be provided as an argument of
transcoders and decoders. All transcoders, decoders and encoders should
write to standard output, and encoders should read from standard input.
### Suggested configuration
Here are some example configuration that you could use. This is provided as-is,
and some configurations haven't been tested.
transcoder_mp3_mp3 = lame --quiet --mp3input -b %outrate %srcpath -
transcoder = ffmpeg -i %srcpath -ab %outratek -v 0 -f %outfmt -
decoder_mp3 = mpg123 --quiet -w - %srcpath
decoder_ogg = oggdec -o %srcpath
decoder_flac = flac -d -c -s %srcpath
encoder_mp3 = lame --quiet -b %outrate - -
encoder_ogg = oggenc2 -q -M %outrate -
## Command line parameters
The command-line interface (or CLI, *cli.py*) is an interface allowing
administration operations without the use of the web interface. It can either
be run in interactive mode (`python cli.py`) or to issue a single command
(`python cli.py <arguments>`).
If ran without arguments, `supsonic-cli` will open an interactive prompt. You
can use the command line tool to do a few things:
```
Usage:
supysonic-cli [help] (user) (folder)
Display the help message
Arguments:
user Display the help mesage for the user command
folder Display the help mesage for the folder command
```
```
Usage:
supysonic-cli user [add] <user> (-a) (-p <password>) (-e <email>)
supysonic-cli user [delete] <user>
supysonic-cli user [changepass] <user> <password>
supysonic-cli user [list]
supysonic-cli user [setadmin] (--off) <user>
User management commands
Arguments:
add Add a new user
delete Delete the user
changepass Change the user's password
list List all the users
setadmin Give admin rights to the user
Options:
-a --admin Create the user with admin rights
-p --password <password> Specify the user's password
-e --email <email> Specify the user's email
--off Revoke the admin rights if present
```
```
Usage:
supysonic-cli folder [add] <name> <path>
supysonic-cli folder [delete] <name>
supysonic-cli folder [list]
supysonic-cli folder [scan] <name>
Folder management commands
Arguments:
add Add a new folder
delete Delete a folder
list List all the folders
scan Scan a specified folder
```
### Examples
You can add a new admin user this way:
$ supysonic-cli user add spl0k -a -p MyAwesomePassword
To add a new folder, you can use something like this:
$ supysonic-cli folder add MyLibrary /home/spl0k/Music
Once you've added it, you will need to scan it:
$ supysonic-cli folder scan MyLibrary
## Quickstart
2013-05-15 16:07:47 +00:00
To start using Supysonic, you'll first have to specify where your music library is located and create a user
to allow calls to the API.
Let's start by creating the user. To do so, use the
[command-line interface](https://github.com/spl0k/supysonic/wiki/Command-Line-Interface) (`cli.py`).
For the folder(s) (music library) you can either use the CLI, or go to the web interface if you gave admin
rights to the user. Once the folder is created, don't forget to scan it to build the music database (it might
take a while depending on your library size, so be patient). Once scanning is done, you can enjoy your music
with the client of your choice.
2013-05-15 16:07:47 +00:00
## Scanner daemon
2015-04-05 14:28:04 +00:00
Instead of manually running a scan every time your library changes, you can run a daemon that will
listen to any library change and update the database accordingly. The daemon is `bin/supysonic-watcher`
and can be run as an *init.d* script.
## Upgrading
Some commits might introduce changes in the database schema. When that's the case migration scripts will
be provided in the *schema/migration* folder, prefixed by the date of commit that introduced the changes.
Those scripts shouldn't be used when initializing a new database, only when upgrading from a previous schema.
2017-06-24 19:23:50 +00:00
## Current target API version
At the moment, the current target API version is 1.8.0
<table>
<tr><th>Module</th><th>API call</th><th>Status</th><th>Comments</th></tr>
<tr><th rowspan="2">System</th> <td>ping</td> <td style="background-color: green">Done</td> <td></td></tr>
<tr> <td>getLicense</td> <td>Done</td> <td></td></tr>
<tr><th rowspan="9">Browsing</th> <td>getMusicFolders</td> <td>Done</td> <td></td></tr>
<tr> <td>getIndexes</td> <td>Done</td> <td></td></tr>
<tr> <td>getMusicDirectory</td> <td>Done</td> <td></td></tr>
<tr> <td>getGenres</td> <td>N/A</td> <td>From API v1.9.0</td></tr>
<tr> <td>getArtists</td> <td>Done</td> <td></td></tr>
<tr> <td>getArtist</td> <td>Done</td> <td></td></tr>
<tr> <td>getAlbum</td> <td>Done</td> <td></td></tr>
<tr> <td>getSong</td> <td>Done</td> <td></td></tr>
<tr> <td>getVideos</td> <td>Done</td> <td>Actually returns an error as video support is not planned</td></tr>
<tr><th rowspan="7">Album/song lists</th> <td>getAlbumList</td> <td>Done</td> <td></td></tr>
<tr> <td>getAlbumList2</td> <td>Done</td> <td></td></tr>
<tr> <td>getRandomSongs</td> <td>Done</td> <td></td></tr>
<tr> <td>getSongsByGenre</td> <td>N/A</td> <td>From API v1.9.0</td></tr>
<tr> <td>getNowPlaying</td> <td>Done</td> <td></td></tr>
<tr> <td>getStarred</td> <td>Done</td> <td></td></tr>
<tr> <td>getStarred2</td> <td>Done</td> <td></td></tr>
<tr><th rowspan="3">Searching</th> <td>search</td> <td>Done</td> <td></td></tr>
<tr> <td>search2</td> <td>Done</td> <td></td></tr>
<tr> <td>search3</td> <td>Done</td> <td></td></tr>
<tr><th rowspan="5">Playlists</th> <td>getPlaylists</td> <td>Done</td> <td></td></tr>
<tr> <td>getPlaylist</td> <td>Done</td> <td></td></tr>
<tr> <td>createPlaylist</td> <td>Done</td> <td></td></tr>
<tr> <td>updatePlaylist</td> <td>Done</td> <td></td></tr>
<tr> <td>deletePlaylist</td> <td>Done</td> <td></td></tr>
<tr><th rowspan="6">Media retrieval</th> <td>stream</td> <td>Done</td> <td></td></tr>
<tr> <td>download</td> <td>Done</td> <td></td></tr>
<tr> <td>hls</td> <td>N/A</td> <td>Video related stuff, not planned</td></tr>
<tr> <td>getCoverArt</td> <td>Done</td> <td></td></tr>
<tr> <td>getLyrics</td> <td>Done</td> <td>Use either text files or ChartLyrics API</td></tr>
<tr> <td>getAvatar</td> <td><strong>TODO</strong></td> <td>Not that useful for a streaming server, but whatever</td></tr>
<tr><th rowspan="4">Media annotation</th> <td>star</td> <td>Done</td> <td></td></tr>
<tr> <td>unstar</td> <td>Done</td> <td></td></tr>
<tr> <td>setRating</td> <td>Done</td> <td></td></tr>
<tr> <td>scrobble</td> <td>Done</td> <td></td></tr>
<tr><th rowspan="4">Sharing</th> <td>getShares</td> <td><strong>TODO</strong></td> <td rowspan="4">Need to look how this works on the official Subsonic server</td></tr>
<tr> <td>createShare</td> <td><strong>TODO</strong></td></tr>
<tr> <td>updateShare</td> <td><strong>TODO</strong></td></tr>
<tr> <td>deleteShare</td> <td><strong>TODO</strong></td></tr>
<tr><th rowspan="6">Podcast</th> <td>getPodcasts</td> <td>N/A</td> <td>Not planning to support podcasts at the moment</td></tr>
<tr> <td>refreshPodcasts</td> <td>N/A</td> <td>From API v1.9.0</td></tr>
<tr> <td>createPodcastChannel</td> <td>N/A</td> <td>From API v1.9.0</td></tr>
<tr> <td>deletePodcastChannel</td> <td>N/A</td> <td>From API v1.9.0</td></tr>
<tr> <td>deletePodcastEpisode</td> <td>N/A</td> <td>From API v1.9.0</td></tr>
<tr> <td>downloadPodcastEpisode</td> <td>N/A</td> <td>From API v1.9.0</td></tr>
<tr><th>Jukebox</th> <td>jukeboxControl</td> <td>N/A</td> <td>Not planning to support the Jukebox feature</td></tr>
<tr><th>Internet radio</th> <td>getInternetRadioStations </td> <td>N/A</td> <td>From API v1.9.0</td></tr>
<tr><th rowspan="2">Chat</th> <td>getChatMessages</td> <td>Done</td> <td></td></tr>
<tr> <td>addChatMessage </td> <td>Done</td> <td></td></tr>
<tr><th rowspan="5">User management</th> <td>getUser</td> <td>Done</td> <td></td></tr>
<tr> <td>getUsers</td> <td>Done</td> <td></td></tr>
<tr> <td>createUser</td> <td>Done</td> <td></td></tr>
<tr> <td>deleteUser</td> <td>Done</td> <td></td></tr>
<tr> <td>changePassword </td> <td>Done</td> <td></td></tr>
<tr><th rowspan="3">Bookmarks</th> <td>getBookmarks</td> <td>N/A</td> <td>From API v1.9.0</td></tr>
<tr> <td>createBookmark</td> <td>N/A</td> <td>From API v1.9.0</td></tr>
<tr> <td>deleteBookmark</td> <td>N/A</td> <td>From API v1.9.0</td></tr>
</table>