From 017f1e8f469a7e9669799c1867c75f80e48ea509 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 15 Apr 2021 19:12:52 +0200 Subject: [PATCH] Change cleaing of song names for spotify search Now the regex is applied before all nonalphanumeric chars are deleted. Additionally everything in square brackets will be deleted. Signed-off-by: trivernis --- src/providers/music/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/providers/music/mod.rs b/src/providers/music/mod.rs index ee72ab0..2fe841a 100644 --- a/src/providers/music/mod.rs +++ b/src/providers/music/mod.rs @@ -83,12 +83,10 @@ async fn search_for_song_variations( static COMMON_AFFIXES: &str = r"feat\.(\s\w+)|official(\svideo)?|remastered|revisited|(with\s)?lyrics"; lazy_static::lazy_static! { - static ref COMMON_ADDITIONS: Regex = Regex::new(format!(r"(?i)\[|\]|\(?[^\w\s]*\s?({})[^\w\s]*\s?\)?", COMMON_AFFIXES).as_str()).unwrap(); + static ref COMMON_ADDITIONS: Regex = Regex::new(format!(r"(?i)\[.*\]|\(?[^\w\s]*\s?({})[^\w\s]*\s?\)?", COMMON_AFFIXES).as_str()).unwrap(); } - let mut query = song - .title() - .replace(|c| c != ' ' && !char::is_alphanumeric(c), ""); - query = COMMON_ADDITIONS.replace_all(&query, " ").to_string(); + let mut query = COMMON_ADDITIONS.replace_all(song.title(), " ").to_string(); + query = query.replace(|c| c != ' ' && !char::is_alphanumeric(c), ""); log::debug!("Searching for youtube song"); if let Some(track) = store.spotify_api.search_for_song(&query).await? {