From 2dc15a0e2b067f7f02aa5a8f1957075a2b5d6d0d Mon Sep 17 00:00:00 2001 From: Fabrice Laporte Date: Sat, 27 Apr 2013 12:21:57 +0200 Subject: [PATCH] Use re.search instead of re.match with simplified regex. Add additional cover_names parameter to art_in_path, and makes 'cover_names' a plugin config option. --- beetsplug/fetchart.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 751663063..14a91d451 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -110,8 +110,7 @@ def aao_art(asin): # Art from the filesystem. - -def art_in_path(path): +def art_in_path(path, cover_names=COVER_NAMES): """Look for album art files in a specified directory.""" if not os.path.isdir(path): return @@ -124,11 +123,9 @@ 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) + cover_pat = r"(\b|_)(%s)(\b|_)" % '|'.join(cover_names) for fn in images: - if re.match(r, os.path.splitext(fn)[0]): + if re.search(cover_pat, os.path.splitext(fn)[0], re.I): log.debug(u'fetchart: using well-named art file {0}'.format( util.displayable_path(fn) )) @@ -175,9 +172,10 @@ def art_for_album(album, paths, maxwidth=None, local_only=False): out = None # Local art. + cover_names = config['fetchart']['cover_names'].as_str_seq() if paths: for path in paths: - out = art_in_path(path) + out = art_in_path(path, cover_names) if out: break @@ -224,7 +222,8 @@ class FetchArtPlugin(BeetsPlugin): 'auto': True, 'maxwidth': 0, 'remote_priority': False, - 'cautious': True + 'cautious': True, + 'cover_names': COVER_NAMES }) # Holds paths to downloaded images between fetching them and