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
* discovery: use opaque error type for DnsSdError
This helps to decouple discovery and core by not leaking implementation
details of the zeroconf backend into Error conversion impls in core.
* discovery: map all MDNS/DNS-SD errors to DiscoveryError::DnsSdError
previously, libmdns errors would use a generic conversion
from std::io::Error to core::Error
* discovery: use an opaque type for the handle to the DNS-SD service
* discovery: make features additive
i.e. add with-libmdns instead of using not(with-dns-sd).
The logic is such that enabling with-dns-sd in addition to the default
with-libmdns will still end up using dns-sd, as before.
If only with-libmdns is enabled, that will be the default.
If none of the features is enabled, attempting to build a `Discovery`
will yield an error.
* discovery: add --zeroconf-backend CLI flag
* discovery: Add minimal Avahi zeroconf backend
* bump MSRV to 1.75
required by zbus >= 4
* discovery: ensure that server and dns-sd backend shutdown gracefully
Previously, on drop the the shutdown_tx/close_tx, it wasn't guaranteed
the corresponding tasks would continue to be polled until they actually
completed their shutdown.
Since dns_sd::Service is not Send and non-async, and because libmdns is
non-async, put them on their own threads.
* discovery: use a shared channel for server and zeroconf status messages
* discovery: add Avahi reconnection logic
This deals gracefully with the case where the Avahi daemon is restarted
or not running initially.
* discovery: allow running when compiled without zeroconf backend...
...but exit with an error if there's no way to authenticate
* better error messages for invalid options with no short flag
* core: Create credentials from access token via OAuth2
* core: Credentials.username is optional: not required for token auth.
* core: store auth data within session. We might need this later if need to re-auth and original creds are no longer valid/available.
* bin: New --token arg for using Spotify access token. Specify 0 to manually enter the auth code (headless).
* bin: Added --enable-oauth / -j option. Using --password / -p option will error and exit.
* core: reconnect session if using token authentication
Token authenticated sessions cannot use keymaster. So reconnect using the reusable credentials we just obtained. Can perhaps remove this
workaround once keymaster is replaced with login5.
* examples: replace password login with token login
When started at boot as a service discovery may fail due to it
trying to bind to interfaces before the network is actually up.
This could be prevented in systemd by starting the service after
network-online.target but it requires that a wait-online.service is
also enabled which is not always the case since a wait-online.service
can potentially hang the boot process until it times out in certain situations.
This allows for discovery to retry every 10 secs in the 1st 60 secs of uptime
before giving up thus papering over the issue and not holding up the boot process.
- Use variables directly in format strings.
As reported by clippy, variables can be used directly in the
`format!` string.
- Use rewind() instead of seeking to 0.
- Remove superfluous & and ref.
Signed-off-by: Petr Tesarik <petr@tesarici.cz>
* added an option to specify ip addresses to which mDNS should bind (ignored by `DNS-SD`)
* changed command line option to `zeroconf-interface` to be consistent with `zeroconf-port`
use builder pattern to DRY up the code
used macro to print warning message
* fixing register error
* renamed `bind_ip` variables to match the option to `zeroconf_ip`, to be more consistent
* Changed user help
Modified comments
Added block for condition to clean the code
Added new modification to the change log
Co-authored-by: setime <timeframe1@gmx.de>
Special thanks to @eladyn for all of their help and suggestions.
* Add all player events to `player_event_handler.rs`
* Move event handler code to `player_event_handler.rs`
* Add session events
* Clean up and de-noise events and event firing
* Added metadata support via a TrackChanged event
* Add `event_handler_example.py`
* Handle invalid track start positions by just starting the track from the beginning
* Add repeat support to `spirc.rs`
* Add `disconnect`, `set_position_ms` and `set_volume` to `spirc.rs`
* Set `PlayStatus` to the correct value when Player is loading to avoid blanking out the controls when `self.play_status` is `LoadingPlay` or `LoadingPause` in `spirc.rs`
* Handle attempts to play local files better by basically ignoring attempts to load them in `handle_remote_update` in `spirc.rs`
* Add an event worker thread that runs async to the main thread(s) but sync to itself to prevent potential data races for event consumers.
* Get rid of (probably harmless) `.unwrap()` in `main.rs`
* Ensure that events are emited in a logical order and at logical times
* Handle invalid and disappearing devices better
* Ignore SpircCommands unless we're active with the exception of ShutDown
- Fixed resolve function panicking when resolving endpoint type with no
AP in the list
- Fixed fallback APs not being applied when only some of the AP types
were missing
- Switch container type from `Vec` to `VecDeque` for the `AccessPoints`
- Remove the note about fallback AP being used even if the port is not
matching the configured `ap_port`
When librespot is built with Avahi turned on, it will crash if Avahi is
later not available at runtime.
This change avoids it crashing hard when Avahi is not available;
librespot will merely warn of the issue.
This affects some distribution packages too, where the maintainer might
prefer leaving Avahi support enabled, but many setups don't (or can't)
run Avahi.
Co-authored-by: Nick Steel <nick@nsteel.co.uk>
This sets the name displayed by PulseAudio to Librespot - Instance Name if a name is given otherwise Librespot (the default name).
This also sets the correct "role" as per the docs:
https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/Developer/Clients/ApplicationProperties/
PA_PROP_MEDIA_ROLE
"This is a property of the actual streamed data, not so much the application"
Roles are used for policies, things like automatically muting a music player when a call comes in and whatnot.
For bonus points this also sets PULSE_PROP_application.icon_name to audio-x-generic so that we get a nice icon in the PulseAudio settings by our name instead of a missing icon placeholder.
When there's a value that corresponds to an argument name used in the same command line, the logging of the arguments gets confused and logs the matching argument, but without the leading dash:
```
% target/debug/librespot -n c --verbose -c /path/to/my/cache
[2022-02-07T22:32:25Z INFO librespot] librespot 0.3.1 55ced49 (Built on 2022-02-07, Build ID: qaEB8kEW, Profile: debug)
[2022-02-07T22:32:25Z TRACE librespot] Command line argument(s):
[2022-02-07T22:32:25Z TRACE librespot] -n "c"
[2022-02-07T22:32:25Z TRACE librespot] c "/path/to/my/cache"
[2022-02-07T22:32:25Z TRACE librespot] --verbose
[2022-02-07T22:32:25Z TRACE librespot] -c "/path/to/my/cache"
```
Here we're using the literal `c` as the device name, and the `-c` argument. Thus the `c /path/to/my/cache` is logged in addition to `-c /path...`.
After checking whether the key has a leading dash, this issue is gone:
```
% target/debug/librespot -n c --verbose -c /path/to/my/cache
[2022-02-07T22:32:41Z INFO librespot] librespot 0.3.1 55ced49 (Built on 2022-02-07, Build ID: qaEB8kEW, Profile: debug)
[2022-02-07T22:32:41Z TRACE librespot] Command line argument(s):
[2022-02-07T22:32:41Z TRACE librespot] -n "c"
[2022-02-07T22:32:41Z TRACE librespot] --verbose
[2022-02-07T22:32:41Z TRACE librespot] -c "/path/to/my/cache"
```