From c644cb4e61f5519bfb50e45efed4db9e765ed425 Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 10 Feb 2020 14:38:48 +0900 Subject: [PATCH] Fix artist parsing from metadata --- src/blocks/music.rs | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/blocks/music.rs b/src/blocks/music.rs index 1be56517..3c951d2b 100644 --- a/src/blocks/music.rs +++ b/src/blocks/music.rs @@ -318,6 +318,20 @@ impl Block for Music { } } +fn extract_artist_from_value(value: &dyn arg::RefArg) -> Result<&str> { + if let Some(artist) = value.as_str() { + Ok(artist) + } else { + extract_artist_from_value( + value + .as_iter() + .block_error("music", "failed to extract artist")? + .next() + .block_error("music", "failed to extract artist")?, + ) + } +} + fn extract_from_metadata(metadata: &Box) -> Result<(String, String)> { let mut title = String::new(); let mut artist = String::new(); @@ -334,25 +348,7 @@ fn extract_from_metadata(metadata: &Box) -> Result<(String, Str .as_str() .block_error("music", "failed to extract metadata")? { - "xesam:artist" => { - artist = String::from( - value - .as_iter() - .block_error("music", "failed to extract metadata")? - .nth(0) - .block_error("music", "failed to extract metadata")? - .as_iter() - .block_error("music", "failed to extract metadata")? - .nth(0) - .block_error("music", "failed to extract metadata")? - .as_iter() - .block_error("music", "failed to extract metadata")? - .nth(0) - .block_error("music", "failed to extract metadata")? - .as_str() - .block_error("music", "failed to extract metadata")?, - ) - } + "xesam:artist" => artist = String::from(extract_artist_from_value(value)?), "xesam:title" => { title = String::from( value