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 <trivernis@protonmail.com>
pull/17/head
trivernis 3 years ago
parent 6b4863fb0a
commit 017f1e8f46
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -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? {

Loading…
Cancel
Save