fix: Use cached credentials if available (#100)

This commit is contained in:
Mark Eijsermans 2024-08-25 02:54:49 -07:00 committed by GitHub
parent 390179c6c9
commit 0262251df9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,11 +29,15 @@ impl Spotify {
market_country_code: Option<CountryCode>, market_country_code: Option<CountryCode>,
) -> Result<Spotify, SpotifyError> { ) -> Result<Spotify, SpotifyError> {
// librespot // librespot
let credentials = Credentials::with_password(username, password); let cache = Cache::new(Some(Path::new("credentials_cache")), None, None, None).unwrap();
let credentials = match cache.credentials() {
Some(creds) => creds,
None => Credentials::with_password(username, password),
};
let (session, _) = Session::connect( let (session, _) = Session::connect(
SessionConfig::default(), SessionConfig::default(),
credentials, credentials,
Some(Cache::new(Some(Path::new("credentials_cache")), None, None, None).unwrap()), Some(cache),
true, true,
) )
.await?; .await?;