Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing release year on search result listings and artist pages #1024

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Added

- Show year of album `release_date` in Search panes and on Artist album panes [#1024](https://github.com/Rigellute/spotify-tui/pull/1024)
- Show `album_type` in Search panes [#868](https://github.com/Rigellute/spotify-tui/pull/868)
- Add option to set window title to "spt - Spotify TUI" on startup [#844](https://github.com/Rigellute/spotify-tui/pull/844)

Expand Down
8 changes: 5 additions & 3 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use tui::{
Frame,
};
use util::{
create_artist_string, display_track_progress, get_artist_highlight_state, get_color,
create_artist_string, create_album_type_and_release_year_string, display_track_progress, get_artist_highlight_state, get_color,
get_percentage_width, get_search_results_highlight_state, get_track_progress_percentage,
millis_to_minutes, BASIC_VIEW_HEIGHT, SMALL_TERMINAL_WIDTH,
};
Expand Down Expand Up @@ -470,11 +470,12 @@ where
album_artist.push_str(&app.user_config.padded_liked_icon());
}
}

album_artist.push_str(&format!(
"{} - {} ({})",
item.name.to_owned(),
create_artist_string(&item.artists),
item.album_type.as_deref().unwrap_or("unknown")
create_album_type_and_release_year_string(item)
));
album_artist
})
Expand Down Expand Up @@ -1238,11 +1239,12 @@ where
album_artist.push_str(&app.user_config.padded_liked_icon());
}
}

album_artist.push_str(&format!(
"{} - {} ({})",
item.name.to_owned(),
create_artist_string(&item.artists),
item.album_type.as_deref().unwrap_or("unknown")
create_album_type_and_release_year_string(item)
));
album_artist
})
Expand Down
9 changes: 9 additions & 0 deletions src/ui/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::super::app::{ActiveBlock, App, ArtistBlock, SearchResultBlock};
use crate::user_config::Theme;
use rspotify::model::artist::SimplifiedArtist;
use rspotify::model::album::SimplifiedAlbum;
use tui::style::Style;

pub const BASIC_VIEW_HEIGHT: u16 = 6;
Expand Down Expand Up @@ -47,6 +48,14 @@ pub fn create_artist_string(artists: &[SimplifiedArtist]) -> String {
.join(", ")
}

pub fn create_album_type_and_release_year_string(album_item: &SimplifiedAlbum) -> String {
// No matter the release_date_precision, release_date should always start with a four-digit string of the year (YYYY[-MM[-DD]]).
// Getting those first four letters/digits should always work.
let album_release_year = album_item.release_date.as_deref().unwrap().get(0..4).unwrap();

album_item.album_type.as_deref().unwrap_or("unknown").to_owned() + ", " + album_release_year
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the above code can be improved, I’m all ears!

}

pub fn millis_to_minutes(millis: u128) -> String {
let minutes = millis / 60000;
let seconds = (millis % 60000) / 1000;
Expand Down