mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Follow autoplay client setting
This commit is contained in:
parent
0fdff0d3fd
commit
2d699e288a
3 changed files with 21 additions and 25 deletions
|
@ -86,7 +86,6 @@ type BoxedStream<T> = Pin<Box<dyn FusedStream<Item = T> + Send>>;
|
|||
struct SpircTask {
|
||||
player: Player,
|
||||
mixer: Box<dyn Mixer>,
|
||||
config: SpircTaskConfig,
|
||||
|
||||
sequence: SeqGenerator<u32>,
|
||||
|
||||
|
@ -123,10 +122,6 @@ pub enum SpircCommand {
|
|||
Shuffle,
|
||||
}
|
||||
|
||||
struct SpircTaskConfig {
|
||||
autoplay: bool,
|
||||
}
|
||||
|
||||
const CONTEXT_TRACKS_HISTORY: usize = 10;
|
||||
const CONTEXT_FETCH_THRESHOLD: u32 = 5;
|
||||
|
||||
|
@ -337,9 +332,6 @@ impl Spirc {
|
|||
let (cmd_tx, cmd_rx) = mpsc::unbounded_channel();
|
||||
|
||||
let initial_volume = config.initial_volume;
|
||||
let task_config = SpircTaskConfig {
|
||||
autoplay: config.autoplay,
|
||||
};
|
||||
|
||||
let device = initial_device_state(config);
|
||||
|
||||
|
@ -348,7 +340,6 @@ impl Spirc {
|
|||
let mut task = SpircTask {
|
||||
player,
|
||||
mixer,
|
||||
config: task_config,
|
||||
|
||||
sequence: SeqGenerator::new(1),
|
||||
|
||||
|
@ -1098,8 +1089,19 @@ impl SpircTask {
|
|||
self.context_fut = self.resolve_station(&context_uri);
|
||||
self.update_tracks_from_context();
|
||||
}
|
||||
|
||||
if new_index >= tracks_len {
|
||||
if self.config.autoplay {
|
||||
let autoplay = self
|
||||
.session
|
||||
.get_user_attribute("autoplay")
|
||||
.unwrap_or_else(|| {
|
||||
warn!(
|
||||
"Unable to get autoplay user attribute. Continuing with autoplay disabled."
|
||||
);
|
||||
"0".into()
|
||||
});
|
||||
|
||||
if autoplay == "1" {
|
||||
// Extend the playlist
|
||||
debug!("Extending playlist <{}>", context_uri);
|
||||
self.update_tracks_from_context();
|
||||
|
@ -1262,18 +1264,23 @@ impl SpircTask {
|
|||
|
||||
fn update_tracks(&mut self, frame: &protocol::spirc::Frame) {
|
||||
trace!("State: {:#?}", frame.get_state());
|
||||
|
||||
let index = frame.get_state().get_playing_track_index();
|
||||
let context_uri = frame.get_state().get_context_uri().to_owned();
|
||||
let tracks = frame.get_state().get_track();
|
||||
|
||||
trace!("Frame has {:?} tracks", tracks.len());
|
||||
|
||||
if context_uri.starts_with("spotify:station:")
|
||||
|| context_uri.starts_with("spotify:dailymix:")
|
||||
{
|
||||
self.context_fut = self.resolve_station(&context_uri);
|
||||
} else if self.config.autoplay {
|
||||
info!("Fetching autoplay context uri");
|
||||
// Get autoplay_station_uri for regular playlists
|
||||
self.autoplay_fut = self.resolve_autoplay_uri(&context_uri);
|
||||
} else if let Some(autoplay) = self.session.get_user_attribute("autoplay") {
|
||||
if &autoplay == "1" {
|
||||
info!("Fetching autoplay context uri");
|
||||
// Get autoplay_station_uri for regular playlists
|
||||
self.autoplay_fut = self.resolve_autoplay_uri(&context_uri);
|
||||
}
|
||||
}
|
||||
|
||||
self.player
|
||||
|
|
|
@ -123,7 +123,6 @@ pub struct ConnectConfig {
|
|||
pub device_type: DeviceType,
|
||||
pub initial_volume: Option<u16>,
|
||||
pub has_volume_ctrl: bool,
|
||||
pub autoplay: bool,
|
||||
}
|
||||
|
||||
impl Default for ConnectConfig {
|
||||
|
@ -133,7 +132,6 @@ impl Default for ConnectConfig {
|
|||
device_type: DeviceType::default(),
|
||||
initial_volume: Some(50),
|
||||
has_volume_ctrl: true,
|
||||
autoplay: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,7 +201,6 @@ fn get_setup() -> Setup {
|
|||
const VALID_NORMALISATION_RELEASE_RANGE: RangeInclusive<u64> = 1..=1000;
|
||||
|
||||
const AP_PORT: &str = "ap-port";
|
||||
const AUTOPLAY: &str = "autoplay";
|
||||
const BACKEND: &str = "backend";
|
||||
const BITRATE: &str = "bitrate";
|
||||
const CACHE: &str = "cache";
|
||||
|
@ -245,7 +244,6 @@ fn get_setup() -> Setup {
|
|||
const ZEROCONF_PORT: &str = "zeroconf-port";
|
||||
|
||||
// Mostly arbitrary.
|
||||
const AUTOPLAY_SHORT: &str = "A";
|
||||
const AP_PORT_SHORT: &str = "a";
|
||||
const BACKEND_SHORT: &str = "B";
|
||||
const BITRATE_SHORT: &str = "b";
|
||||
|
@ -376,11 +374,6 @@ fn get_setup() -> Setup {
|
|||
EMIT_SINK_EVENTS,
|
||||
"Run PROGRAM set by `--onevent` before the sink is opened and after it is closed.",
|
||||
)
|
||||
.optflag(
|
||||
AUTOPLAY_SHORT,
|
||||
AUTOPLAY,
|
||||
"Automatically play similar songs when your music ends.",
|
||||
)
|
||||
.optflag(
|
||||
PASSTHROUGH_SHORT,
|
||||
PASSTHROUGH,
|
||||
|
@ -1245,14 +1238,12 @@ fn get_setup() -> Setup {
|
|||
.unwrap_or_default();
|
||||
|
||||
let has_volume_ctrl = !matches!(mixer_config.volume_ctrl, VolumeCtrl::Fixed);
|
||||
let autoplay = opt_present(AUTOPLAY);
|
||||
|
||||
ConnectConfig {
|
||||
name,
|
||||
device_type,
|
||||
initial_volume,
|
||||
has_volume_ctrl,
|
||||
autoplay,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue