1

Add sanitize_searches Option

This commit is contained in:
Kim Wittenburg
2018-09-04 11:35:52 +02:00
parent 2dc716622e
commit 5412b7034b

View File

@@ -72,6 +72,7 @@ class iTunesPlugin(BeetsPlugin):
'search_countries': ['US'], 'search_countries': ['US'],
'lookup_countries': ['US', 'DE', 'AU', 'GB', 'FR', 'IT', 'JP'], 'lookup_countries': ['US', 'DE', 'AU', 'GB', 'FR', 'IT', 'JP'],
'search_limit': 5, '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 '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)' 'method': 'lookup', # Valid values: 'search', 'lookup', 'both', 'lookup (search fallback)'
}) })
@@ -107,6 +108,10 @@ class iTunesPlugin(BeetsPlugin):
def search_limit(self): def search_limit(self):
return self.config['search_limit'].as_number() return self.config['search_limit'].as_number()
@property
def sanitize_searches(self):
return self.config['sanitize_searches']
def scan_track_ids(self, session, task): def scan_track_ids(self, session, task):
self._log.debug("Scanning track IDs") self._log.debug("Scanning track IDs")
for item in task.items: for item in task.items:
@@ -171,11 +176,18 @@ class iTunesPlugin(BeetsPlugin):
"""Searches for matching albums on iTunes. """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: if va_likely:
query = album query = album
else: else:
query = '%s %s' % (artist, album) query = '%s %s' % (artist, album)
print("Searching", query)
albums = [] albums = []
for country in self.search_countries: for country in self.search_countries:
try: try: