diff --git a/beets/library.py b/beets/library.py index e0a0aa840..9e8332931 100644 --- a/beets/library.py +++ b/beets/library.py @@ -45,9 +45,9 @@ from datetime import datetime # - Is the field writable? # - Does the field reflect an attribute of a MediaFile? ITEM_FIELDS = [ - ('id', int, False, False), - ('path', str, False, False), - ('album_id', int, False, False), + ('id', int, False, False), + ('path', bytes, False, False), + ('album_id', int, False, False), ('title', unicode, True, True), ('artist', unicode, True, True), @@ -116,7 +116,7 @@ ITEM_KEYS = [f[0] for f in ITEM_FIELDS] # identically-named field in the items table. ALBUM_FIELDS = [ ('id', int, False), - ('artpath', str, False), + ('artpath', bytes, False), ('added', datetime, True), ('albumartist', unicode, True), @@ -157,7 +157,7 @@ SQLITE_TYPES = { int: 'INT', float: 'REAL', datetime: 'FLOAT', - str: 'BLOB', + bytes: 'BLOB', unicode: 'TEXT', bool: 'INT', } diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 2983358fa..6789045f1 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -381,8 +381,8 @@ def _colordiff(a, b, highlight='red'): else: return colorize(highlight, a), colorize(highlight, b) - if not isinstance(a, unicode) or not isinstance(b, unicode): - # This is probably a path + if isinstance(a, bytes) or isinstance(b, bytes): + # A path field. a = util.displayable_path(a) b = util.displayable_path(b) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 39f353421..78306205b 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -1089,6 +1089,8 @@ def _convert_type(key, value, album=False): return time.mktime(time.strptime(value, fmt)) except ValueError: raise ui.UserError(u'{0} must have format {1}'.format(key, fmt)) + elif typ is bytes: # A path. + return util.bytestring_path(value) else: try: return typ(value) @@ -1107,9 +1109,6 @@ def modify_items(lib, mods, query, write, move, album, confirm): key, value = mod.split('=', 1) if key not in allowed_keys: raise ui.UserError('"%s" is not a valid field' % key) - - if key == 'artpath': - value = util.bytestring_path(value) fsets[key] = _convert_type(key, value, album) # Get the items to modify. diff --git a/docs/changelog.rst b/docs/changelog.rst index 1306e814e..8b17e247b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -38,6 +38,8 @@ Changelog * Album art filenames now respect the :ref:`replace` configuration. * Friendly error messages are now printed when trying to read or write files that go missing. +* The :ref:`modify-cmd` command can now change albums' album art paths (i.e., + ``beet modify artpath=...`` works). * Various UI enhancements to the importer due to Tai Lee: * More consistent format and colorization of album and track metadata.