implement audio_cache setting

fixes #196
This commit is contained in:
Henrik Friedrichsen
2020-05-14 22:11:35 +02:00
parent 85bc898830
commit d04766160d
3 changed files with 18 additions and 17 deletions

View File

@@ -122,6 +122,8 @@ values are:
* `use_nerdfont`: Turn nerdfont glyphs on/off <true/false> * `use_nerdfont`: Turn nerdfont glyphs on/off <true/false>
* `theme`: Set a custom color palette (see below) * `theme`: Set a custom color palette (see below)
* `audio_cache`: Enable or disable caching of audio files, on by default
<true/false>
* `volnorm`: Enable or disable volume normalization, off by default <true/false> * `volnorm`: Enable or disable volume normalization, off by default <true/false>
* `volnorm_pregain`: Normalization pregain to apply (if enabled) * `volnorm_pregain`: Normalization pregain to apply (if enabled)

View File

@@ -13,6 +13,7 @@ pub struct Config {
pub theme: Option<ConfigTheme>, pub theme: Option<ConfigTheme>,
pub use_nerdfont: Option<bool>, pub use_nerdfont: Option<bool>,
pub saved_state: Option<SavedState>, pub saved_state: Option<SavedState>,
pub audio_cache: Option<bool>,
pub volnorm: Option<bool>, pub volnorm: Option<bool>,
pub volnorm_pregain: Option<f32>, pub volnorm_pregain: Option<f32>,
} }

View File

@@ -223,11 +223,6 @@ impl futures::Future for Worker {
impl Spotify { impl Spotify {
pub fn new(events: EventManager, credentials: Credentials, cfg: &config::Config) -> Spotify { pub fn new(events: EventManager, credentials: Credentials, cfg: &config::Config) -> Spotify {
let player_config = PlayerConfig {
bitrate: Bitrate::Bitrate320,
normalisation: cfg.volnorm.unwrap_or(false),
normalisation_pregain: cfg.volnorm_pregain.unwrap_or(0.0),
};
let (user_tx, user_rx) = oneshot::channel(); let (user_tx, user_rx) = oneshot::channel();
let volume = match &cfg.saved_state { let volume = match &cfg.saved_state {
Some(state) => match state.volume { Some(state) => match state.volume {
@@ -257,15 +252,9 @@ impl Spotify {
let (tx, rx) = mpsc::unbounded(); let (tx, rx) = mpsc::unbounded();
{ {
let cfg = cfg.clone();
thread::spawn(move || { thread::spawn(move || {
Self::worker( Self::worker(events, Box::pin(rx), cfg, credentials, user_tx, volume)
events,
Box::pin(rx),
player_config,
credentials,
user_tx,
volume,
)
}); });
} }
@@ -314,9 +303,12 @@ impl Spotify {
th.join().is_ok() th.join().is_ok()
} }
fn create_session(core: &mut Core, credentials: Credentials) -> Session { fn create_session(core: &mut Core, cfg: &config::Config, credentials: Credentials) -> Session {
let session_config = Self::session_config(); let session_config = Self::session_config();
let cache = Cache::new(config::cache_path("librespot"), true); let cache = Cache::new(
config::cache_path("librespot"),
cfg.audio_cache.unwrap_or(true),
);
let handle = core.handle(); let handle = core.handle();
debug!("opening spotify session"); debug!("opening spotify session");
core.run(Session::connect( core.run(Session::connect(
@@ -358,14 +350,20 @@ impl Spotify {
fn worker( fn worker(
events: EventManager, events: EventManager,
commands: Pin<Box<mpsc::UnboundedReceiver<WorkerCommand>>>, commands: Pin<Box<mpsc::UnboundedReceiver<WorkerCommand>>>,
player_config: PlayerConfig, cfg: config::Config,
credentials: Credentials, credentials: Credentials,
user_tx: oneshot::Sender<String>, user_tx: oneshot::Sender<String>,
volume: u16, volume: u16,
) { ) {
let player_config = PlayerConfig {
bitrate: Bitrate::Bitrate320,
normalisation: cfg.volnorm.unwrap_or(false),
normalisation_pregain: cfg.volnorm_pregain.unwrap_or(0.0),
};
let mut core = Core::new().unwrap(); let mut core = Core::new().unwrap();
let session = Self::create_session(&mut core, credentials); let session = Self::create_session(&mut core, &cfg, credentials);
user_tx user_tx
.send(session.username()) .send(session.username())
.expect("could not pass username back to Spotify::new"); .expect("could not pass username back to Spotify::new");