mirror of
https://github.com/LibreELEC/LibreELEC.tv
synced 2025-09-24 19:46:01 +07:00
88 lines
3.2 KiB
Diff
88 lines
3.2 KiB
Diff
From 031cc0a420db9d3ae8dd3543d07ff8503bdc508d Mon Sep 17 00:00:00 2001
|
|
From: Michael Herger <michael@herger.net>
|
|
Date: Tue, 20 Jun 2017 12:31:55 +0200
|
|
Subject: [PATCH] Add --disable-audio-cache startup parameter
|
|
|
|
Disable caching of downloaded audio files at runtime. Comes in handy when running librespot on a small device with SD card or other small storage.
|
|
---
|
|
src/audio_file.rs | 24 +++++++++++++-----------
|
|
src/main.rs | 2 ++
|
|
src/session.rs | 2 ++
|
|
3 files changed, 17 insertions(+), 11 deletions(-)
|
|
|
|
diff --git a/src/audio_file.rs b/src/audio_file.rs
|
|
index 369d5ca..d014ba2 100644
|
|
--- a/src/audio_file.rs
|
|
+++ b/src/audio_file.rs
|
|
@@ -151,17 +151,19 @@ impl AudioFileManager {
|
|
complete_tx: Some(complete_tx),
|
|
};
|
|
|
|
- let session = self.session();
|
|
- self.session().spawn(move |_| {
|
|
- complete_rx.map(move |mut file| {
|
|
- if let Some(cache) = session.cache() {
|
|
- cache.save_file(file_id, &mut file);
|
|
- debug!("File {} complete, saving to cache", file_id);
|
|
- } else {
|
|
- debug!("File {} complete", file_id);
|
|
- }
|
|
- }).or_else(|oneshot::Canceled| Ok(()))
|
|
- });
|
|
+ if self.session().config().use_audio_cache {
|
|
+ let session = self.session();
|
|
+ self.session().spawn(move |_| {
|
|
+ complete_rx.map(move |mut file| {
|
|
+ if let Some(cache) = session.cache() {
|
|
+ cache.save_file(file_id, &mut file);
|
|
+ debug!("File {} complete, saving to cache", file_id);
|
|
+ } else {
|
|
+ debug!("File {} complete", file_id);
|
|
+ }
|
|
+ }).or_else(|oneshot::Canceled| Ok(()))
|
|
+ });
|
|
+ }
|
|
|
|
AudioFileOpen::Streaming(open)
|
|
}
|
|
diff --git a/src/main.rs b/src/main.rs
|
|
index 38c57fd..8a31a44 100644
|
|
--- a/src/main.rs
|
|
+++ b/src/main.rs
|
|
@@ -86,6 +86,7 @@ struct Setup {
|
|
fn setup(args: &[String]) -> Setup {
|
|
let mut opts = getopts::Options::new();
|
|
opts.optopt("c", "cache", "Path to a directory where files will be cached.", "CACHE")
|
|
+ .optflag("", "disable-audio-cache", "Disable caching of the audio data.")
|
|
.reqopt("n", "name", "Device name", "NAME")
|
|
.optopt("b", "bitrate", "Bitrate (96, 160 or 320). Defaults to 160", "BITRATE")
|
|
.optopt("", "onstart", "Run PROGRAM when playback is about to begin.", "PROGRAM")
|
|
@@ -152,6 +153,7 @@ fn setup(args: &[String]) -> Setup {
|
|
bitrate: bitrate,
|
|
onstart: matches.opt_str("onstart"),
|
|
onstop: matches.opt_str("onstop"),
|
|
+ use_audio_cache: !matches.opt_present("disable-audio-cache"),
|
|
};
|
|
|
|
let device = matches.opt_str("device");
|
|
diff --git a/src/session.rs b/src/session.rs
|
|
index 86162bd..a5d397e 100644
|
|
--- a/src/session.rs
|
|
+++ b/src/session.rs
|
|
@@ -49,6 +49,7 @@ pub struct Config {
|
|
pub bitrate: Bitrate,
|
|
pub onstart: Option<String>,
|
|
pub onstop: Option<String>,
|
|
+ pub use_audio_cache: bool,
|
|
}
|
|
|
|
impl Default for Config {
|
|
@@ -60,6 +61,7 @@ impl Default for Config {
|
|
bitrate: Bitrate::Bitrate160,
|
|
onstart: None,
|
|
onstop: None,
|
|
+ use_audio_cache: true,
|
|
}
|
|
}
|
|
}
|