From 3dee97321b0b4e263c03bbee331027e3b5e72b83 Mon Sep 17 00:00:00 2001 From: Felix Prillwitz Date: Wed, 24 Sep 2025 22:13:11 +0200 Subject: [PATCH] fix: uses the index as fallback value --- connect/src/spirc.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/connect/src/spirc.rs b/connect/src/spirc.rs index 43702d8a..58f0ea42 100644 --- a/connect/src/spirc.rs +++ b/connect/src/spirc.rs @@ -651,7 +651,7 @@ impl SpircTask { SpircCommand::RepeatTrack(repeat) => self.handle_repeat_track(repeat), SpircCommand::SetPosition(position) => self.handle_seek(position), SpircCommand::SetVolume(volume) => self.set_volume(volume), - SpircCommand::Load(command) => self.handle_load(command, None).await?, + SpircCommand::Load(command) => self.handle_load(command, None, None).await?, }; self.notify().await @@ -998,6 +998,13 @@ impl SpircTask { .map(Into::into) .map(LoadContextOptions::Options); + let fallback_index = play + .options + .skip_to + .as_ref() + .and_then(|s| s.track_index) + .map(|i| i as usize); + self.handle_load( LoadRequest { context, @@ -1009,6 +1016,7 @@ impl SpircTask { }, }, play.context.pages.pop(), + fallback_index, ) .await?; @@ -1217,6 +1225,7 @@ impl SpircTask { &mut self, cmd: LoadRequest, page: Option, + fallback_index: Option, ) -> Result<(), Error> { self.connect_state .reset_context(if let PlayContext::Uri(ref uri) = cmd.context { @@ -1253,17 +1262,26 @@ impl SpircTask { let index = match cmd_options.playing_track { None => None, Some(ref playing_track) => Some(match playing_track { - PlayingTrack::Index(i) => *i as usize, + PlayingTrack::Index(i) => Ok(*i as usize), PlayingTrack::Uri(uri) => { let ctx = self.connect_state.get_context(ContextType::Default)?; - ConnectState::find_index_in_context(ctx, |t| &t.uri == uri)? + ConnectState::find_index_in_context(ctx, |t| &t.uri == uri) } PlayingTrack::Uid(uid) => { let ctx = self.connect_state.get_context(ContextType::Default)?; - ConnectState::find_index_in_context(ctx, |t| &t.uid == uid)? + ConnectState::find_index_in_context(ctx, |t| &t.uid == uid) } }), - }; + } + .map(|i| { + i.unwrap_or_else(|why| { + warn!( + "Failed to resolve index by {:?}, using fallback index: {:?} (Error: {why})", + cmd_options.playing_track, fallback_index + ); + fallback_index.unwrap_or_default() + }) + }); if let Some(LoadContextOptions::Options(ref options)) = cmd_options.context_options { debug!(