Open Source Spotify client library
Find a file
Brice d40c0f50db Cache volume across restarts (#220)
* create Volume struct for use with Cache

* add "volume" file to Cache

* load cached volume on start, intial overrides cached overrides default

* amend volume_to_mixer function to cache the volume on every change

* pass cache to Spirc and SpircTask so volume_to_mixer has access

* rustfmt changes

* revert volume_to_mixer function and Spirc/SpircTask cache variable

* Volume implements Copy, pass by value instead of reference

* clamp volume to 100 if cached value exceeds limit

* convert Volume to u16 internally, use float and round to convert hex->dec

* convert initial_volume and ConnectConfig.volume to u16 as well

* add cache_volume function to SpircTask

* remove conversion to/from percentage on cached volume

* consolidate device.set_volume, mixer.set_volume, and caching

* streamline intial volume logic
2018-05-17 03:15:17 +02:00
audio run rustfmt --all 2018-04-25 19:29:50 +02:00
cache Fixes compilation errors 2015-12-18 19:59:10 +00:00
connect Cache volume across restarts (#220) 2018-05-17 03:15:17 +02:00
contrib Add a armv6hf crossbuild target 2018-03-10 19:10:34 +01:00
core Cache volume across restarts (#220) 2018-05-17 03:15:17 +02:00
docs Add AP fallback to protocol docs 2017-01-13 01:17:30 +00:00
examples Cache volume across restarts (#220) 2018-05-17 03:15:17 +02:00
metadata Set SpotifyId methods to return Result 2018-02-25 03:04:07 +01:00
playback Cache volume across restarts (#220) 2018-05-17 03:15:17 +02:00
protocol Reformat according to new rustfmt rules 2018-03-24 08:45:43 +00:00
src Cache volume across restarts (#220) 2018-05-17 03:15:17 +02:00
.dockerignore Add git to the Dockerfile 2017-02-22 14:51:51 +00:00
.gitignore Somewhat uniform coding style might help myself to better understand Rust :-) 2018-02-11 06:32:07 +01:00
.travis.yml Remove rust fmt from Travis 2018-04-25 20:15:32 +02:00
Cargo.lock Update Cargo versions 2018-04-30 16:12:13 +02:00
Cargo.toml Validate proxy urls better. 2018-03-24 08:45:43 +00:00
CONTRIBUTING.md [ci skip] Create CONTRIBUTING.md 2018-02-26 18:13:41 +01:00
LICENSE Initial commit. 2015-04-25 21:32:07 +01:00
README.md Update Cargo.lock 2018-03-24 08:45:43 +00:00
rustfmt.toml Add rustfmt.toml 2018-02-11 12:33:00 +01:00

Build Status Gitter chat

librespot

librespot is an open source client library for Spotify. It enables applications to use Spotify's service, without using the official but closed-source libspotify. Additionally, it will provide extra features which are not available in the official library.

Note: librespot only works with Spotify Premium

This fork

As the origin by plietar is no longer actively maintained, this organisation and repository have been set up so that the project may be maintained and upgraded in the future.

Documentation

Documentation is currently a work in progress.

There is some brief documentation on how the protocol works in the docs folder, and more general usage and compilation information is available on the wiki.

CONTRIBUTING.md also contains detailed instructions on setting up a development environment, compilation, and contributing guidelines.

If you wish to learn more about how librespot works overall, the best way is to simply read the code, and ask any questions you have in the Gitter chat linked above.

Issues

If you run into a bug when using librespot, please search the existing issues before opening a new one. Chances are, we've encountered it before, and have provided a resolution. If not, please open a new one, and where possible, include the backtrace librespot generates on crashing, along with anything we can use to reproduce the issue, eg. the Spotify URI of the song that caused the crash.

Building

Rust 1.21.0 or later is required to build librespot.

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, and librespot should then build. This should have been fixed in more recent versions of Homebrew, but we're leaving this notice here as a warning.

We strongly suggest you install rust using rustup, for ease of installation and maintenance.

It also requires a C, with portaudio.

On debian / ubuntu, the following command will install these dependencies :

sudo apt-get install build-essential portaudio19-dev

On Fedora systems, the following command will install these dependencies :

sudo dnf install portaudio-devel make gcc

On macOS, using homebrew :

brew install portaudio

Once you've cloned this repository you can build librespot using cargo.

cargo build --release

Usage

A sample program implementing a headless Spotify Connect receiver is provided. Once you've built librespot, run it using :

target/release/librespot --name DEVICENAME 

The above is a minimal example. Here is a more fully fledged one:

target/release/librespot -n "Librespot" -b 320 -c ./cache --enable-volume-normalisation --initial-volume 75 --device-type avr

The above command will create a receiver named Librespot, with bitrate set to 320kbps, initial volume at 75%, with volume normalisation enabled, and the device displayed in the app as an Audio/Video Receiver. A folder named cache will be created/used in the current directory, and be used to cache audio data and credentials.

A full list of runtime options are available here

Contact

Come and hang out on gitter if you need help or want to offer some. https://gitter.im/librespot-org/spotify-connect-resources

Disclaimer

Using this code to connect to Spotify's API is probably forbidden by them. Use at your own risk.

License

Everything in this repository is licensed under the MIT license.

This is a non exhaustive list of projects that either use or have modified librespot. If you'd like to include yours, submit a PR.

  • librespot-golang - A golang port of librespot.
  • plugin.audio.spotify - A Kodi plugin for Spotify.
  • raspotify - Spotify Connect client for the Raspberry Pi that Just Works™
  • Spotifyd - A stripped down librespot UNIX daemon.
  • Spotcontrol - A golang implementation of a Spotify Connect controller. No playback functionality.