Update to librespot 0.4.0

Changes: https://github.com/librespot-org/librespot/compare/v0.3.1..v0.4.0
This commit is contained in:
Henrik Friedrichsen
2022-05-22 17:15:02 +02:00
parent 8fad4009d2
commit c41294cb8d
7 changed files with 348 additions and 95 deletions

View File

@@ -146,14 +146,9 @@ async fn main() -> Result<(), String> {
let cfg: Arc<crate::config::Config> = Arc::new(Config::new(
matches.value_of("config").unwrap_or("config.toml"),
));
let cache = Cache::new(
Some(config::cache_path("librespot")),
Some(config::cache_path("librespot").join("files")),
None,
)
.expect("Could not create librespot cache");
let mut credentials = {
let cache = Cache::new(Some(config::cache_path("librespot")), None, None, None)
.expect("Could not create librespot cache");
let cached_credentials = cache.credentials();
match cached_credentials {
Some(c) => {

View File

@@ -65,7 +65,7 @@ impl Queue {
PlaybackState::Stopped => {
spotify.stop();
}
PlaybackState::Paused | PlaybackState::Default | _ => {
PlaybackState::Paused | PlaybackState::Playing | PlaybackState::Default => {
spotify.pause();
}
}

View File

@@ -126,29 +126,33 @@ impl Spotify {
pub fn test_credentials(credentials: Credentials) -> Result<Session, SessionError> {
let config = Self::session_config();
let handle = tokio::runtime::Handle::current();
let jh = handle.spawn(async { Session::connect(config, credentials, None).await });
futures::executor::block_on(jh).unwrap()
let jh = handle.spawn(async { Session::connect(config, credentials, None, true).await });
futures::executor::block_on(jh).unwrap().map(|r| r.0)
}
async fn create_session(
cfg: &config::Config,
credentials: Credentials,
) -> Result<Session, SessionError> {
let session_config = Self::session_config();
let librespot_cache_path = config::cache_path("librespot");
let audio_cache_path = match cfg.values().audio_cache.unwrap_or(true) {
true => Some(config::cache_path("librespot").join("files")),
true => Some(librespot_cache_path.join("files")),
false => None,
};
let cache = Cache::new(
Some(config::cache_path("librespot")),
Some(librespot_cache_path.clone()),
audio_cache_path,
Some(librespot_cache_path.join("volume")),
cfg.values()
.audio_cache_size
.map(|size| (size * 1048576) as u64),
)
.expect("Could not create cache");
debug!("opening spotify session");
Session::connect(session_config, credentials, Some(cache)).await
let session_config = Self::session_config();
Session::connect(session_config, credentials, Some(cache), true)
.await
.map(|r| r.0)
}
async fn worker(
@@ -170,7 +174,7 @@ impl Spotify {
gapless: cfg.values().gapless.unwrap_or(true),
bitrate: bitrate.unwrap_or(Bitrate::Bitrate320),
normalisation: cfg.values().volnorm.unwrap_or(false),
normalisation_pregain: cfg.values().volnorm_pregain.unwrap_or(0.0),
normalisation_pregain_db: cfg.values().volnorm_pregain.unwrap_or(0.0),
..Default::default()
};
@@ -189,7 +193,7 @@ impl Spotify {
let (player, player_events) = Player::new(
player_config,
session.clone(),
mixer.get_audio_filter(),
mixer.get_soft_volume(),
move || (backend)(cfg.values().backend_device.clone(), audio_format),
);

View File

@@ -27,7 +27,7 @@ impl LibraryView {
.values()
.library_tabs
.clone()
.unwrap_or(Vec::from_iter(LibraryTab::iter()));
.unwrap_or_else(|| Vec::from_iter(LibraryTab::iter()));
for tab in selected_tabs {
match tab {