modernize code

This commit is contained in:
Julien Rabier 2025-10-30 15:22:15 +01:00
parent 2a610965a1
commit 18a56f4454
2 changed files with 14 additions and 12 deletions

View File

@ -1,11 +1,11 @@
[package]
name = "mpdyn"
version = "0.1.2"
version = "0.1.3"
authors = ["Julien Rabier <taziden@flexiden.org>"]
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
mpdrs = "0.1.0"
rand = "0.8.4"
rand = "0.9.2"

View File

@ -1,6 +1,6 @@
use mpdrs::lsinfo::LsInfoResponse;
use mpdrs::{Client, Song};
use rand::prelude::*;
use rand::{prelude::*, rng};
use std::{error::Error, thread, time};
fn main() -> Result<(), Box<dyn Error>> {
@ -40,15 +40,17 @@ fn populate_playlist(a: u32) -> Result<(), Box<dyn Error>> {
}
fn get_random_tracks(n: u32) -> Result<Vec<Song>, Box<dyn Error>> {
let mut rng = rand::thread_rng();
let mut rng = rng();
let query_albums = Client::default().lsinfo("/")?;
let tracks: Vec<Song> = query_albums
let tracks: Vec<Song> = Iterator::filter_map(
query_albums
.choose_multiple(&mut rng, n.try_into()?)
.filter(|&x| match_directory(x).is_ok())
.map(find_path)
.filter_map(|x| Some(get_random_track(x)).unwrap())
.map(find_path),
get_random_track,
)
.collect();
Ok(tracks)
@ -65,7 +67,7 @@ fn match_directory(response: &LsInfoResponse) -> Result<i32, i32> {
}
fn get_random_track(path: &str) -> Option<Song> {
let mut rng = rand::thread_rng();
let mut rng = rng();
match Client::default().lsinfo(path) {
Ok(songs) => match songs.choose(&mut rng) {