Merge pull request #69 from jizz/master

Fix for Issue 450: Expand templates in art_filename config option
This commit is contained in:
Adrian Sampson 2012-12-05 08:54:42 -08:00
commit c50289d34d
2 changed files with 26 additions and 5 deletions

View file

@ -1002,7 +1002,7 @@ class Library(BaseLibrary):
self.path = bytestring_path(normpath(path))
self.directory = bytestring_path(normpath(directory))
self.path_formats = path_formats
self.art_filename = bytestring_path(art_filename)
self.art_filename = art_filename
self.replacements = replacements
self._memotable = {} # Used for template substitution performance.
@ -1562,11 +1562,19 @@ class Album(BaseAlbum):
items, so the album must contain at least one item or
item_dir must be provided.
"""
image = bytestring_path(image)
item_dir = item_dir or self.item_dir()
if not isinstance(self._library.art_filename,Template):
self._library.art_filename = Template(self._library.art_filename)
sanitized_art_filename = util.sanitize_for_path(self.evaluate_template(self._library.art_filename),os.path)
_, ext = os.path.splitext(image)
dest = os.path.join(item_dir, self._library.art_filename + ext)
return dest
dest = os.path.join(item_dir, util.sanitize_path(sanitized_art_filename) + ext)
return bytestring_path(dest)
def set_art(self, path, copy=True):
"""Sets the album's cover art to the image at the given path.

View file

@ -516,6 +516,20 @@ def _get_path_formats(config):
return path_formats
def _get_art_filename(config):
"""Returns a string of album art format; reflecting
the config's specified album art filename.
"""
legacy_art_filename = config_val(config, 'beets', 'art_filename', None)
if legacy_art_filename:
# Old art filename format override the default value.
art_filename = Template(legacy_art_filename)
else:
# If no legacy art filename format, use the default instead.
art_filename = DEFAULT_ART_FILENAME
return art_filename
def _pick_format(config=None, album=False, fmt=None):
"""Pick a format string for printing Album or Item objects,
falling back to config options and defaults.
@ -771,8 +785,7 @@ def _raw_main(args, configfh):
directory = options.directory or \
config_val(config, 'beets', 'directory', default_dir)
path_formats = _get_path_formats(config)
art_filename = \
config_val(config, 'beets', 'art_filename', DEFAULT_ART_FILENAME)
art_filename = _get_art_filename(config)
lib_timeout = config_val(config, 'beets', 'timeout', DEFAULT_TIMEOUT)
replacements = _get_replacements(config)
try: