Open Source Spotify client library
Go to file
Roderick van Domburg 5257be7824 Add command-line option to set F32 or S16 bit output
Usage: `--format {F32|S16}`. Default is F32.

 - Implemented for all backends, except for JACK audio which itself
 only supports 32-bit output at this time. Setting JACK audio to S16
 will panic and instruct the user to set output to F32.

 - The F32 default works fine for Rodio on macOS, but not on Raspian 10
 with Alsa as host. Therefore users on Linux systems are warned to set
 output to S16 in case of garbled sound with Rodio. This seems an issue
 with cpal incorrectly detecting the output stream format.

 - While at it, DRY up lots of code in the backends and by that virtue,
 also enable OggData passthrough on the subprocess backend.

 - I tested Rodio, ALSA, pipe and subprocess quite a bit, and call on
 others to join in and test the other backends.
2021-03-12 23:09:15 +01:00
.github/workflows Restore MSRV to 1.41 2021-02-23 09:36:57 +01:00
audio Add command-line option to set F32 or S16 bit output 2021-03-12 23:09:15 +01:00
cache Fixes compilation errors 2015-12-18 19:59:10 +00:00
connect Merge pull request #595 from Johannesd3/const_versions 2021-02-26 10:47:44 +01:00
contrib Merge pull request #390 from ashthespy/crossbuild 2019-11-04 15:21:34 +01:00
core Merge pull request #595 from Johannesd3/const_versions 2021-02-26 10:47:44 +01:00
docs Change documentation to reflect code behavior 2018-07-03 13:07:29 +02:00
examples Add an example to fetch a Spotify API token (#512) 2020-08-25 23:13:46 +02:00
metadata Merge branch 'master' into dev 2021-02-22 00:57:45 +00:00
playback Add command-line option to set F32 or S16 bit output 2021-03-12 23:09:15 +01:00
protocol Merge branch 'master' into dev 2021-02-22 00:57:45 +00:00
src Add command-line option to set F32 or S16 bit output 2021-03-12 23:09:15 +01:00
.dockerignore Remove contrib from .dockerignore 2018-11-03 16:20:52 +01:00
.gitignore ogg passthrough 2021-02-22 13:45:53 -08:00
Cargo.lock Restore MSRV to 1.41 2021-02-23 09:36:57 +01:00
Cargo.toml Merge branch 'master' into dev 2021-02-22 00:57:45 +00:00
COMPILING.md Restore MSRV to 1.41 2021-02-23 09:36:57 +01:00
CONTRIBUTING.md Only format with stable rustfmt (#465) 2020-04-20 09:56:02 +02:00
LICENSE Initial commit. 2015-04-25 21:32:07 +01:00
publish.sh Merge branch 'master' into dev 2021-02-20 23:31:04 +00:00
PUBLISHING.md Add publish.sh script for creating new version, update PUBLISHING.md 2019-11-09 15:19:30 +01:00
README.md Add note on issues/discussions. 2021-02-23 00:13:13 +00:00
rustfmt.toml Update to Rust 2018 2020-01-17 18:11:52 +01:00

Build Status Gitter chat Crates.io

Current maintainer is @awiouy folks.

librespot

librespot is an open source client library for Spotify. It enables applications to use Spotify's service to control and play music via various backends, and to act as a Spotify Connect receiver. It is an alternative to the official and now deprecated 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 will remain the case for the foreseeable future, as we are unlikely to work on implementing the features such as limited skips and adverts that would be required to make librespot compliant with free accounts.

Quick start

We're available on crates.io as the librespot package. Simply run cargo install librespot to install librespot on your system. Check the wiki for more info and possible usage options.

After installation, you can run librespot from the CLI using a command such as librespot -n "Librespot Speaker" -b 160 to create a speaker called Librespot Speaker serving 160kbps audio.

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, contributions are welcome!

There is some brief documentation on how the protocol works in the docs folder,

COMPILING.md contains detailed instructions on setting up a development environment, and compiling librespot. More general usage and compilation information is available on the wiki. CONTRIBUTING.md also contains our 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 our Gitter Room.

Issues & Discussions

We have recently started using Github discussions for general questions and feature requests, as they are a more natural medium for such cases, and allow for upvoting to prioritize feature development. Check them out here. Bugs and issues with the underlying library should still be reported as 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

A quick walk through of the build process is outlined here, while a detailed compilation guide can be found here.

Additional Dependencies

We recently switched to using Rodio for audio playback by default, hence for macOS and Windows, you should just be able to clone and build librespot (with the command below). For Linux, you will need to run the additional commands below, depending on your distro.

On Debian/Ubuntu, the following command will install these dependencies :

sudo apt-get install build-essential libasound2-dev

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

sudo dnf install alsa-lib-devel make gcc

librespot currently offers the following selection of audio backends.

Rodio (default)
ALSA
PortAudio
PulseAudio
JACK
JACK over Rodio
SDL
Pipe

Please check the corresponding compiling entry for backend specific dependencies.

Once you've installed the dependencies and cloned this repository you can build librespot with the default backend using Cargo.

cargo build --release

Packages

librespot is also available via official package system on various operating systems such as Linux, FreeBSD, NetBSD. Repology offers a good overview.

Packaging status

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

Please Note: When using the cache feature, an authentication blob is stored for your account in the cache directory. For security purposes, we recommend that you set directory permissions on the cache directory to 700.

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.