mirror of
https://github.com/beetbox/beets.git
synced 2025-12-25 10:05:13 +01:00
Moved summarize_items to utils. Cleaned up output
Output now uses K for bitrate. summarize function now in util
This commit is contained in:
parent
4bf07aa8a6
commit
a15cf2b001
2 changed files with 29 additions and 20 deletions
|
|
@ -741,23 +741,6 @@ class TerminalImportSession(importer.ImportSession):
|
|||
assert isinstance(choice, autotag.TrackMatch)
|
||||
return choice
|
||||
|
||||
def summarize_items(self,items):
|
||||
summary_text = ""
|
||||
summary_text += "%d items. " % len(items)
|
||||
format_counts = {}
|
||||
for item in items:
|
||||
format_counts[item[1]] = format_counts.get(item[1],0) + 1;
|
||||
|
||||
for format, count in format_counts.iteritems():
|
||||
summary_text += '{count} {format}. '.format(format=format, count=count)
|
||||
|
||||
average_bitrate = sum([item[2] for item in items]) / len(items)
|
||||
total_duration = sum([item[3] for item in items])
|
||||
summary_text += '{bitrate} average bitrate. '.format(bitrate=average_bitrate)
|
||||
summary_text += '{length}s total length. '.format(length=int(total_duration))
|
||||
|
||||
return summary_text
|
||||
|
||||
def resolve_duplicate(self, task):
|
||||
"""Decide what to do when a new album or item seems similar to one
|
||||
that's already in the library.
|
||||
|
|
@ -771,12 +754,11 @@ class TerminalImportSession(importer.ImportSession):
|
|||
sel = 's'
|
||||
else:
|
||||
# print some detail about the existing and new items so it can be an informed decision
|
||||
|
||||
for duplicate in task.found_duplicates:
|
||||
old_items = [(item.path, item.format, item.bitrate, item.length) for item in duplicate.items()]
|
||||
print("OLD: " + self.summarize_items(old_items))
|
||||
print("OLD: " + util.summarize_items(old_items))
|
||||
new_items = [(item.path, item.format, item.bitrate, item.length) for item in task.items]
|
||||
print("NEW: " + self.summarize_items(new_items))
|
||||
print("NEW: " + util.summarize_items(new_items))
|
||||
|
||||
sel = ui.input_options(
|
||||
('Skip new', 'Keep both', 'Remove old')
|
||||
|
|
|
|||
|
|
@ -658,3 +658,30 @@ def max_filename_length(path, limit=MAX_FILENAME_LENGTH):
|
|||
return min(res[9], limit)
|
||||
else:
|
||||
return limit
|
||||
|
||||
def summarize_items(items):
|
||||
"""Produces a brief summary line for manually resolving duplicates during import.
|
||||
Accepts a list of tuples, one per item containing:
|
||||
(path, format, bitrate, duration)
|
||||
"""
|
||||
|
||||
summary_text = ""
|
||||
summary_text += "%d items. " % len(items)
|
||||
format_counts = {}
|
||||
for item in items:
|
||||
format_counts[item[1]] = format_counts.get(item[1],0) + 1;
|
||||
|
||||
for format, count in format_counts.iteritems():
|
||||
summary_text += '{count} {format}. '.format(format=format, count=count)
|
||||
|
||||
average_bitrate = sum([item[2] for item in items]) / len(items)
|
||||
total_duration = sum([item[3] for item in items])
|
||||
summary_text += '{bitrate}K average bitrate. '.format(bitrate=int(average_bitrate/1000))
|
||||
summary_text += '{length}s total length. '.format(length=int(total_duration))
|
||||
|
||||
return summary_text
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue