mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-03 09:49:31 +02:00
refactor: use Rust 2021 format strings for error and debug messages
This commit is contained in:
parent
fdd4a16fdc
commit
0aec38b07a
4 changed files with 32 additions and 39 deletions
|
@ -36,7 +36,7 @@ async fn main() {
|
||||||
println!("Connecting...");
|
println!("Connecting...");
|
||||||
let session = Session::new(session_config, None);
|
let session = Session::new(session_config, None);
|
||||||
if let Err(e) = session.connect(credentials, false).await {
|
if let Err(e) = session.connect(credentials, false).await {
|
||||||
println!("Error connecting: {}", e);
|
println!("Error connecting: {e}");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,12 @@ async fn main() {
|
||||||
|
|
||||||
let session = Session::new(session_config, None);
|
let session = Session::new(session_config, None);
|
||||||
if let Err(e) = session.connect(credentials, false).await {
|
if let Err(e) = session.connect(credentials, false).await {
|
||||||
println!("Error connecting: {}", e);
|
println!("Error connecting: {e}");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let plist = Playlist::get(&session, &plist_uri).await.unwrap();
|
let plist = Playlist::get(&session, &plist_uri).await.unwrap();
|
||||||
println!("{:?}", plist);
|
println!("{plist:?}");
|
||||||
for track_id in plist.tracks() {
|
for track_id in plist.tracks() {
|
||||||
let plist_track = Track::get(&session, track_id).await.unwrap();
|
let plist_track = Track::get(&session, track_id).await.unwrap();
|
||||||
println!("track: {} ", plist_track.name);
|
println!("track: {} ", plist_track.name);
|
||||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -1114,7 +1114,7 @@ fn get_setup() -> Setup {
|
||||||
let tmp_dir = opt_str(TEMP_DIR).map_or(SessionConfig::default().tmp_dir, |p| {
|
let tmp_dir = opt_str(TEMP_DIR).map_or(SessionConfig::default().tmp_dir, |p| {
|
||||||
let tmp_dir = PathBuf::from(p);
|
let tmp_dir = PathBuf::from(p);
|
||||||
if let Err(e) = create_dir_all(&tmp_dir) {
|
if let Err(e) = create_dir_all(&tmp_dir) {
|
||||||
error!("could not create or access specified tmp directory: {}", e);
|
error!("could not create or access specified tmp directory: {e}");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
tmp_dir
|
tmp_dir
|
||||||
|
@ -1164,15 +1164,14 @@ fn get_setup() -> Setup {
|
||||||
|
|
||||||
if audio_dir.is_none() && opt_present(CACHE_SIZE_LIMIT) {
|
if audio_dir.is_none() && opt_present(CACHE_SIZE_LIMIT) {
|
||||||
warn!(
|
warn!(
|
||||||
"Without a `--{}` / `-{}` path, and/or if the `--{}` / `-{}` flag is set, `--{}` / `-{}` has no effect.",
|
"Without a `--{CACHE}` / `-{CACHE_SHORT}` path, and/or if the `--{DISABLE_AUDIO_CACHE}` / `-{DISABLE_AUDIO_CACHE_SHORT}` flag is set, `--{CACHE_SIZE_LIMIT}` / `-{CACHE_SIZE_LIMIT_SHORT}` has no effect."
|
||||||
CACHE, CACHE_SHORT, DISABLE_AUDIO_CACHE, DISABLE_AUDIO_CACHE_SHORT, CACHE_SIZE_LIMIT, CACHE_SIZE_LIMIT_SHORT
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let cache = match Cache::new(cred_dir.clone(), volume_dir, audio_dir, limit) {
|
let cache = match Cache::new(cred_dir.clone(), volume_dir, audio_dir, limit) {
|
||||||
Ok(cache) => Some(cache),
|
Ok(cache) => Some(cache),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Cannot create cache: {}", e);
|
warn!("Cannot create cache: {e}");
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1240,8 +1239,7 @@ fn get_setup() -> Setup {
|
||||||
let oauth_port = if opt_present(OAUTH_PORT) {
|
let oauth_port = if opt_present(OAUTH_PORT) {
|
||||||
if !enable_oauth {
|
if !enable_oauth {
|
||||||
warn!(
|
warn!(
|
||||||
"Without the `--{}` / `-{}` flag set `--{}` / `-{}` has no effect.",
|
"Without the `--{ENABLE_OAUTH}` / `-{ENABLE_OAUTH_SHORT}` flag set `--{OAUTH_PORT}` / `-{OAUTH_PORT_SHORT}` has no effect."
|
||||||
ENABLE_OAUTH, ENABLE_OAUTH_SHORT, OAUTH_PORT, OAUTH_PORT_SHORT
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
opt_str(OAUTH_PORT)
|
opt_str(OAUTH_PORT)
|
||||||
|
@ -1268,8 +1266,7 @@ fn get_setup() -> Setup {
|
||||||
if let Some(reason) = no_discovery_reason.as_deref() {
|
if let Some(reason) = no_discovery_reason.as_deref() {
|
||||||
if opt_present(ZEROCONF_PORT) {
|
if opt_present(ZEROCONF_PORT) {
|
||||||
warn!(
|
warn!(
|
||||||
"With {} `--{}` / `-{}` has no effect.",
|
"With {reason} `--{ZEROCONF_PORT}` / `-{ZEROCONF_PORT_SHORT}` has no effect."
|
||||||
reason, ZEROCONF_PORT, ZEROCONF_PORT_SHORT
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1348,8 +1345,7 @@ fn get_setup() -> Setup {
|
||||||
if let Some(reason) = no_discovery_reason.as_deref() {
|
if let Some(reason) = no_discovery_reason.as_deref() {
|
||||||
if opt_present(ZEROCONF_BACKEND) {
|
if opt_present(ZEROCONF_BACKEND) {
|
||||||
warn!(
|
warn!(
|
||||||
"With {} `--{}` / `-{}` has no effect.",
|
"With {reason} `--{ZEROCONF_BACKEND}` / `-{ZEROCONF_BACKEND_SHORT}` has no effect."
|
||||||
reason, ZEROCONF_BACKEND, ZEROCONF_BACKEND_SHORT
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1534,7 +1530,7 @@ fn get_setup() -> Setup {
|
||||||
url
|
url
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Invalid proxy URL: \"{}\", only URLs in the format \"http(s)://host:port\" are allowed", e);
|
error!("Invalid proxy URL: \"{e}\", only URLs in the format \"http(s)://host:port\" are allowed");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1591,8 +1587,7 @@ fn get_setup() -> Setup {
|
||||||
] {
|
] {
|
||||||
if opt_present(a) {
|
if opt_present(a) {
|
||||||
warn!(
|
warn!(
|
||||||
"Without the `--{}` / `-{}` flag normalisation options have no effect.",
|
"Without the `--{ENABLE_VOLUME_NORMALISATION}` / `-{ENABLE_VOLUME_NORMALISATION_SHORT}` flag normalisation options have no effect.",
|
||||||
ENABLE_VOLUME_NORMALISATION, ENABLE_VOLUME_NORMALISATION_SHORT,
|
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1774,7 +1769,7 @@ fn get_setup() -> Setup {
|
||||||
"none" => None,
|
"none" => None,
|
||||||
_ => match format {
|
_ => match format {
|
||||||
AudioFormat::F64 | AudioFormat::F32 => {
|
AudioFormat::F64 | AudioFormat::F32 => {
|
||||||
error!("Dithering is not available with format: {:?}.", format);
|
error!("Dithering is not available with format: {format:?}.");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
_ => Some(dither::find_ditherer(ditherer_name).unwrap_or_else(|| {
|
_ => Some(dither::find_ditherer(ditherer_name).unwrap_or_else(|| {
|
||||||
|
@ -1987,7 +1982,7 @@ async fn main() {
|
||||||
|
|
||||||
if let Some(spirc) = spirc.take() {
|
if let Some(spirc) = spirc.take() {
|
||||||
if let Err(e) = spirc.shutdown() {
|
if let Err(e) = spirc.shutdown() {
|
||||||
error!("error sending spirc shutdown message: {}", e);
|
error!("error sending spirc shutdown message: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(spirc_task) = spirc_task.take() {
|
if let Some(spirc_task) = spirc_task.take() {
|
||||||
|
@ -2021,7 +2016,7 @@ async fn main() {
|
||||||
mixer.clone()).await {
|
mixer.clone()).await {
|
||||||
Ok((spirc_, spirc_task_)) => (spirc_, spirc_task_),
|
Ok((spirc_, spirc_task_)) => (spirc_, spirc_task_),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("could not initialize spirc: {}", e);
|
error!("could not initialize spirc: {e}");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2073,7 +2068,7 @@ async fn main() {
|
||||||
// Shutdown spirc if necessary
|
// Shutdown spirc if necessary
|
||||||
if let Some(spirc) = spirc {
|
if let Some(spirc) = spirc {
|
||||||
if let Err(e) = spirc.shutdown() {
|
if let Err(e) = spirc.shutdown() {
|
||||||
error!("error sending spirc shutdown message: {}", e);
|
error!("error sending spirc shutdown message: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(spirc_task) = spirc_task {
|
if let Some(spirc_task) = spirc_task {
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl EventHandler {
|
||||||
PlayerEvent::TrackChanged { audio_item } => {
|
PlayerEvent::TrackChanged { audio_item } => {
|
||||||
match audio_item.track_id.to_base62() {
|
match audio_item.track_id.to_base62() {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("PlayerEvent::TrackChanged: Invalid track id: {}", e)
|
warn!("PlayerEvent::TrackChanged: Invalid track id: {e}")
|
||||||
}
|
}
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "track_changed".to_string());
|
env_vars.insert("PLAYER_EVENT", "track_changed".to_string());
|
||||||
|
@ -94,7 +94,7 @@ impl EventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerEvent::Stopped { track_id, .. } => match track_id.to_base62() {
|
PlayerEvent::Stopped { track_id, .. } => match track_id.to_base62() {
|
||||||
Err(e) => warn!("PlayerEvent::Stopped: Invalid track id: {}", e),
|
Err(e) => warn!("PlayerEvent::Stopped: Invalid track id: {e}"),
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "stopped".to_string());
|
env_vars.insert("PLAYER_EVENT", "stopped".to_string());
|
||||||
env_vars.insert("TRACK_ID", id);
|
env_vars.insert("TRACK_ID", id);
|
||||||
|
@ -105,7 +105,7 @@ impl EventHandler {
|
||||||
position_ms,
|
position_ms,
|
||||||
..
|
..
|
||||||
} => match track_id.to_base62() {
|
} => match track_id.to_base62() {
|
||||||
Err(e) => warn!("PlayerEvent::Playing: Invalid track id: {}", e),
|
Err(e) => warn!("PlayerEvent::Playing: Invalid track id: {e}"),
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "playing".to_string());
|
env_vars.insert("PLAYER_EVENT", "playing".to_string());
|
||||||
env_vars.insert("TRACK_ID", id);
|
env_vars.insert("TRACK_ID", id);
|
||||||
|
@ -117,7 +117,7 @@ impl EventHandler {
|
||||||
position_ms,
|
position_ms,
|
||||||
..
|
..
|
||||||
} => match track_id.to_base62() {
|
} => match track_id.to_base62() {
|
||||||
Err(e) => warn!("PlayerEvent::Paused: Invalid track id: {}", e),
|
Err(e) => warn!("PlayerEvent::Paused: Invalid track id: {e}"),
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "paused".to_string());
|
env_vars.insert("PLAYER_EVENT", "paused".to_string());
|
||||||
env_vars.insert("TRACK_ID", id);
|
env_vars.insert("TRACK_ID", id);
|
||||||
|
@ -125,14 +125,14 @@ impl EventHandler {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PlayerEvent::Loading { track_id, .. } => match track_id.to_base62() {
|
PlayerEvent::Loading { track_id, .. } => match track_id.to_base62() {
|
||||||
Err(e) => warn!("PlayerEvent::Loading: Invalid track id: {}", e),
|
Err(e) => warn!("PlayerEvent::Loading: Invalid track id: {e}"),
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "loading".to_string());
|
env_vars.insert("PLAYER_EVENT", "loading".to_string());
|
||||||
env_vars.insert("TRACK_ID", id);
|
env_vars.insert("TRACK_ID", id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PlayerEvent::Preloading { track_id, .. } => match track_id.to_base62() {
|
PlayerEvent::Preloading { track_id, .. } => match track_id.to_base62() {
|
||||||
Err(e) => warn!("PlayerEvent::Preloading: Invalid track id: {}", e),
|
Err(e) => warn!("PlayerEvent::Preloading: Invalid track id: {e}"),
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "preloading".to_string());
|
env_vars.insert("PLAYER_EVENT", "preloading".to_string());
|
||||||
env_vars.insert("TRACK_ID", id);
|
env_vars.insert("TRACK_ID", id);
|
||||||
|
@ -141,8 +141,7 @@ impl EventHandler {
|
||||||
PlayerEvent::TimeToPreloadNextTrack { track_id, .. } => {
|
PlayerEvent::TimeToPreloadNextTrack { track_id, .. } => {
|
||||||
match track_id.to_base62() {
|
match track_id.to_base62() {
|
||||||
Err(e) => warn!(
|
Err(e) => warn!(
|
||||||
"PlayerEvent::TimeToPreloadNextTrack: Invalid track id: {}",
|
"PlayerEvent::TimeToPreloadNextTrack: Invalid track id: {e}"
|
||||||
e
|
|
||||||
),
|
),
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "preload_next".to_string());
|
env_vars.insert("PLAYER_EVENT", "preload_next".to_string());
|
||||||
|
@ -151,14 +150,14 @@ impl EventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerEvent::EndOfTrack { track_id, .. } => match track_id.to_base62() {
|
PlayerEvent::EndOfTrack { track_id, .. } => match track_id.to_base62() {
|
||||||
Err(e) => warn!("PlayerEvent::EndOfTrack: Invalid track id: {}", e),
|
Err(e) => warn!("PlayerEvent::EndOfTrack: Invalid track id: {e}"),
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "end_of_track".to_string());
|
env_vars.insert("PLAYER_EVENT", "end_of_track".to_string());
|
||||||
env_vars.insert("TRACK_ID", id);
|
env_vars.insert("TRACK_ID", id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PlayerEvent::Unavailable { track_id, .. } => match track_id.to_base62() {
|
PlayerEvent::Unavailable { track_id, .. } => match track_id.to_base62() {
|
||||||
Err(e) => warn!("PlayerEvent::Unavailable: Invalid track id: {}", e),
|
Err(e) => warn!("PlayerEvent::Unavailable: Invalid track id: {e}"),
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "unavailable".to_string());
|
env_vars.insert("PLAYER_EVENT", "unavailable".to_string());
|
||||||
env_vars.insert("TRACK_ID", id);
|
env_vars.insert("TRACK_ID", id);
|
||||||
|
@ -173,7 +172,7 @@ impl EventHandler {
|
||||||
position_ms,
|
position_ms,
|
||||||
..
|
..
|
||||||
} => match track_id.to_base62() {
|
} => match track_id.to_base62() {
|
||||||
Err(e) => warn!("PlayerEvent::Seeked: Invalid track id: {}", e),
|
Err(e) => warn!("PlayerEvent::Seeked: Invalid track id: {e}"),
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "seeked".to_string());
|
env_vars.insert("PLAYER_EVENT", "seeked".to_string());
|
||||||
env_vars.insert("TRACK_ID", id);
|
env_vars.insert("TRACK_ID", id);
|
||||||
|
@ -186,7 +185,7 @@ impl EventHandler {
|
||||||
..
|
..
|
||||||
} => match track_id.to_base62() {
|
} => match track_id.to_base62() {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("PlayerEvent::PositionCorrection: Invalid track id: {}", e)
|
warn!("PlayerEvent::PositionCorrection: Invalid track id: {e}")
|
||||||
}
|
}
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
env_vars.insert("PLAYER_EVENT", "position_correction".to_string());
|
env_vars.insert("PLAYER_EVENT", "position_correction".to_string());
|
||||||
|
@ -263,7 +262,7 @@ impl Drop for EventHandler {
|
||||||
debug!("Shutting down EventHandler thread ...");
|
debug!("Shutting down EventHandler thread ...");
|
||||||
if let Some(handle) = self.thread_handle.take() {
|
if let Some(handle) = self.thread_handle.take() {
|
||||||
if let Err(e) = handle.join() {
|
if let Err(e) = handle.join() {
|
||||||
error!("EventHandler thread Error: {:?}", e);
|
error!("EventHandler thread Error: {e:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,8 +288,7 @@ fn run_program(env_vars: HashMap<&str, String>, onevent: &str) {
|
||||||
let mut v: Vec<&str> = onevent.split_whitespace().collect();
|
let mut v: Vec<&str> = onevent.split_whitespace().collect();
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Running {} with environment variables:\n{:#?}",
|
"Running {onevent} with environment variables:\n{env_vars:#?}"
|
||||||
onevent, env_vars
|
|
||||||
);
|
);
|
||||||
|
|
||||||
match Command::new(v.remove(0))
|
match Command::new(v.remove(0))
|
||||||
|
@ -298,15 +296,15 @@ fn run_program(env_vars: HashMap<&str, String>, onevent: &str) {
|
||||||
.envs(env_vars.iter())
|
.envs(env_vars.iter())
|
||||||
.spawn()
|
.spawn()
|
||||||
{
|
{
|
||||||
Err(e) => warn!("On event program {} failed to start: {}", onevent, e),
|
Err(e) => warn!("On event program {onevent} failed to start: {e}"),
|
||||||
Ok(mut child) => match child.wait() {
|
Ok(mut child) => match child.wait() {
|
||||||
Err(e) => warn!("On event program {} failed: {}", onevent, e),
|
Err(e) => warn!("On event program {onevent} failed: {e}"),
|
||||||
Ok(e) if e.success() => (),
|
Ok(e) if e.success() => (),
|
||||||
Ok(e) => {
|
Ok(e) => {
|
||||||
if let Some(code) = e.code() {
|
if let Some(code) = e.code() {
|
||||||
warn!("On event program {} returned exit code {}", onevent, code);
|
warn!("On event program {onevent} returned exit code {code}");
|
||||||
} else {
|
} else {
|
||||||
warn!("On event program {} returned failure: {}", onevent, e);
|
warn!("On event program {onevent} returned failure: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue