From 5bb064a8604f09fff08b2bc58eb94fbdc71a3fdb Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 13 Jul 2010 22:00:42 -0700 Subject: [PATCH] configurable album art path construction --- beets/library.py | 15 +++++++++++++-- beets/ui/__init__.py | 6 +++++- test/rsrc/test.blb | Bin 5120 -> 7168 bytes test/test_db.py | 16 +++++++++++++++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/beets/library.py b/beets/library.py index cfbf6b7ad..9448d234c 100644 --- a/beets/library.py +++ b/beets/library.py @@ -703,11 +703,13 @@ class Library(BaseLibrary): def __init__(self, path='library.blb', directory='~/Music', path_format='$artist/$album/$track $title', + art_filename='cover', item_fields=ITEM_FIELDS, album_fields=ALBUM_FIELDS): self.path = path self.directory = directory self.path_format = path_format + self.art_filename = art_filename self.conn = sqlite3.connect(self.path) self.conn.row_factory = sqlite3.Row @@ -786,8 +788,8 @@ class Library(BaseLibrary): libpath = self.directory subpath_tmpl = Template(self.path_format) - # build the mapping for substitution in the path template, beginning - # with the values from the database + # Build the mapping for substitution in the path template, + # beginning with the values from the database. mapping = {} for key in ITEM_KEYS_META: value = getattr(item, key) @@ -814,6 +816,15 @@ class Library(BaseLibrary): return _normpath(os.path.join(libpath, subpath)) + def art_path(self, item, image): + """Returns a path to the destination for the album art image + for the item's album. `image` is the path of the image that + will be moved there (used for its extension). + """ + item_dir = os.path.dirname(self.destination(item)) + _, ext = os.path.splitext(image) + dest = os.path.join(item_dir, self.art_filename + ext) + return dest # Main interface. diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index e504d187f..0f53595d4 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -31,6 +31,7 @@ CONFIG_FILE = os.path.expanduser('~/.beetsconfig') DEFAULT_LIBRARY = '~/.beetsmusic.blb' DEFAULT_DIRECTORY = '~/Music' DEFAULT_PATH_FORMAT = '$artist/$album/$track $title' +DEFAULT_ART_FILENAME = 'cover' # UI exception. Commands should throw this in order to display @@ -369,9 +370,12 @@ def main(): config_val(config, 'beets', 'directory', DEFAULT_DIRECTORY) path_format = options.path_format or \ config_val(config, 'beets', 'path_format', DEFAULT_PATH_FORMAT) + art_filename = \ + config_val(config, 'beets', 'art_filename', DEFAULT_ART_FILENAME) lib = library.Library(os.path.expanduser(libpath), directory, - path_format) + path_format, + art_filename) # Invoke the subcommand. try: diff --git a/test/rsrc/test.blb b/test/rsrc/test.blb index bdbf362bccfd1fca00947db1a85f5dd49d5cadb7..1559b449b130b979af4b5023b2369384de1e1ec8 100644 GIT binary patch delta 764 zcmZqBXt0MjoYHl%ubC9cJh^s>;zkX9~V6^OTp34MIo`M zB(t~#A_!(`A{plytl$^w