From f442e2855cc7d63ca6a3f5e0536a91a1181d9e86 Mon Sep 17 00:00:00 2001 From: nathom Date: Sat, 31 Jul 2021 10:07:02 -0700 Subject: [PATCH] Improve lastfm search filter --- rip/core.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/rip/core.py b/rip/core.py index 9248bc4..3a41e32 100644 --- a/rip/core.py +++ b/rip/core.py @@ -488,6 +488,14 @@ class RipCore(list): self._config_corrupted_message(err) exit() + # Do not include tracks that have (re)mix, live, karaoke in their titles + # within parentheses or brackets + # This will match somthing like "Test (Person Remix]" though, so its not perfect + banned_words_plain = re.compile(r"(?i)(?:(?:re)?mix|live|karaoke)") + banned_words = re.compile( + rf"(?i)[\(\[][^\)\]]*?(?:(?:re)?mix|live|karaoke)[^\)\]]*[\]\)]" + ) + def search_query(title, artist, playlist) -> bool: """Search for a query and add the first result to playlist. @@ -503,7 +511,16 @@ class RipCore(list): query = QUERY_FORMAT[lastfm_source].format( title=title, artist=artist ) - track = next(self.search(source, query, media_type="track")) + query_is_clean = banned_words_plain.search(query) is None + + search_results = self.search(source, query, media_type="track") + track = next(search_results) + + if query_is_clean: + while banned_words.search(track["title"]) is not None: + logger.debug("Track title banned for query=%s", query) + track = next(search_results) + # Because the track is searched as a single we need to set # this manually track.part_of_tracklist = True