diff --git a/beets/library.py b/beets/library.py index 7e1bccd73..e19c4682f 100644 --- a/beets/library.py +++ b/beets/library.py @@ -104,7 +104,7 @@ ITEM_FIELDS = [ ('bitdepth', 'int', False, True), ('channels', 'int', False, True), ('mtime', 'int', False, False), - ('itime', 'datetime', False, False), + ('added', 'datetime', False, False), ] ITEM_KEYS_WRITABLE = [f[0] for f in ITEM_FIELDS if f[3] and f[2]] ITEM_KEYS_META = [f[0] for f in ITEM_FIELDS if f[3]] @@ -116,7 +116,7 @@ ITEM_KEYS = [f[0] for f in ITEM_FIELDS] ALBUM_FIELDS = [ ('id', 'integer primary key', False), ('artpath', 'blob', False), - ('itime', 'datetime', True), + ('added', 'datetime', True), ('albumartist', 'text', True), ('albumartist_sort', 'text', True), @@ -203,7 +203,7 @@ def format_for_path(value, key=None, pathmod=None): elif key == 'samplerate': # Sample rate formatted as kHz. value = u'%ikHz' % ((value or 0) // 1000) - elif key in ('itime', 'mtime'): + elif key in ('added', 'mtime'): # Times are formatted to be human-readable. value = time.strftime(beets.config['time_format'].get(unicode), time.localtime(value)) @@ -1295,7 +1295,7 @@ class Library(BaseLibrary): # Item manipulation. def add(self, item, copy=False): - item.itime = time.time() + item.added = time.time() if copy: self.move(item, copy=True) @@ -1510,7 +1510,7 @@ class Library(BaseLibrary): # When adding an album and its items for the first time, the # items do not yet have a timestamp. - album_values['itime'] = time.time() + album_values['added'] = time.time() with self.transaction() as tx: sql = 'INSERT INTO albums (%s) VALUES (%s)' % \ @@ -1826,8 +1826,8 @@ class DefaultTemplateFunctions(object): return unidecode(s) @staticmethod - def tmpl_format(s, format): - """Format the import time to any format according to time.strfime() + def tmpl_time(s, format): + """Format a time value using `strftime`. """ cur_fmt = beets.config['time_format'].get(unicode) return time.strftime(format, time.strptime(s, cur_fmt)) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 6a2669f49..8954b1c7c 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -1014,7 +1014,10 @@ def _convert_type(key, value, album=False): def modify_items(lib, mods, query, write, move, album, confirm): """Modifies matching items according to key=value assignments.""" # Parse key=value specifications into a dictionary. - allowed_keys = library.ALBUM_KEYS if album else library.ITEM_KEYS_WRITABLE + ['itime'] + if album: + allowed_keys = library.ALBUM_KEYS + else: + allowed_keys = library.ITEM_KEYS_WRITABLE + ['added'] fsets = {} for mod in mods: key, value = mod.split('=', 1) diff --git a/test/rsrc/test.blb b/test/rsrc/test.blb index bd92dd6fd..22c621da5 100644 Binary files a/test/rsrc/test.blb and b/test/rsrc/test.blb differ diff --git a/test/test_db.py b/test/test_db.py index 76d99087c..042877bce 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -365,7 +365,7 @@ class DestinationTest(unittest.TestCase): self.assertEqual(val, u'12kHz') def test_component_sanitize_datetime(self): - val = beets.library.format_for_path(1368302461.210265, 'itime', + val = beets.library.format_for_path(1368302461.210265, 'added', posixpath) self.assertTrue(val.startswith('2013')) @@ -985,16 +985,16 @@ class ImportTimeTest(_common.TestCase): super(ImportTimeTest, self).setUp() self.lib = beets.library.Library(':memory:') - def test_itime_for_album(self): + def added(self): self.track = item() self.album = self.lib.add_album((self.track,)) - self.assertGreater(self.album.itime, 0) - self.assertGreater(self.track.itime, 0) + self.assertGreater(self.album.added, 0) + self.assertGreater(self.track.added, 0) def test_atime_for_singleton(self): self.singleton = item() self.lib.add(self.singleton) - self.assertGreater(self.singleton.itime, 0) + self.assertGreater(self.singleton.added, 0) def suite(): return unittest.TestLoader().loadTestsFromName(__name__)