def show_stats(lib, query): """Shows some statistics about the matched items.""" items = lib.items(query) total_size = 0 total_time = 0.0 total_items = 0 artists = set() albums = set() for item in items: #fixme This is approximate, so people might complain that # this total size doesn't match "du -sh". Could fix this # by putting total file size in the database. total_size += int(item.length * item.bitrate / 8) total_time += item.length total_items += 1 artists.add(item.artist) albums.add(item.album) print_("""Tracks: %i Total time: %s Total size: %s Artists: %i Albums: %i""" % (total_items, ui.human_seconds(total_time), ui.human_bytes(total_size), len(artists), len(albums)))
def show_stats(lib, query): """Shows some statistics about the matched items.""" items = lib.items(query) total_size = 0 total_time = 0.0 total_items = 0 artists = set() albums = set() for item in items: #fixme This is approximate, so people might complain that # this total size doesn't match "du -sh". Could fix this # by putting total file size in the database. total_size += int(item.length * item.bitrate / 8) total_time += item.length total_items += 1 artists.add(item.artist) albums.add(item.album) print_("""Tracks: %i Total time: %s Total size: %s Artists: %i Albums: %i""" % ( total_items, ui.human_seconds(total_time), ui.human_bytes(total_size), len(artists), len(albums) ))
def show_stats(lib, query, exact): """Shows some statistics about the matched items.""" items = lib.items(query) total_size = 0 total_time = 0.0 total_items = 0 artists = set() albums = set() for item in items: if exact: total_size += os.path.getsize(item.path) else: total_size += int(item.length * item.bitrate / 8) total_time += item.length total_items += 1 artists.add(item.artist) albums.add(item.album) size_str = '' + ui.human_bytes(total_size) if exact: size_str += ' ({0} bytes)'.format(total_size) print_("""Tracks: {0} Total time: {1} ({2:.2f} seconds) Total size: {3} Artists: {4} Albums: {5}""".format(total_items, ui.human_seconds(total_time), total_time, size_str, len(artists), len(albums)))
def update_stats(self): items = self.library.items() total_size = 0 total_time = 0.0 total_items = 0 artists = set() albums = set() album_artists = set() for item in items: total_size += int(item.length * item.bitrate / 8) total_time += item.length total_items += 1 artists.add(item.artist) album_artists.add(item.albumartist) if item.album_id: albums.add(item.album_id) size_str = human_bytes(total_size) time_str = human_seconds(total_time) self.stats["count"] = total_items self.stats["time"] = time_str self.stats["size"] = size_str self.stats["artists"] = len(artists) self.stats["albums"] = len(albums) self.stats["album_artists"] = len(album_artists)
def test_human_bytes(self): tests = [ (0, '0.0 B'), (30, '30.0 B'), (pow(2, 10), '1.0 KiB'), (pow(2, 20), '1.0 MiB'), (pow(2, 30), '1.0 GiB'), (pow(2, 40), '1.0 TiB'), (pow(2, 50), '1.0 PiB'), (pow(2, 60), '1.0 EiB'), (pow(2, 70), '1.0 ZiB'), (pow(2, 80), '1.0 YiB'), (pow(2, 90), '1.0 HiB'), (pow(2, 100), 'big'), ] for i, h in tests: self.assertEqual(h, ui.human_bytes(i))