Follow autoplay client setting

This commit is contained in:
Roderick van Domburg 2022-01-01 20:23:21 +01:00
parent 0fdff0d3fd
commit 2d699e288a
No known key found for this signature in database
GPG key ID: FE2585E713F9F30A
3 changed files with 21 additions and 25 deletions

View file

@ -86,7 +86,6 @@ type BoxedStream<T> = Pin<Box<dyn FusedStream<Item = T> + Send>>;
struct SpircTask { struct SpircTask {
player: Player, player: Player,
mixer: Box<dyn Mixer>, mixer: Box<dyn Mixer>,
config: SpircTaskConfig,
sequence: SeqGenerator<u32>, sequence: SeqGenerator<u32>,
@ -123,10 +122,6 @@ pub enum SpircCommand {
Shuffle, Shuffle,
} }
struct SpircTaskConfig {
autoplay: bool,
}
const CONTEXT_TRACKS_HISTORY: usize = 10; const CONTEXT_TRACKS_HISTORY: usize = 10;
const CONTEXT_FETCH_THRESHOLD: u32 = 5; const CONTEXT_FETCH_THRESHOLD: u32 = 5;
@ -337,9 +332,6 @@ impl Spirc {
let (cmd_tx, cmd_rx) = mpsc::unbounded_channel(); let (cmd_tx, cmd_rx) = mpsc::unbounded_channel();
let initial_volume = config.initial_volume; let initial_volume = config.initial_volume;
let task_config = SpircTaskConfig {
autoplay: config.autoplay,
};
let device = initial_device_state(config); let device = initial_device_state(config);
@ -348,7 +340,6 @@ impl Spirc {
let mut task = SpircTask { let mut task = SpircTask {
player, player,
mixer, mixer,
config: task_config,
sequence: SeqGenerator::new(1), sequence: SeqGenerator::new(1),
@ -1098,8 +1089,19 @@ impl SpircTask {
self.context_fut = self.resolve_station(&context_uri); self.context_fut = self.resolve_station(&context_uri);
self.update_tracks_from_context(); self.update_tracks_from_context();
} }
if new_index >= tracks_len { 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 // Extend the playlist
debug!("Extending playlist <{}>", context_uri); debug!("Extending playlist <{}>", context_uri);
self.update_tracks_from_context(); self.update_tracks_from_context();
@ -1262,19 +1264,24 @@ impl SpircTask {
fn update_tracks(&mut self, frame: &protocol::spirc::Frame) { fn update_tracks(&mut self, frame: &protocol::spirc::Frame) {
trace!("State: {:#?}", frame.get_state()); trace!("State: {:#?}", frame.get_state());
let index = frame.get_state().get_playing_track_index(); let index = frame.get_state().get_playing_track_index();
let context_uri = frame.get_state().get_context_uri().to_owned(); let context_uri = frame.get_state().get_context_uri().to_owned();
let tracks = frame.get_state().get_track(); let tracks = frame.get_state().get_track();
trace!("Frame has {:?} tracks", tracks.len()); trace!("Frame has {:?} tracks", tracks.len());
if context_uri.starts_with("spotify:station:") if context_uri.starts_with("spotify:station:")
|| context_uri.starts_with("spotify:dailymix:") || context_uri.starts_with("spotify:dailymix:")
{ {
self.context_fut = self.resolve_station(&context_uri); self.context_fut = self.resolve_station(&context_uri);
} else if self.config.autoplay { } else if let Some(autoplay) = self.session.get_user_attribute("autoplay") {
if &autoplay == "1" {
info!("Fetching autoplay context uri"); info!("Fetching autoplay context uri");
// Get autoplay_station_uri for regular playlists // Get autoplay_station_uri for regular playlists
self.autoplay_fut = self.resolve_autoplay_uri(&context_uri); self.autoplay_fut = self.resolve_autoplay_uri(&context_uri);
} }
}
self.player self.player
.set_auto_normalise_as_album(context_uri.starts_with("spotify:album:")); .set_auto_normalise_as_album(context_uri.starts_with("spotify:album:"));

View file

@ -123,7 +123,6 @@ pub struct ConnectConfig {
pub device_type: DeviceType, pub device_type: DeviceType,
pub initial_volume: Option<u16>, pub initial_volume: Option<u16>,
pub has_volume_ctrl: bool, pub has_volume_ctrl: bool,
pub autoplay: bool,
} }
impl Default for ConnectConfig { impl Default for ConnectConfig {
@ -133,7 +132,6 @@ impl Default for ConnectConfig {
device_type: DeviceType::default(), device_type: DeviceType::default(),
initial_volume: Some(50), initial_volume: Some(50),
has_volume_ctrl: true, has_volume_ctrl: true,
autoplay: false,
} }
} }
} }

View file

@ -201,7 +201,6 @@ fn get_setup() -> Setup {
const VALID_NORMALISATION_RELEASE_RANGE: RangeInclusive<u64> = 1..=1000; const VALID_NORMALISATION_RELEASE_RANGE: RangeInclusive<u64> = 1..=1000;
const AP_PORT: &str = "ap-port"; const AP_PORT: &str = "ap-port";
const AUTOPLAY: &str = "autoplay";
const BACKEND: &str = "backend"; const BACKEND: &str = "backend";
const BITRATE: &str = "bitrate"; const BITRATE: &str = "bitrate";
const CACHE: &str = "cache"; const CACHE: &str = "cache";
@ -245,7 +244,6 @@ fn get_setup() -> Setup {
const ZEROCONF_PORT: &str = "zeroconf-port"; const ZEROCONF_PORT: &str = "zeroconf-port";
// Mostly arbitrary. // Mostly arbitrary.
const AUTOPLAY_SHORT: &str = "A";
const AP_PORT_SHORT: &str = "a"; const AP_PORT_SHORT: &str = "a";
const BACKEND_SHORT: &str = "B"; const BACKEND_SHORT: &str = "B";
const BITRATE_SHORT: &str = "b"; const BITRATE_SHORT: &str = "b";
@ -376,11 +374,6 @@ fn get_setup() -> Setup {
EMIT_SINK_EVENTS, EMIT_SINK_EVENTS,
"Run PROGRAM set by `--onevent` before the sink is opened and after it is closed.", "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( .optflag(
PASSTHROUGH_SHORT, PASSTHROUGH_SHORT,
PASSTHROUGH, PASSTHROUGH,
@ -1245,14 +1238,12 @@ fn get_setup() -> Setup {
.unwrap_or_default(); .unwrap_or_default();
let has_volume_ctrl = !matches!(mixer_config.volume_ctrl, VolumeCtrl::Fixed); let has_volume_ctrl = !matches!(mixer_config.volume_ctrl, VolumeCtrl::Fixed);
let autoplay = opt_present(AUTOPLAY);
ConnectConfig { ConnectConfig {
name, name,
device_type, device_type,
initial_volume, initial_volume,
has_volume_ctrl, has_volume_ctrl,
autoplay,
} }
}; };