Add credentials cache and bump libraries

This commit is contained in:
oSumAtrIX 2022-05-31 01:16:45 +02:00
parent cad94d74e9
commit 4098752737
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
4 changed files with 593 additions and 381 deletions

949
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,7 @@ panic = "abort"
[package]
name = "down_on_spot"
version = "0.2.0"
version = "0.2.1"
edition = "2018"
authors = ["exttex", "oSumAtrIX"]
build = "build.rs"
@ -19,7 +19,7 @@ winres = "0.1"
clap = "3.0"
log = "0.4"
url = "2.2"
protobuf = "2.25"
protobuf = "3.0"
id3 = "1.0"
dirs = "4.0"
chrono = "0.4"
@ -34,7 +34,7 @@ async-std = { version = "1.10", features = ["attributes", "tokio1"] }
serde_json = "1.0"
async-stream = "0.3"
oggvorbismeta = "0.1"
sanitize-filename = "0.3"
sanitize-filename = "0.4"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.12", features = ["fs"] }
@ -42,4 +42,4 @@ tokio = { version = "1.12", features = ["fs"] }
OriginalFilename = "DownOnSpot.exe"
FileDescription = "Download songs from Spotify with Rust"
ProductName = "DownOnSpot"
ProductVersion = "0.2.0"
ProductVersion = "0.2.1"

View file

@ -504,7 +504,7 @@ impl DownloaderInternal {
'outer: loop {
for format in quality.get_file_formats() {
if let Some(f) = track.files.get(&format) {
info!("{} Using {:?} format.", id.to_base62(), format);
info!("{} Using {:?} format.", id.to_base62().unwrap(), format);
file_id = Some(f);
file_format = Some(format);
break 'outer;
@ -515,7 +515,7 @@ impl DownloaderInternal {
Some(q) => quality = q,
None => break,
}
warn!("{} Falling back to: {:?}", id.to_base62(), quality);
warn!("{} Falling back to: {:?}", id.to_base62().unwrap(), quality);
}
let file_id = file_id.ok_or(SpotifyError::Unavailable)?;
let file_format = file_format.unwrap();
@ -573,7 +573,7 @@ impl DownloaderInternal {
}
}
info!("Done downloading: {}", track.id.to_base62());
info!("Done downloading: {}", track.id.to_base62().unwrap());
Ok((path, audio_format))
}

View file

@ -3,9 +3,11 @@ use aspotify::{
TrackSimplified,
};
use librespot::core::authentication::Credentials;
use librespot::core::cache::Cache;
use librespot::core::config::SessionConfig;
use librespot::core::session::Session;
use std::fmt;
use std::path::Path;
use url::Url;
use crate::error::SpotifyError;
@ -26,7 +28,14 @@ impl Spotify {
) -> Result<Spotify, SpotifyError> {
// librespot
let credentials = Credentials::with_password(username, password);
let session = Session::connect(SessionConfig::default(), credentials, None).await?;
let (session, _) = Session::connect(
SessionConfig::default(),
credentials,
Some(Cache::new(Some(Path::new("credentials_cache")), None, None, None).unwrap()),
true,
)
.await?;
//aspotify
let credentials = ClientCredentials {
id: client_id.to_string(),