Improve lastfm search filter

This commit is contained in:
nathom 2021-07-31 10:07:02 -07:00
parent af50b7f9c7
commit f442e2855c

View file

@ -488,6 +488,14 @@ class RipCore(list):
self._config_corrupted_message(err) self._config_corrupted_message(err)
exit() 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: def search_query(title, artist, playlist) -> bool:
"""Search for a query and add the first result to playlist. """Search for a query and add the first result to playlist.
@ -503,7 +511,16 @@ class RipCore(list):
query = QUERY_FORMAT[lastfm_source].format( query = QUERY_FORMAT[lastfm_source].format(
title=title, artist=artist 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 # Because the track is searched as a single we need to set
# this manually # this manually
track.part_of_tracklist = True track.part_of_tracklist = True