def summarize_items(items, singleton):
 summary_parts = []
 if (not singleton):
  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):
  summary_parts.append(items[0].format)
 else:
  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 summarize_items ( items , singleton ) : summary_parts = [ ] if ( not singleton ) : 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 ) : summary_parts . append ( items [ 0 ] . format ) else : 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 )
produces a brief summary line describing a set of items .