Upgrading to v0.11: questions and support #342
Replies: 33 comments
-
Do note that this version hasn't been released yet, but those using the |
Beta Was this translation helpful? Give feedback.
-
Is there an ETA when 0.11 will get released? What issues are blocking the release and can I help to address those? |
Beta Was this translation helpful? Give feedback.
-
Hi @flip1995! The problem is that I've recently started Uni classes again and I haven't had time to push the release, but it's really really close. What's pending is:
If you can help on any of these go ahead (just let us know to avoid repeated work), and if you have any questions do ask them. The most fun one is probably fixing |
Beta Was this translation helpful? Give feedback.
-
Thanks for the summary! Sadly I'm also a bit low on time, so I can't make any promises. I may have some time to look into the async issue in about 2 weeks. |
Beta Was this translation helpful? Give feedback.
-
Since all PRs have been merged, I think, we are ready to release a new version crate or a pre-version crate now :) PS: ooh, it reminds me that there is something left to be updated, some docs are not up-to-date, for example, the diagram of trait hierarchy. I should update them. |
Beta Was this translation helpful? Give feedback.
-
I think once we merge your PR we're ready, as long as everyone is OK leaving #221 for a future version. |
Beta Was this translation helpful? Give feedback.
-
Shall we? Do you want to do the honors, Ramsay? |
Beta Was this translation helpful? Give feedback.
-
Three attempts later, we've finally released v0.11.2! The changes from v0.11.0 to v0.11.2 are just fixes for the builds in Cheers! |
Beta Was this translation helpful? Give feedback.
-
Also, here's my (super long) blog post about the new version: https://nullderef.com/blog/web-api-client/. It tells the whole story and showcases some of the cool features we've added. Thanks again to everyone who made this release possible ❤️ |
Beta Was this translation helpful? Give feedback.
-
@marioortizmanero wow finally! Nice work, everyone who is involved 🎉 I have been waiting for Bookmarked the blog post! I haven't noticed you're the guy behind nullderef until now. Really enjoyed your previous blogs about Rust. |
Beta Was this translation helpful? Give feedback.
-
Hey there. Congratulations to your release and thanks for all the effort. I'm currently migrating ncspot to 0.11.x. and I'm struggling a little with the new use rspotify::model::{Id, ItemPositions, PlayableId, TrackId};
fn main() {
let track_ids = ["foo", "bar"];
let positions = [1u32, 2u32];
// will not compile
let ids = track_ids.iter().zip(positions.iter()).map(|(id, pos)| ItemPositions {
id: &TrackId::from_id(id).unwrap(),
positions: &[pos.clone()]
});
// compiles fine
let test = ItemPositions {
id: &TrackId::from_id("test").unwrap(),
positions: &[1]
};
} The borrow checker returns the following error:
I'm a little bit at loss here. It works fine if I pass static literals, but I can't manage to fulfill the memory lifetime requirements for dynamic IDs/positions. Any ideas? |
Beta Was this translation helpful? Give feedback.
-
use rspotify::model::{Id, ItemPositions, PlayableId, TrackId};
fn main() {
let track_ids = ["foo", "bar"];
let positions = [1u32, 2u32];
let track_ids = track_ids.iter().map(|id| TrackId::from_id(id).unwrap()).collect::<Vec<_>>();
let positions = positions.iter().map(|pos| [*pos]).collect::<Vec<_>>();
let ids = track_ids.iter().zip(positions.iter()).map(|(id, pos)| ItemPositions {
id,
positions: pos
});
} Not sure if it's the best way to do it, but try with something like that. |
Beta Was this translation helpful? Give feedback.
-
I just realized my example wasn't very good and the problem was actually in the creation of |
Beta Was this translation helpful? Give feedback.
-
Hey again, one more question. Previously I used to specify the limit and offset values to implement a "Show more results" button in ncspot (see screenshow below). I would like to use the iterable results, but I can't think of a way to stop iteration if the end of a page is reached. Do you have any ideas on how I could tackle this or plans to expose this information? |
Beta Was this translation helpful? Give feedback.
-
Assuming you know the length of the page, you can use |
Beta Was this translation helpful? Give feedback.
-
I think I may have found a bug .. Querying for devices, sometimes I get the following error:
The device in question is a Roku 3 running the Spotify app. What's weird is that sometimes it does work .. so I'm not sure if, when it works, it returns The error is being generated by: convert_result. Here's the full payload returned from the Spotify API:
|
Beta Was this translation helpful? Give feedback.
-
Unfortunately the device type is not very well documented: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-a-users-available-devices. It doesn't even mention "TV" or "Tv". I would say this is a problem on Spotify's side, but we can surely fix it easily.
Nvm, it's easier to just use |
Beta Was this translation helpful? Give feedback.
-
Great news, thanks again @marioortizmanero ! 😄 👍 |
Beta Was this translation helpful? Give feedback.
-
For completeness - the fix in |
Beta Was this translation helpful? Give feedback.
-
Awesome, thanks for the bug report! |
Beta Was this translation helpful? Give feedback.
-
Hi @marioortizmanero , it looks like a similar issue exists for the device type
|
Beta Was this translation helpful? Give feedback.
-
I have created a PR to fix this problem, you could retry after this PR merged :) |
Beta Was this translation helpful? Give feedback.
-
That worked! Thanks so much! Sorry for the delay in getting back to you, it was a busy weekend. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
That is indeed an error in rspotify, thanks for reporting. I assume it's the Edit: can confirm that tekore also has this variant: https://github.com/felix-hilden/tekore/blob/d1200964f50d88e99e42ada1748769de64228dc7/tekore/_model/context.py#L5 |
Beta Was this translation helpful? Give feedback.
-
it is quite long but sure. |
Beta Was this translation helpful? Give feedback.
-
You did well, the only sensitive thing may be what you censored. I can confirm that it's a problem in |
Beta Was this translation helpful? Give feedback.
-
Hi! I'm currently trying to port this code to the new This method receives a spotify URI from user interaction and should start playback for the given URI. In the current version, it just uses This is no longer that easy. Not only has Spotify added shows, from which one can play episodes ( Due to the new way, I'm currently doing something similar to the following and I'm wondering, if and how this could be achieved in a better way:
let mv_device_name = device_name.clone();
let sp_client = Arc::clone(&spotify_api_client);
b.method("OpenUri", ("uri",), (), move |_, _, (uri,): (String,)| {
struct AnyContextId(Box<dyn PlayContextId>);
impl Id for AnyContextId {
fn id(&self) -> &str {
self.0.id()
}
fn _type(&self) -> Type {
self.0._type()
}
fn _type_static() -> Type
where
Self: Sized,
{
unreachable!("never called");
}
unsafe fn from_id_unchecked(_id: &str) -> Self
where
Self: Sized,
{
unreachable!("never called");
}
}
impl PlayContextId for AnyContextId {}
enum Uri {
Playable(Box<dyn PlayableId>),
Context(AnyContextId),
}
impl Uri {
fn from_id(id_type: Type, id: &str) -> Result<Uri, IdError> {
use Uri::*;
let uri = match id_type {
Type::Track => Playable(Box::new(TrackId::from_id(id)?)),
Type::Episode => Playable(Box::new(EpisodeId::from_id(id)?)),
Type::Artist => Context(AnyContextId(Box::new(ArtistId::from_id(id)?))),
Type::Album => Context(AnyContextId(Box::new(AlbumId::from_id(id)?))),
Type::Playlist => Context(AnyContextId(Box::new(PlaylistId::from_id(id)?))),
Type::Show => Context(AnyContextId(Box::new(ShowId::from_id(id)?))),
Type::User | Type::Collection => Err(IdError::InvalidType)?,
};
Ok(uri)
}
}
// parsing the uri
let mut chars = uri
.strip_prefix("spotify")
.ok_or(MethodErr::invalid_arg(&uri))?
.chars();
let sep = match chars.next() {
Some(ch) if ch == '/' || ch == ':' => ch,
_ => return Err(MethodErr::invalid_arg(&uri)),
};
let rest = chars.as_str();
let (id_type, id) = rest
.rsplit_once(sep)
.and_then(|(id_type, id)| Some((id_type.parse::<Type>().ok()?, id)))
.ok_or(MethodErr::invalid_arg(&uri))?;
let uri = Uri::from_id(id_type, id).map_err(|_| MethodErr::invalid_arg(&uri))?;
// spotifyd specific things
let device_name = utf8_percent_encode(&mv_device_name, NON_ALPHANUMERIC).to_string();
let device_id = sp_client.device().ok().and_then(|devices| {
devices.into_iter().find_map(|d| {
if d.is_active && d.name == device_name {
d.id
} else {
None
}
})
});
// call the appropriate method
match uri {
Uri::Playable(id) => {
let _ = sp_client.start_uris_playback(
Some(id.as_ref()),
device_id.as_deref(),
Some(Offset::for_position(0)),
None,
);
}
Uri::Context(id) => {
let _ = sp_client.start_context_playback(
&id,
device_id.as_deref(),
Some(Offset::for_position(0)),
None,
);
}
}
Ok(())
}); Sorry, if this issue is not the right place to ask this question, feel free to move it elsewhere, if not. Some of the issues I encountered might not be "Upgrading to v0.11" specific since the last crate version that Some of my problems should be fixed with #305, although things like parsing an Id that I know nothing about I would still have to implement myself. If you'd like me to, I can add my thoughts on that over there. Anyway, thanks for this great library and sorry for this massive wall of text! 😅 |
Beta Was this translation helpful? Give feedback.
-
Hi @eladyn, just wanted to let you know that I wasn't able to answer yet because I haven't had any free time (and it will continue that way until around the end of May, unfortunately). I can agree with you that the design of
Note that you may not need to box your Id if you don't plan on keeping it after the function. You can use a I agree that the resulting code is indeed overly complex, but only because you have to implement your own I'm glad you at least got it working, though. If it's fine by you, once either I or Ramsay have more time, we can look into the issue and fix it properly in a future version. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the answer! I don't have much time myself currently, so no hurries. I might have a look at the code I wrote again some time in the future and hopefully find a way to improve it a bit (maybe apply your suggestion about the |
Beta Was this translation helpful? Give feedback.
-
Rspotify's v0.11 update introduces a lot of breaking changes. Thus, I think an issue like this might help with upgrading.
First, check out the upgrading guide in the changelog:
CHANGELOG.md
. If you have any questions or need any help please let us know!Beta Was this translation helpful? Give feedback.
All reactions