diff --git a/NEWS b/NEWS index c4e698842..42f227635 100644 --- a/NEWS +++ b/NEWS @@ -28,7 +28,11 @@ refactored to keep track of some information at an album (rather than item) granularity. Databases created with earlier versions of beets should work fine, but they won't have any "albums" in them--they'll - just be a bag of items. + just be a bag of items. One way to "upgrade" your database so it + contains albums is to remove your old database file and use + "beet import -A" to import without autotagging. This will use the + existing tags on the files but use their location in the directory + tree to cluster items into albums. * Fixed some bugs with encoding paths on Windows. Also, :s are now replaced with -s in path names (instead of _s) for readability. diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 3c855d51d..8b5fa4d29 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -247,62 +247,36 @@ def import_files(lib, paths, copy=True, write=True, autot=True, albums will be logged there. If art, then attempt to download cover art for each album. """ + # Open the log. if logpath: logfile = open(logpath, 'w') else: logfile = None - if autot: - # Make sure we have only directories. - for path in paths: - if not os.path.isdir(path): - raise ui.UserError('not a directory: ' + path) - - # Crawl albums and tag them. - first = True - for path in paths: - for album in autotag.albums_in_dir(os.path.expanduser(path)): + # Make sure we have only directories. + for path in paths: + if not os.path.isdir(path): + raise ui.UserError('not a directory: ' + path) + + # Crawl albums and (optionally) tag them. + first = True + for path in paths: + for items in autotag.albums_in_dir(os.path.expanduser(path)): + if autot: + # Infer tags. if not first: print_() first = False - - # Infer tags. - tag_album(album, lib, copy, write, logfile, art) - - # Write the database after each album. - lib.save() - - else: - # No autotagging. Just walk the paths. - for path in paths: - if os.path.isdir(path): - # Find all files in the directory. - filepaths = [] - for root, dirs, files in autotag._sorted_walk(path): - for filename in files: - filepaths.append(os.path.join(root, filename)) + tag_album(items, lib, copy, write, logfile, art) else: - # Just add the file. - filepaths = [path] - - # Add all the files. - for filepath in filepaths: - try: - item = library.Item.from_path(filepath) - except FileTypeError: - continue - except UnreadableFileError: - log.warn('unreadable file: ' + filepath) - continue - - # Add the item to the library, copying if requested. + # No autotagging. Just add the album. if copy: - item.move(lib, True) - # Don't write tags because nothing changed. - lib.add(item) - - # Save when completely finished. - lib.save() + for item in items: + item.move(lib, True) + lib.add_album(items) + + # Write the database after each album. + lib.save() # If we were logging, close the file. if logfile: