Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ spotify_player -o device.volume=80 -o theme=dracula
| `enable_streaming` | Enable streaming (`Always`, `Never`, or `DaemonOnly`). | `Always` |
| `enable_audio_visualization` | Show a real-time frequency bar chart in the playback window (requires `streaming` feature). | `false` |
| `enable_notify` | Enable notifications (requires `notify` feature). | `true` |
| `sort_ignore_the` | Ignore "the" at the start of names when sorting in library. | `true` |
| `enable_cover_image_cache` | Cache album cover images. | `true` |
| `notify_streaming_only` | Send notifications only when streaming is active (requires `streaming` and `notify` features). | `false` |
| `default_device` | Default device to connect to on startup. | `spotify-player` |
Expand Down
4 changes: 4 additions & 0 deletions spotify_player/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ pub struct AppConfig {
#[cfg(feature = "notify")]
pub enable_notify: bool,

pub sort_ignore_the: bool,

pub enable_cover_image_cache: bool,

pub default_device: String,
Expand Down Expand Up @@ -375,6 +377,8 @@ impl Default for AppConfig {
#[cfg(feature = "notify")]
enable_notify: true,

sort_ignore_the: true,

enable_cover_image_cache: true,

default_device: "spotify-player".to_string(),
Expand Down
19 changes: 13 additions & 6 deletions spotify_player/src/event/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ fn handle_command_for_library_page(
if command == Command::SortLibraryAlphabetically {
let mut data = state.data.write();

// Always compare using lowercase, strip "the " prefix if set in config
let filter = if config::get_config().app_config.sort_ignore_the {
|name: &str| {
let lowered = name.to_lowercase();
lowered.strip_prefix("the ").unwrap_or(&lowered).to_string()
}
} else {
|name: &str| name.to_lowercase()
};

// Sort playlists alphabetically, keeping folders on top
data.user_data.playlists.sort_by(|a, b| match (a, b) {
(PlaylistFolderItem::Folder(_), PlaylistFolderItem::Playlist(_)) => {
Expand All @@ -112,21 +122,18 @@ fn handle_command_for_library_page(
(PlaylistFolderItem::Playlist(_), PlaylistFolderItem::Folder(_)) => {
std::cmp::Ordering::Greater
}
_ => a
.to_string()
.to_lowercase()
.cmp(&b.to_string().to_lowercase()),
_ => filter(&a.to_string()).cmp(&filter(&b.to_string())),
});

// Sort albums alphabetically
data.user_data
.saved_albums
.sort_by(|x, y| x.name.to_lowercase().cmp(&y.name.to_lowercase()));
.sort_by(|x, y| filter(&x.name).cmp(&filter(&y.name)));

// Sort artists alphabetically
data.user_data
.followed_artists
.sort_by(|x, y| x.name.to_lowercase().cmp(&y.name.to_lowercase()));
.sort_by(|x, y| filter(&x.name).cmp(&filter(&y.name)));
}

if command == Command::SortLibraryByRecent {
Expand Down