From d9e213867cd36c25970269cd91de3f18a6b416da Mon Sep 17 00:00:00 2001 From: Fabrice Laporte Date: Mon, 22 Apr 2013 23:44:35 +0200 Subject: [PATCH] fetchart (issue 459): use regex to detect valid image names + 'cautious' option for finer control of filename matching --- beetsplug/fetchart.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 886a59250..751663063 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -124,16 +124,19 @@ def art_in_path(path): images.append(fn) # Look for "preferred" filenames. + pattern = r"^(.*[^0-9a-z])?(%s)([^0-9a-z].*)?$" % \ + '|'.join(COVER_NAMES) + r=re.compile(pattern,re.I) for fn in images: - for name in COVER_NAMES: - if fn.lower().startswith(name): - log.debug(u'fetchart: using well-named art file {0}'.format( - util.displayable_path(fn) - )) - return os.path.join(path, fn) + if re.match(r, os.path.splitext(fn)[0]): + log.debug(u'fetchart: using well-named art file {0}'.format( + util.displayable_path(fn) + )) + return os.path.join(path, fn) # Fall back to any image in the folder. - if images: + cautious = config['fetchart']['cautious'].get(bool) + if not cautious and images: log.debug(u'fetchart: using fallback art file {0}'.format( util.displayable_path(images[0]) )) @@ -221,6 +224,7 @@ class FetchArtPlugin(BeetsPlugin): 'auto': True, 'maxwidth': 0, 'remote_priority': False, + 'cautious': True }) # Holds paths to downloaded images between fetching them and