diff options
author | John King <beaverking1212@proton.me> | 2023-04-15 23:24:44 +0300 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@onestream.live> | 2023-04-21 10:12:47 +0300 |
commit | 2bd2e501d97668227443a5f857093344608efa82 (patch) | |
tree | c38db6761978d48bf841ba88a2fe86f2ad31c194 /audio/spotify/src | |
parent | cc3646640e8258cb078951af830ff3e994dcc9b5 (diff) |
spotify: fix credentials cache
Cache Spotify response instead of username and password.
This should resolve frequent "New login to Spotify" emails.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1183>
Diffstat (limited to 'audio/spotify/src')
-rw-r--r-- | audio/spotify/src/common.rs | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/audio/spotify/src/common.rs b/audio/spotify/src/common.rs index ae2bd176..f373af65 100644 --- a/audio/spotify/src/common.rs +++ b/audio/spotify/src/common.rs @@ -131,29 +131,37 @@ impl Settings { let cache = Cache::new(credentials_cache, None, files_cache, max_size)?; - let credentials = match cache.credentials() { - Some(cached_cred) => { - gst::debug!(cat, obj: &src, "reuse credentials from cache",); - cached_cred + if let Some(cached_cred) = cache.credentials() { + gst::debug!(cat, obj: &src, "reuse credentials from cache",); + if let Ok((session, _credentials)) = Session::connect( + SessionConfig::default(), + cached_cred, + Some(cache.clone()), + true, + ) + .await + { + return Ok(session); } - None => { - gst::debug!(cat, obj: &src, "credentials not in cache",); - - if self.username.is_empty() { - bail!("username is not set and credentials are not in cache"); - } - if self.password.is_empty() { - bail!("password is not set and credentials are not in cache"); - } - - let cred = Credentials::with_password(&self.username, &self.password); - cache.save_credentials(&cred); - cred - } - }; + } + + gst::debug!( + cat, + obj: &src, + "credentials not in cache or cached credentials invalid", + ); + + if self.username.is_empty() { + bail!("username is not set and credentials are not in cache"); + } + if self.password.is_empty() { + bail!("password is not set and credentials are not in cache"); + } + + let cred = Credentials::with_password(&self.username, &self.password); let (session, _credentials) = - Session::connect(SessionConfig::default(), credentials, Some(cache), false).await?; + Session::connect(SessionConfig::default(), cred, Some(cache), true).await?; Ok(session) } |