some fixed, thanks clippy
This commit is contained in:
parent
9150dc5bcd
commit
2a610965a1
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mpdyn"
|
name = "mpdyn"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
authors = ["Julien Rabier <taziden@flexiden.org>"]
|
authors = ["Julien Rabier <taziden@flexiden.org>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
@ -8,5 +8,4 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mpdrs = "0.1.0"
|
mpdrs = "0.1.0"
|
||||||
chrono = "0.4.19"
|
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
|
|||||||
48
src/main.rs
48
src/main.rs
@ -1,4 +1,3 @@
|
|||||||
//use chrono::Local;
|
|
||||||
use mpdrs::lsinfo::LsInfoResponse;
|
use mpdrs::lsinfo::LsInfoResponse;
|
||||||
use mpdrs::{Client, Song};
|
use mpdrs::{Client, Song};
|
||||||
use rand::prelude::*;
|
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 query_albums = Client::default().lsinfo("/")?;
|
||||||
|
|
||||||
let albums: Vec<&str> = query_albums
|
let tracks: Vec<Song> = query_albums
|
||||||
.choose_multiple(&mut rng, n.try_into()?)
|
.choose_multiple(&mut rng, n.try_into()?)
|
||||||
.filter(|&x| match_directory(x).is_ok())
|
.filter(|&x| match_directory(x).is_ok())
|
||||||
.map(|x| find_path(x))
|
.map(find_path)
|
||||||
.collect();
|
|
||||||
|
|
||||||
let tracks: Vec<Song> = albums
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|x| Some(get_random_track(x)).unwrap())
|
.filter_map(|x| Some(get_random_track(x)).unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
return Ok(tracks);
|
Ok(tracks)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn match_directory(response: &LsInfoResponse) -> Result<i32, i32> {
|
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user