From 096816cba725dca9a25168f6aef79bb42afc874e Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 22 Mar 2011 20:09:27 -0700 Subject: [PATCH] path formats can now be specified by album type --- beets/library.py | 50 +++++++++++++++++++++++++----------------------- test/test_db.py | 18 +++++++++++++++++ 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/beets/library.py b/beets/library.py index 5afaf9b70..6a94b604b 100644 --- a/beets/library.py +++ b/beets/library.py @@ -38,29 +38,29 @@ ITEM_FIELDS = [ ('path', 'blob', False, False), ('album_id', 'int', False, False), - ('title', 'text', True, True), - ('artist', 'text', True, True), - ('album', 'text', True, True), - ('albumartist', 'text', True, True), - ('genre', 'text', True, True), - ('composer', 'text', True, True), - ('grouping', 'text', True, True), - ('year', 'int', True, True), - ('month', 'int', True, True), - ('day', 'int', True, True), - ('track', 'int', True, True), - ('tracktotal', 'int', True, True), - ('disc', 'int', True, True), - ('disctotal', 'int', True, True), - ('lyrics', 'text', True, True), - ('comments', 'text', True, True), - ('bpm', 'int', True, True), - ('comp', 'bool', True, True), - ('mb_trackid', 'text', True, True), - ('mb_albumid', 'text', True, True), - ('mb_artistid', 'text', True, True), - ('mb_albumartistid', 'text', True, True), - ('albumtype', 'text', True, True), + ('title', 'text', True, True), + ('artist', 'text', True, True), + ('album', 'text', True, True), + ('albumartist', 'text', True, True), + ('genre', 'text', True, True), + ('composer', 'text', True, True), + ('grouping', 'text', True, True), + ('year', 'int', True, True), + ('month', 'int', True, True), + ('day', 'int', True, True), + ('track', 'int', True, True), + ('tracktotal', 'int', True, True), + ('disc', 'int', True, True), + ('disctotal', 'int', True, True), + ('lyrics', 'text', True, True), + ('comments', 'text', True, True), + ('bpm', 'int', True, True), + ('comp', 'bool', True, True), + ('mb_trackid', 'text', True, True), + ('mb_albumid', 'text', True, True), + ('mb_artistid', 'text', True, True), + ('mb_albumartistid', 'text', True, True), + ('albumtype', 'text', True, True), ('length', 'real', False, True), ('bitrate', 'int', False, True), @@ -878,7 +878,9 @@ class Library(BaseLibrary): pathmod = pathmod or os.path # Use a path format based on the album type, if available. - if item.comp and 'comp' in self.path_formats: + if item.albumtype and item.albumtype in self.path_formats: + path_format = self.path_formats[item.albumtype] + elif item.comp and 'comp' in self.path_formats: path_format = self.path_formats['comp'] else: path_format = self.path_formats['default'] diff --git a/test/test_db.py b/test/test_db.py index 1afd67e0a..95db813fb 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -288,6 +288,24 @@ class DestinationTest(unittest.TestCase): 'comp': 'three'} self.assertEqual(self.lib.destination(self.i), np('one/three')) + def test_albumtype_path(self): + self.i.comp = True + self.i.albumtype = 'sometype' + self.lib.directory = 'one' + self.lib.path_formats = {'default': 'two', + 'comp': 'three', + 'sometype': 'four'} + self.assertEqual(self.lib.destination(self.i), np('one/four')) + + def test_albumtype_path_fallback_to_comp(self): + self.i.comp = True + self.i.albumtype = 'sometype' + self.lib.directory = 'one' + self.lib.path_formats = {'default': 'two', + 'comp': 'three', + 'anothertype': 'four'} + self.assertEqual(self.lib.destination(self.i), np('one/three')) + def test_syspath_windows_format(self): path = ntpath.join('a', 'b', 'c') outpath = beets.library._syspath(path, ntpath)