remove this absolute brainfuck of a function, what the fuck

This commit is contained in:
krolxon 2024-04-22 14:46:12 +05:30
parent bc0348ec5b
commit 3578eae01a
1 changed files with 6 additions and 23 deletions

View File

@ -10,8 +10,12 @@ pub struct Connection {
impl Connection {
pub fn new(addrs: &str) -> Result<Self, mpd::error::Error> {
let mut conn = Client::connect(addrs)?;
let mut songs_filenames: Vec<String> = Vec::new();
get_file_tree_into_vec(&mut conn, &mut songs_filenames, ".", ".");
let songs_filenames: Vec<String> = conn
.listall()
.unwrap()
.iter()
.map(|x| x.clone().file)
.collect();
Ok(Self {
conn,
@ -99,27 +103,6 @@ impl Connection {
}
}
fn get_file_tree_into_vec(conn: &mut Client, vec: &mut Vec<String>, path: &str, dir_append: &str) {
let songs = conn.listfiles(path).unwrap_or_default();
for (i, s) in songs {
// Output of listfiles contains the last-modified thing, we dont want that
if i != "Last-Modified" {
if i == "directory" {
get_file_tree_into_vec(conn, vec, &s, &s);
} else {
// We parse the string as float because the output of listfiles contains some random numbers, we dont want that
if !s.parse::<f32>().is_ok() {
let mut sam: String = String::new();
sam.push_str(dir_append);
sam.push_str(r"/");
sam.push_str(s.as_str());
vec.push(sam);
}
}
}
}
}
fn get_choice_index(ss: &Vec<String>, selection: &str) -> usize {
let mut choice: usize = 0;
if let Some(index) = ss.iter().position(|s| s == selection) {