Skip to content

Commit

Permalink
Fix artist display (#74) (#75)
Browse files Browse the repository at this point in the history
Grab Song artist(s) instead of Album Artist.

This streamlines the code a bit (and fixes a bug!), made a new function called get_artists() that formats them correctly and the code is now using that for audiobooks and music.
  • Loading branch information
Radiicall authored Oct 7, 2023
1 parent ae3dc54 commit 5ed7bde
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/services/jellyfin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@ impl Content {
return Some(());
}
}
let artist = now_playing_item["AlbumArtist"].as_str()?.to_string();
let raw_artists = now_playing_item["Artists"]
.as_array()?
.iter()
.map(|a| a.as_str().unwrap().to_string())
.collect::<Vec<String>>();

let artists = Self::get_artists(raw_artists);

let display = match config
.jellyfin
Expand All @@ -225,7 +231,7 @@ impl Content {
.unwrap_or('-');

let state =
Content::get_music_info(now_playing_item, artist, display, name, separator).await;
Content::get_music_info(now_playing_item, artists, display, name, separator).await;

content.media_type(MediaType::Music);
content.details(name.into());
Expand Down Expand Up @@ -259,18 +265,7 @@ impl Content {
.map(|a| a.as_str().unwrap().to_string())
.collect::<Vec<String>>();

let mut artists = String::new();

for (i, artist) in raw_artists.iter().enumerate() {
if i != 0 {
if i == raw_artists.len() - 1 {
artists += " and ";
} else {
artists += ", "
}
}
artists += artist
}
let artists = Self::get_artists(raw_artists);

let mut genres = Content::get_genres(now_playing_item).unwrap_or(String::from(""));

Expand All @@ -286,6 +281,21 @@ impl Content {
Some(())
}

fn get_artists(raw_artists: Vec<String>) -> String {
let mut artists = String::new();
for (i, artist) in raw_artists.iter().enumerate() {
if i != 0 {
if i == raw_artists.len() - 1 {
artists += " and ";
} else {
artists += ", "
}
}
artists += artist
}
artists
}

async fn time_left(now_playing_item: &Value, play_state: &Value) -> Option<i64> {
if !play_state["IsPaused"].as_bool()? {
let ticks_to_seconds = 10000000;
Expand All @@ -310,12 +320,12 @@ impl Content {

async fn get_music_info(
npi: &Value,
artist: String,
artists: String,
display: Vec<std::string::String>,
name: &str,
separator: char,
) -> String {
let mut state = format!("By {}", artist);
let mut state = format!("By {}", artists);

display.iter().for_each(|data| {
let data = data.as_str();
Expand Down

0 comments on commit 5ed7bde

Please sign in to comment.