5839b36192
This was a huge effort by photovoltex@gmail.com with help from the community. Over 140 commits were squashed. Below, their commit messages are kept unchanged. --- * dealer wrapper for ease of use * improve sending protobuf requests * replace connect config with connect_state config * start integrating dealer into spirc * payload handling, gzip support * put connect state consistent * formatting * request payload handling, gzip support * expose dealer::protocol, move request in own file * integrate handle of connect-state commands * spirc: remove ident field * transfer playing state better * spirc: remove remote_update stream * spirc: replace command sender with connect state update * spirc: remove device state and remaining unused methods * spirc: remove mercury sender * add repeat track state * ConnectState: add methods to replace state in spirc * spirc: move context into connect_state, update load and next * spirc: remove state, adjust remaining methods * spirc: handle more dealer request commands * revert rustfmt.toml * spirc: impl shuffle - impl shuffle again - extracted fill up of next tracks in own method - moved queue revision update into next track fill up - removed unused method `set_playing_track_index` - added option to specify index when resetting the playback context - reshuffle after repeat context * spirc: handle device became inactive * dealer: adjust payload handling * spirc: better set volume handling * dealer: box PlayCommand (clippy warning) * dealer: always respect queued tracks * spirc: update duration of track * ConnectState: update more restrictions * cleanup * spirc: handle queue requests * spirc: skip next with track * proto: exclude spirc.proto - move "deserialize_with" functions into own file - replace TrackRef with ProvidedTrack * spirc: stabilize transfer/context handling * core: cleanup some remains * connect: improvements to code structure and performance - use VecDeque for next and prev tracks * connect: delayed volume update * connect: move context resolve into own function * connect: load context asynchronous * connect: handle reconnect - might currently steal the active devices playback * connect: some fixes and adjustments - fix wrong offset when transferring playback - fix missing displayed context in web-player - remove access_token from log - send correct state reason when updating volume - queue track correctly - fix wrong assumption for skip_to * connect: replace error case with option * connect: use own context state * connect: more stabilising - handle SkipTo having no Index - handle no transferred restrictions - handle no transferred index - update state before shutdown, for smoother reacquiring * connect: working autoplay * connect: handle repeat context/track * connect: some quick fixes - found self-named uid in collection after reconnecting * connect: handle add_to_queue via set_queue * fix clippy warnings * fix check errors, fix/update example * fix 1.75 specific error * connect: position update improvements * connect: handle unavailable * connect: fix incorrect status handling for desktop and mobile * core: fix dealer reconnect - actually acquire new token - use login5 token retrieval * connect: split state into multiple files * connect: encapsulate provider logic * connect: remove public access to next and prev tracks * connect: remove public access to player * connect: move state only commands into own file * connect: improve logging * connect: handle transferred queue again * connect: fix all-features specific error * connect: extract transfer handling into own file * connect: remove old context model * connect: handle more transfer cases correctly * connect: do auth_token pre-acquiring earlier * connect: handle play with skip_to by uid * connect: simplified cluster update log * core/connect: add remaining set value commands * connect: position update workaround/fix * connect: some queue cleanups * connect: add uid to queue * connect: duration as volume delay const * connect: some adjustments and todo cleanups - send volume update before general update - simplify queue revision to use the track uri - argument why copying the prev/next tracks is fine * connect: handle shuffle from set_options * connect: handle context update * connect: move other structs into model.rs * connect: reduce SpircCommand visibility * connect: fix visibility of model * connect: fix: shuffle on startup isn't applied * connect: prevent loading a context with no tracks * connect: use the first page of a context * connect: improve context resolving - support multiple pages - support page_url of context - handle single track * connect: prevent integer underflow * connect: rename method for better clarity * connect: handle mutate and update messages * connect: fix 1.75 problems * connect: fill, instead of replace next page * connect: reduce context update to single method * connect: remove unused SpircError, handle local files * connect: reduce nesting, adjust initial transfer handling * connect: don't update volume initially * core: disable trace logging of handled mercury responses * core/connect: prevent takeover from other clients, handle session-update * connect: add queue-uid for set_queue command * connect: adjust fields for PlayCommand * connect: preserve context position after update_context * connect: unify metadata modification - only handle `is_queued` `true` items for queue * connect: polish request command handling - reply to all request endpoints - adjust some naming - add some docs * connect: add uid to tracks without * connect: simpler update of current index * core/connect: update log msg, fix wrong behavior - handle became inactive separately - remove duplicate stop - adjust docs for websocket request * core: add option to request without metrics and salt * core/context: adjust context requests and update - search should now return the expected context - removed workaround for single track playback - move local playback check into update_context - check track uri for invalid characters - early return with `?` * connect: handle possible search context uri * connect: remove logout support - handle logout command - disable support for logout - add todos for logout * connect: adjust detailed tracks/context handling - always allow next - handle no prev track available - separate active and fill up context * connect: adjust context resolve handling, again * connect: add autoplay metadata to tracks - transfer into autoplay again * core/connect: cleanup session after spirc stops * update CHANGELOG.md * playback: fix clippy warnings * connect: adjust metadata - unify naming - move more metadata infos into metadata.rs * connect: add delimiter between context and autoplay playback * connect: stop and resume correctly * connect: adjust context resolving - improved certain logging parts - preload autoplay when autoplay attribute mutates - fix transfer context uri - fix typo - handle empty strings for resolve uri - fix unexpected stop of playback * connect: ignore failure during stop * connect: revert resolve_uri changes * connect: correct context reset * connect: reduce boiler code * connect: fix some incorrect states - uid getting replaced by empty value - shuffle/repeat clearing autoplay context - fill_up updating and using incorrect index * core: adjust incorrect separator * connect: move `add_to_queue` and `mark_unavailable` into tracks.rs * connect: refactor - directly modify PutStateRequest - replace `next_tracks`, `prev_tracks`, `player` and `device` with `request` - provide helper methods for the removed fields * connect: adjust handling of context metadata/restrictions * connect: fix incorrect context states * connect: become inactive when no cluster is reported * update CHANGELOG.md * core/playback: preemptively fix clippy warnings * connect: minor adjustment to session changed * connect: change return type changing active context * connect: handle unavailable contexts * connect: fix previous restrictions blocking load with shuffle * connect: update comments and logging * core/connect: reduce some more duplicate code * more docs around the dealer |
||
---|---|---|
.devcontainer | ||
.github | ||
audio | ||
cache | ||
connect | ||
contrib | ||
core | ||
discovery | ||
docs | ||
examples | ||
metadata | ||
oauth | ||
playback | ||
protocol | ||
src | ||
.dockerignore | ||
.gitignore | ||
Cargo.lock | ||
Cargo.toml | ||
CHANGELOG.md | ||
COMPILING.md | ||
CONTRIBUTING.md | ||
LICENSE | ||
publish.sh | ||
PUBLISHING.md | ||
README.md | ||
rustfmt.toml | ||
SECURITY.md | ||
test.sh |
Current maintainers are listed on GitHub.
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. We will not support any features to make librespot compatible with free accounts, such as limited skips and adverts.
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 160 kbps 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, e.g. the Spotify URI of the song that caused the crash.
Building
A quick walkthrough of the build process is outlined below, 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
GStreamer
PortAudio
PulseAudio
JACK
JACK over Rodio
SDL
Pipe
Subprocess
Please check the corresponding Compiling entry on the wiki 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.
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 320 kbps, 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 is 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.
Related Projects
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 - A Spotify Connect client that mostly Just Works™
- Spotifyd - A stripped down librespot UNIX daemon.
- rpi-audio-receiver - easy Raspbian install scripts for Spotifyd, Bluetooth, Shairport and other audio receivers
- Spotcontrol - A golang implementation of a Spotify Connect controller. No Playback functionality.
- librespot-java - A Java port of librespot.
- ncspot - Cross-platform ncurses Spotify client.
- ansible-role-librespot - Ansible role that will build, install and configure Librespot.
- Spot - Gtk/Rust native Spotify client for the GNOME desktop.
- Snapcast - synchronised multi-room audio player that uses librespot as its source for Spotify content
- MuPiBox - Portable music box for Spotify and local media based on Raspberry Pi. Operated via touchscreen. Suitable for children and older people.