import -A now tags albums

Previously, importing without autotagging just imported a bunch of Items. Now,
like the autotagging version, "import -A" creates albums based on the directory
hierarchy. The effect is exactly as if the user chose "use as-is" every time in
the interactive procedure. One side effect is that "import -A" can now only take
directories, where previously it could take single items on the command line. We
need a new solution for this kind of import in the future.
This commit is contained in:
Adrian Sampson 2010-07-15 13:58:16 -07:00
parent e9e90fa538
commit 602f896bd1
2 changed files with 25 additions and 47 deletions

6
NEWS
View file

@ -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.

View file

@ -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: