From 2786c6ba3476fe0f4cacc3fee634193482948341 Mon Sep 17 00:00:00 2001 From: bentheklutz <115167576+bentheklutz@users.noreply.github.com> Date: Sat, 22 Jul 2023 06:05:03 -0500 Subject: [PATCH] Sort Artists Ignoring "The" (#1238) * Sorting QoL Ignore leading "The" when sorting albums and artists by artist name in the library. * Simplify stripping of `The ` prefix in artist --------- Co-authored-by: Henrik Friedrichsen --- src/library.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/library.rs b/src/library.rs index e6c81b5..079f073 100644 --- a/src/library.rs +++ b/src/library.rs @@ -396,11 +396,15 @@ impl Library { } albums.sort_unstable_by_key(|album| { + let album_artist = album.artists[0] + .strip_prefix("The ") + .unwrap_or(&album.artists[0]); + let album_title = album.title.strip_prefix("The ").unwrap_or(&album.title); format!( "{}{}{}", - album.artists[0].to_lowercase(), + album_artist.to_lowercase(), album.year, - album.title.to_lowercase() + album_title.to_lowercase() ) }); @@ -483,7 +487,12 @@ impl Library { artist.tracks = Some(Vec::new()); } - artists.sort_unstable_by(|a, b| a.name.partial_cmp(&b.name).unwrap()); + artists.sort_unstable_by(|a, b| { + let a_cmp = a.name.strip_prefix("The ").unwrap_or(&a.name); + let b_cmp = b.name.strip_prefix("The ").unwrap_or(&b.name); + + a_cmp.partial_cmp(b_cmp).unwrap() + }); // Add saved tracks to artists {