diff --git a/Cargo.toml b/Cargo.toml index 6db4aa8..9c8568f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mpdyn" -version = "0.1.1" +version = "0.1.2" authors = ["Julien Rabier "] edition = "2021" @@ -8,5 +8,4 @@ edition = "2021" [dependencies] mpdrs = "0.1.0" -chrono = "0.4.19" rand = "0.8.4" diff --git a/src/main.rs b/src/main.rs index 1cc8118..6f7cdcf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -//use chrono::Local; use mpdrs::lsinfo::LsInfoResponse; use mpdrs::{Client, Song}; use rand::prelude::*; @@ -45,18 +44,14 @@ fn get_random_tracks(n: u32) -> Result, Box> { let query_albums = Client::default().lsinfo("/")?; - let albums: Vec<&str> = query_albums + let tracks: Vec = query_albums .choose_multiple(&mut rng, n.try_into()?) .filter(|&x| match_directory(x).is_ok()) - .map(|x| find_path(x)) - .collect(); - - let tracks: Vec = albums - .into_iter() + .map(find_path) .filter_map(|x| Some(get_random_track(x)).unwrap()) .collect(); - return Ok(tracks); + Ok(tracks) } fn match_directory(response: &LsInfoResponse) -> Result { @@ -87,40 +82,3 @@ fn find_path(response: &LsInfoResponse) -> &str { _ => "", } } - -/* -fn add_track() { - let mut c = Client::default(); - - if let Some(res) = get_random_track() { - println!("adding: {:?}", res.file); - - let _ = c.push(&res.file); - let _ = c.close(); - } else { - println!("could not add track") - } -} -*/ -/* -fn get_random_track() -> Option { - let mut c = Client::default(); - let mut rng = rand::thread_rng(); - - match c.lsinfo("/") { - Ok(albums) => match albums.choose(&mut rng) { - Some(LsInfoResponse::Directory { path, metadata: _ }) => match c.lsinfo(path) { - Ok(songs) => match songs.choose(&mut rng) { - Some(LsInfoResponse::Song(song)) => Some(song.clone()), - _ => None, - }, - Err(_) => None, - }, - Some(LsInfoResponse::Song(_)) => None, - Some(LsInfoResponse::Playlist { .. }) => None, - None => None, - }, - Err(_) => None, - } -} -*/