mirror of
https://github.com/beetbox/beets.git
synced 2025-12-31 04:52:49 +01:00
destination now uses album values when available
When computing track destination paths, we now look for album-level values when they're available. This has the effect of making albums go into a single directory even when their tracks have heterogeneous metadata. We will need to revisit this once we start explicitly supporting non-album tracks.
This commit is contained in:
parent
181949d1a3
commit
898b4bd24e
2 changed files with 22 additions and 4 deletions
|
|
@ -805,13 +805,23 @@ class Library(BaseLibrary):
|
|||
item (i.e., where the file ought to be).
|
||||
"""
|
||||
subpath_tmpl = Template(self.path_format)
|
||||
|
||||
# Get the item's Album if it has one.
|
||||
album = self.get_album(item)
|
||||
|
||||
# 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)
|
||||
# sanitize the value for inclusion in a path:
|
||||
# Get the values from either the item or its album.
|
||||
if key in ALBUM_KEYS_ITEM and album is not None:
|
||||
# From album.
|
||||
value = getattr(album, key)
|
||||
else:
|
||||
# From Item.
|
||||
value = getattr(item, key)
|
||||
|
||||
# Sanitize the value for inclusion in a path:
|
||||
# replace / and leading . with _
|
||||
if isinstance(value, basestring):
|
||||
value = value.replace(os.sep, '_')
|
||||
|
|
|
|||
|
|
@ -254,6 +254,14 @@ class DestinationTest(unittest.TestCase):
|
|||
p = self.lib.destination(self.i)
|
||||
self.assert_('(FLAC)' in p)
|
||||
|
||||
def test_heterogeneous_album_gets_single_directory(self):
|
||||
i1, i2 = item(), item()
|
||||
self.lib.add_album([i1, i2])
|
||||
i1.year, i2.year = 2009, 2010
|
||||
self.lib.path_format = '$album ($year)/$track $title'
|
||||
dest1, dest2 = self.lib.destination(i1), self.lib.destination(i2)
|
||||
self.assertEqual(os.path.dirname(dest1), os.path.dirname(dest2))
|
||||
|
||||
class MigrationTest(unittest.TestCase):
|
||||
"""Tests the ability to change the database schema between
|
||||
versions.
|
||||
|
|
|
|||
Loading…
Reference in a new issue