mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
Formatting and style refinements for #900
This commit is contained in:
parent
44e0dee16d
commit
0ec285f96c
3 changed files with 31 additions and 31 deletions
|
|
@ -989,29 +989,3 @@ def main(args=None):
|
|||
except KeyboardInterrupt:
|
||||
# Silently ignore ^C except in verbose mode.
|
||||
log.debug(traceback.format_exc())
|
||||
|
||||
|
||||
|
||||
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}kbps average bitrate. '.format(bitrate=int(average_bitrate/1000))
|
||||
summary_text += '{length} total length. '.format(length=human_seconds_short(total_duration))
|
||||
|
||||
return summary_text
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -424,6 +424,32 @@ def show_item_change(item, match):
|
|||
print_(' '.join(info))
|
||||
|
||||
|
||||
def summarize_items(items):
|
||||
"""Produces a brief summary line describing a set of items. Used for
|
||||
manually resolving duplicates during import.
|
||||
"""
|
||||
summary_parts = []
|
||||
summary_parts.append("{0} items".format(len(items)))
|
||||
|
||||
format_counts = {}
|
||||
for item in items:
|
||||
format_counts[item.format] = format_counts.get(item.format, 0) + 1
|
||||
if len(format_counts) == 1:
|
||||
# A single format.
|
||||
summary_parts.append(items[0].format)
|
||||
else:
|
||||
# Enumerate all the formats.
|
||||
for format, count in format_counts.iteritems():
|
||||
summary_parts.append('{0} {1}'.format(format, count))
|
||||
|
||||
average_bitrate = sum([item.bitrate for item in items]) / len(items)
|
||||
total_duration = sum([item.length for item in items])
|
||||
summary_parts.append('{0}kbps'.format(int(average_bitrate / 1000)))
|
||||
summary_parts.append(ui.human_seconds_short(total_duration))
|
||||
|
||||
return ', '.join(summary_parts)
|
||||
|
||||
|
||||
def _summary_judment(rec):
|
||||
"""Determines whether a decision should be made without even asking
|
||||
the user. This occurs in quiet mode and when an action is chosen for
|
||||
|
|
@ -753,12 +779,11 @@ class TerminalImportSession(importer.ImportSession):
|
|||
log.info('Skipping.')
|
||||
sel = 's'
|
||||
else:
|
||||
# print some detail about the existing and new items so it can be an informed decision
|
||||
# Print some detail about the existing and new items so the
|
||||
# user can make an informed decision.
|
||||
for duplicate in found_duplicates:
|
||||
old_items = [(item.path, item.format, item.bitrate, item.length) for item in duplicate.items()]
|
||||
print("OLD: " + ui.summarize_items(old_items))
|
||||
new_items = [(item.path, item.format, item.bitrate, item.length) for item in task.items]
|
||||
print("NEW: " + ui.summarize_items(new_items))
|
||||
print("Old: " + summarize_items(list(duplicate.items())))
|
||||
print("New: " + summarize_items(task.items))
|
||||
|
||||
sel = ui.input_options(
|
||||
('Skip new', 'Keep both', 'Remove old')
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import traceback
|
|||
import subprocess
|
||||
import platform
|
||||
|
||||
|
||||
MAX_FILENAME_LENGTH = 200
|
||||
WINDOWS_MAGIC_PREFIX = u'\\\\?\\'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue