From cdeaeb9760d1289280781cb8e85dcd244fd85698 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 8 Nov 2009 21:02:44 -0800 Subject: [PATCH] catch a few tagging failure modes --- beets/autotag/__init__.py | 11 +++++++++-- bts | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 91b033b13..01a700ef0 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -31,6 +31,8 @@ from beets import library, mediafile LENGTH_TOLERANCE = 30 class AutotagError(Exception): pass +class InsufficientMetadataError(AutotagError): pass +class UnknownAlbumError(AutotagError): pass class UnorderedTracksError(AutotagError): pass def albums_in_dir(path, lib=None): @@ -244,13 +246,18 @@ def tag_album(items): - The current metadata: an (artist, album) tuple. - The inferred metadata dictionary. - The distance between the current and new metadata. - May raise an UnorderedTracksError if existing metadata is - insufficient. + May raise an AutotagError if existing metadata is insufficient. """ # Get current and candidate metadata. cur_artist, cur_album = current_metadata(items) + if not cur_artist or not cur_album: + raise InsufficientMetadataError() info = mb.match_album(cur_artist, cur_album, len(items)) + # Make sure the album has the correct number of tracks. + if len(items) != len(info['tracks']): + raise UnknownAlbumError() + # Put items in order. #fixme need to try ordering tracks for every candidate album items = order_items(items, info['tracks']) diff --git a/bts b/bts index a9e931490..a467bbceb 100755 --- a/bts +++ b/bts @@ -59,8 +59,8 @@ def tag_album(items, lib): # Infer tags. try: items, (cur_artist, cur_album), info, dist = autotag.tag_album(items) - except autotag.UnorderedTracksError: - print "Tracks could not be ordered." + except autotag.AutotagError: + print "Untaggable album:", os.path.dirname(items[0].path) return # Show what we're about to do.