From 9e970f57990732893ac23d69e233903fe684e746 Mon Sep 17 00:00:00 2001 From: eulerfan271 <13190658+eulerfan271@users.noreply.github.com> Date: Tue, 22 Sep 2020 10:01:56 -0500 Subject: [PATCH] Added config option for bitrate (#270) * added config option for bitrate * updated README.md to include bitrate config options --- README.md | 1 + src/config.rs | 1 + src/spotify.rs | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ce7c99f..5662362 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,7 @@ Possible configuration values are: * `default_keybindings`: If disabled, the default keybindings are discarded, off by default * `notify`: Enable or disable desktop notifications, off by default +* `bitrate`: The audio bitrate to use for streaming, can be 96, 160, or 320 (default is 320) Keybindings can be configured in `[keybindings]` section in `config.toml`, e.g. as such: diff --git a/src/config.rs b/src/config.rs index 1e4a271..fa2fe8a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,6 +20,7 @@ pub struct Config { pub volnorm: Option, pub volnorm_pregain: Option, pub notify: Option, + pub bitrate: Option, } #[derive(Serialize, Deserialize, Debug, Default, Clone)] diff --git a/src/spotify.rs b/src/spotify.rs index 093ad9e..cc17066 100644 --- a/src/spotify.rs +++ b/src/spotify.rs @@ -51,6 +51,7 @@ use std::sync::RwLock; use std::thread; use std::time::{Duration, SystemTime}; use std::{env, io}; +use std::str::FromStr; use crate::artist::Artist; use crate::config; @@ -398,9 +399,15 @@ impl Spotify { user_tx: Option>, volume: u16, ) { + let bitrate_str = cfg.bitrate.unwrap_or(320).to_string(); + let bitrate = Bitrate::from_str(&bitrate_str); + if bitrate.is_err(){ + error!("invalid bitrate, will use 320 instead") + } + let player_config = PlayerConfig { gapless: false, - bitrate: Bitrate::Bitrate320, + bitrate: bitrate.unwrap_or(Bitrate::Bitrate320), normalisation: cfg.volnorm.unwrap_or(false), normalisation_pregain: cfg.volnorm_pregain.unwrap_or(0.0), };