1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 17:59:24 +02:00

fix: uses the index as fallback value

This commit is contained in:
Felix Prillwitz 2025-09-24 22:13:11 +02:00
parent eb7c65e77b
commit 3dee97321b
No known key found for this signature in database
GPG key ID: DE334B43606D1455

View file

@ -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<ContextPage>,
fallback_index: Option<usize>,
) -> 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!(