Added basic airsonic support

This commit is contained in:
Connor Johnstone
2026-03-03 14:56:00 -05:00
parent 51ededc612
commit 98e3367822
4 changed files with 249 additions and 14 deletions

View File

@@ -83,7 +83,7 @@ impl MpdClient {
}
}
pub fn queue_playlist(&mut self, tracks: &[String], music_dir: &str) {
pub fn queue_playlist(&mut self, tracks: &[String], local_dir: &str, mpd_dir: &str) {
if let Err(e) = self.send_command("clear") {
eprintln!("MPD clear: {e}");
return;
@@ -92,7 +92,7 @@ impl MpdClient {
let mut failed: Vec<String> = Vec::new();
for track in tracks {
let uri = Self::track_to_uri(track, music_dir);
let uri = Self::track_to_uri(track, local_dir, mpd_dir);
let escaped = uri.replace('\\', "\\\\").replace('"', "\\\"");
if self.send_command(&format!("add \"{escaped}\"")).is_err() {
failed.push(uri.to_string());
@@ -117,10 +117,12 @@ impl MpdClient {
}
}
fn track_to_uri<'a>(track: &'a str, music_dir: &str) -> &'a str {
track
.strip_prefix(music_dir)
fn track_to_uri(track: &str, local_dir: &str, mpd_dir: &str) -> String {
let relative = track
.strip_prefix(local_dir)
.map(|p| p.trim_start_matches('/'))
.unwrap_or(track)
.unwrap_or(track);
let mpd_base = mpd_dir.trim_end_matches('/');
format!("{mpd_base}/{relative}")
}
}