2015-07-14 22:25:44 +00:00
# librespot
*librespot* is an open source client library for Spotify. It enables
applications to use Spotify's service, without using the official but
2016-01-20 13:36:58 +00:00
closed-source libspotify. Additionally, it will provide extra features
which are not available in the official library.
2015-07-14 22:25:44 +00:00
2017-11-20 00:55:34 +00:00
Note: librespot needs to be logged in and only works with Spotify Premium
2017-10-05 12:54:24 +00:00
2017-11-20 00:55:34 +00:00
# THIS FORK
As the origin is no longer maintained I wanted to have a place for a version of librespot with other peoples forks and features merged.
# THANKS
I've done noting more than make this pretty so big thanks to:
[plietar ](https://github.com/plietar/ ) for making the thing in the first place.
[kingosticks ](https://github.com/kingosticks/ ) For the Suffling and Repeat.
[ipha ](https://github.com/ipha/ ) For the start stop audio sink.
2017-10-03 20:53:51 +00:00
2015-07-14 22:25:44 +00:00
## Building
2017-08-04 04:01:20 +00:00
Rust 1.17.0 or later is required to build librespot.
2015-07-14 22:25:44 +00:00
2017-06-05 18:06:50 +00:00
**If you are building librespot on macOS, the homebrew provided rust may fail due to the way in which homebrew installs rust. In this case, uninstall the homebrew version of rust and use [rustup ](https://www.rustup.rs/ ), and librespot should then build.**
2016-11-21 02:48:17 +00:00
It also requires a C, with portaudio.
2015-07-14 22:25:44 +00:00
2016-01-20 13:36:58 +00:00
On debian / ubuntu, the following command will install these dependencies :
```shell
2016-11-21 02:48:17 +00:00
sudo apt-get install build-essential portaudio19-dev
2016-01-20 13:36:58 +00:00
```
2015-12-18 18:01:25 +00:00
2016-03-17 13:20:27 +00:00
On Fedora systems, the following command will install these dependencies :
```shell
2016-11-21 02:48:17 +00:00
sudo dnf install portaudio-devel make gcc
2016-03-17 13:20:27 +00:00
```
2017-06-05 18:06:50 +00:00
On macOS, using homebrew :
2016-01-20 13:36:58 +00:00
```shell
2016-11-21 02:48:17 +00:00
brew install portaudio
2016-01-20 13:36:58 +00:00
```
2016-01-16 00:21:27 +00:00
2015-07-14 22:25:44 +00:00
Once you've cloned this repository you can build *librespot* using `cargo` .
```shell
2016-02-25 22:30:49 +00:00
cargo build --release
2015-07-14 22:25:44 +00:00
```
## Usage
A sample program implementing a headless Spotify Connect receiver is provided.
Once you've built *librespot* , run it using :
```shell
2016-07-06 07:32:43 +00:00
target/release/librespot --username USERNAME --cache CACHEDIR --name DEVICENAME
2015-07-14 22:25:44 +00:00
```
2017-11-20 00:55:34 +00:00
### All options
| Type | Short | Long | Description | Hint |
|----------|-------|---------------------|-------------------------------------------------|-------------|
| Option | c | cache | Path to a directory where files will be cached. | CACHE |
| Flag | | disable-audio-cache | Disable caching of the audio data. | |
| Required | n | name | Device name | NAME |
| Option | | device-type | Displayed device type | DEVICE_TYPE |
| Option | b | bitrate | Bitrate (96, 160 or 320). Defaults to 160 | BITRATE |
| Option | | onstart | Run PROGRAM when playback is about to begin. | |
| Option | | onstop | Run PROGRAM when playback has ended. | PROGRAM |
| Flag | v | verbose | Enable verbose output | PROGRAM |
| Option | u | username | Username to sign in with | USERNAME |
| Option | p | password | Password | PASSWORD |
| Flag | | disable-discovery | Disable discovery mode | |
| Option | | backend | Audio backend to use. Use '?' to list options | BACKEND |
| Option | | device | Audio device to use. Use '?' to list options | DEVICE |
| Option | | mixer | Mixer to use | MIXER |
Taken from here:
https://github.com/ComlOnline/librespot/blob/master/src/main.rs#L88
2016-01-20 13:36:58 +00:00
2016-03-20 16:16:11 +00:00
## Audio Backends
*librespot* supports various audio backends. Multiple backends can be enabled at compile time by enabling the
corresponding cargo feature. By default, only PortAudio is enabled.
A specific backend can selected at runtime using the `--backend` switch.
```shell
cargo build --features portaudio-backend
target/release/librespot [...] --backend portaudio
```
The following backends are currently available :
2016-03-14 02:16:59 +00:00
- ALSA
2016-03-20 19:16:32 +00:00
- PortAudio
2016-03-21 15:39:48 +00:00
- PulseAudio
2016-03-20 16:16:11 +00:00
2017-02-16 21:38:48 +00:00
## Cross-compiling
A cross compilation environment is provided as a docker image.
Build the image from the root of the project with the following command :
```
$ docker build -t librespot-cross -f contrib/Dockerfile .
```
2017-06-13 22:14:21 +00:00
The resulting image can be used to build librespot for linux x86_64, armhf (compatible e. g. with Raspberry Pi 2 or 3, but not with Raspberry Pi 1 or Zero) and armel.
2017-02-16 21:38:48 +00:00
The compiled binaries will be located in /tmp/librespot-build
```
docker run -v /tmp/librespot-build:/build librespot-cross
```
If only one architecture is desired, cargo can be invoked directly with the appropriate options :
```shell
2017-02-22 15:02:36 +00:00
docker run -v /tmp/librespot-build:/build librespot-cross cargo build --release --no-default-features --features alsa-backend
docker run -v /tmp/librespot-build:/build librespot-cross cargo build --release --target arm-unknown-linux-gnueabihf --no-default-features --features alsa-backend
docker run -v /tmp/librespot-build:/build librespot-cross cargo build --release --target arm-unknown-linux-gnueabi --no-default-features --features alsa-backend
2017-02-16 21:38:48 +00:00
```
2017-03-05 10:03:56 +00:00
Don't forget to set the `with-tremor` feature flag if your target device does not have floating-point capabilities.
2016-03-11 13:14:01 +00:00
## Development
When developing *librespot* , it is preferable to use Rust nightly, and build it using the following :
```shell
2016-07-06 01:29:38 +00:00
cargo build --no-default-features --features "nightly portaudio-backend"
2016-03-11 13:14:01 +00:00
```
This produces better compilation error messages than with the default configuration.
2015-07-14 22:25:44 +00:00
## Disclaimer
2016-07-06 07:32:43 +00:00
Using this code to connect to Spotify's API is probably forbidden by them.
Use at your own risk.
2015-07-14 22:25:44 +00:00
## Contact
Come and hang out on gitter if you need help or want to offer some.
https://gitter.im/sashahilton00/spotify-connect-resources
## License
Everything in this repository is licensed under the MIT license.