Improved verbosity on build
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -38,9 +38,9 @@ enum Command {
|
|||||||
},
|
},
|
||||||
/// Build a playlist from similar artists
|
/// Build a playlist from similar artists
|
||||||
Build {
|
Build {
|
||||||
/// Print track scores
|
/// Verbosity level (-v, -vv)
|
||||||
#[arg(short)]
|
#[arg(short, action = clap::ArgAction::Count)]
|
||||||
verbose: bool,
|
verbose: u8,
|
||||||
/// Queue in MPD
|
/// Queue in MPD
|
||||||
#[arg(short, conflicts_with = "airsonic")]
|
#[arg(short, conflicts_with = "airsonic")]
|
||||||
mpd: bool,
|
mpd: bool,
|
||||||
@@ -65,7 +65,7 @@ enum Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct BuildOptions {
|
struct BuildOptions {
|
||||||
verbose: bool,
|
verbose: u8,
|
||||||
mpd: bool,
|
mpd: bool,
|
||||||
airsonic: bool,
|
airsonic: bool,
|
||||||
shuffle: bool,
|
shuffle: bool,
|
||||||
@@ -358,10 +358,11 @@ fn build_playlist(
|
|||||||
|
|
||||||
let scored = playlist::score_tracks(conn, &artists, opts.popularity_bias);
|
let scored = playlist::score_tracks(conn, &artists, opts.popularity_bias);
|
||||||
|
|
||||||
if opts.verbose {
|
if opts.verbose >= 1 {
|
||||||
let mut sorted = scored.iter().collect::<Vec<_>>();
|
let mut sorted = scored.iter().collect::<Vec<_>>();
|
||||||
sorted.sort_by(|a, b| b.score.partial_cmp(&a.score).unwrap_or(std::cmp::Ordering::Equal));
|
sorted.sort_by(|a, b| b.score.partial_cmp(&a.score).unwrap_or(std::cmp::Ordering::Equal));
|
||||||
for t in &sorted {
|
let limit = if opts.verbose >= 2 { sorted.len() } else { 50.min(sorted.len()) };
|
||||||
|
for t in &sorted[..limit] {
|
||||||
eprintln!("{:.4}\t{:.4}\t{:.4}\t{}\t{}", t.score, t.similarity, t.popularity, t.artist, t.path);
|
eprintln!("{:.4}\t{:.4}\t{:.4}\t{}\t{}", t.score, t.similarity, t.popularity, t.artist, t.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,7 +419,7 @@ fn output_tracks(
|
|||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Err(e) = client.create_playlist(seed_name, tracks, conn, opts.verbose) {
|
if let Err(e) = client.create_playlist(seed_name, tracks, conn, opts.verbose >= 1) {
|
||||||
eprintln!("Airsonic error: {e}");
|
eprintln!("Airsonic error: {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user