some fixed, thanks clippy

This commit is contained in:
Julien Rabier 2022-01-02 16:33:03 +01:00
parent 9150dc5bcd
commit 2a610965a1
2 changed files with 4 additions and 47 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "mpdyn"
version = "0.1.1"
version = "0.1.2"
authors = ["Julien Rabier <taziden@flexiden.org>"]
edition = "2021"
@ -8,5 +8,4 @@ edition = "2021"
[dependencies]
mpdrs = "0.1.0"
chrono = "0.4.19"
rand = "0.8.4"

View File

@ -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<Vec<Song>, Box<dyn Error>> {
let query_albums = Client::default().lsinfo("/")?;
let albums: Vec<&str> = query_albums
let tracks: Vec<Song> = 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<Song> = 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<i32, i32> {
@ -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<Song> {
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,
}
}
*/