From 749b55b782ca2a9d76be72f0201cc6cc734169cb Mon Sep 17 00:00:00 2001 From: "adrian.sampson" Date: Thu, 28 May 2009 20:29:59 +0000 Subject: [PATCH] made track ordering function --HG-- extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%40226 --- beets/autotag/__init__.py | 43 +++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index f0925be0b..623a7b986 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -75,6 +75,31 @@ def _input_yn(prompt): return False resp = raw_input("Type 'y' or 'n': ") +def order_items(items): + # First, see if the current tags indicate an ordering. + ordered_items = [None]*len(items) + available_indices = set(range(len(items))) + for item in items: + if item.track: + index = item.track - 1 + ordered_items[index] = item + if index in available_indices: + available_indices.remove(index) + else: + # Same index used twice. + return None + else: + # If we have any item without an index, give up. + return None + if available_indices: + # Not all indices were used. + return None + + #fixme: Otherwise, match based on names and lengths of tracks + # (confirm). + + return ordered_items + def tag_album_dir(path, lib): # Read items from directory. items = [] @@ -119,22 +144,10 @@ def tag_album_dir(path, lib): return # Determine order of existing tracks. - # First, see if the current tags indicate an ordering. - ordered_items = [None]*len(items) - available_indices = set(range(len(items))) - for item in items: - if item.track: - index = item.track - 1 - ordered_items[index] = item - available_indices.remove(index) - else: - # If we have any item without an index, give up. - break - if available_indices: - print "Tracks are not correctly ordered." + ordered_items = order_items(items) + if not ordered_items: + print "Tracks could not be ordered." return - #fixme: - # Otherwise, match based on names and lengths of tracks (confirm). # Apply new metadata. for index, (item, track_data) in enumerate(zip(ordered_items,