Removed mpd re-sync
This commit is contained in:
31
src/mpd.rs
31
src/mpd.rs
@@ -84,28 +84,43 @@ impl MpdClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn queue_playlist(&mut self, tracks: &[String], music_dir: &str) {
|
pub fn queue_playlist(&mut self, tracks: &[String], music_dir: &str) {
|
||||||
if let Err(e) = self.update_and_wait() {
|
|
||||||
eprintln!("MPD update: {e}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Err(e) = self.send_command("clear") {
|
if let Err(e) = self.send_command("clear") {
|
||||||
eprintln!("MPD clear: {e}");
|
eprintln!("MPD clear: {e}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut failed: Vec<String> = Vec::new();
|
||||||
|
|
||||||
for track in tracks {
|
for track in tracks {
|
||||||
let uri = track
|
let uri = Self::track_to_uri(track, music_dir);
|
||||||
.strip_prefix(music_dir)
|
let escaped = uri.replace('\\', "\\\\").replace('"', "\\\"");
|
||||||
.map(|p| p.trim_start_matches('/'))
|
if self.send_command(&format!("add \"{escaped}\"")).is_err() {
|
||||||
.unwrap_or(track);
|
failed.push(uri.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If some tracks failed, update MPD's DB and retry them
|
||||||
|
if !failed.is_empty() {
|
||||||
|
eprintln!("MPD: {} tracks not found, updating database...", failed.len());
|
||||||
|
if self.update_and_wait().is_ok() {
|
||||||
|
for uri in &failed {
|
||||||
let escaped = uri.replace('\\', "\\\\").replace('"', "\\\"");
|
let escaped = uri.replace('\\', "\\\\").replace('"', "\\\"");
|
||||||
if let Err(e) = self.send_command(&format!("add \"{escaped}\"")) {
|
if let Err(e) = self.send_command(&format!("add \"{escaped}\"")) {
|
||||||
eprintln!("MPD add {uri}: {e}");
|
eprintln!("MPD add {uri}: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Err(e) = self.send_command("play") {
|
if let Err(e) = self.send_command("play") {
|
||||||
eprintln!("MPD play: {e}");
|
eprintln!("MPD play: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn track_to_uri<'a>(track: &'a str, music_dir: &str) -> &'a str {
|
||||||
|
track
|
||||||
|
.strip_prefix(music_dir)
|
||||||
|
.map(|p| p.trim_start_matches('/'))
|
||||||
|
.unwrap_or(track)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user