From 5412b7034b2b11016474a324e6d8bfcc586ec161 Mon Sep 17 00:00:00 2001 From: Kim Wittenburg <5wittenb@informatik.uni-hamburg.de> Date: Tue, 4 Sep 2018 11:35:52 +0200 Subject: [PATCH] Add sanitize_searches Option --- beetsplug/itunes.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/beetsplug/itunes.py b/beetsplug/itunes.py index dba8fd2..cddf797 100644 --- a/beetsplug/itunes.py +++ b/beetsplug/itunes.py @@ -72,6 +72,7 @@ class iTunesPlugin(BeetsPlugin): 'search_countries': ['US'], 'lookup_countries': ['US', 'DE', 'AU', 'GB', 'FR', 'IT', 'JP'], 'search_limit': 5, + 'sanitize_searches': True, # Whether to remove parenthesized and braced text from searches 'artwork': False, # Whether to also download artwork from iTunes. Does not work well with fetchart 'method': 'lookup', # Valid values: 'search', 'lookup', 'both', 'lookup (search fallback)' }) @@ -106,6 +107,10 @@ class iTunesPlugin(BeetsPlugin): @property def search_limit(self): return self.config['search_limit'].as_number() + + @property + def sanitize_searches(self): + return self.config['sanitize_searches'] def scan_track_ids(self, session, task): self._log.debug("Scanning track IDs") @@ -170,12 +175,19 @@ class iTunesPlugin(BeetsPlugin): def search_albums(self, artist, album, va_likely): """Searches for matching albums on iTunes. """ - + + if self.sanitize_searches: + pattern = re.compile('(\s*(\(.*\)|\[.*\]|\{.*\}))*$') + album = pattern.sub('', album) + artist = pattern.sub('', artist) + if va_likely: query = album else: query = '%s %s' % (artist, album) + print("Searching", query) + albums = [] for country in self.search_countries: try: