Torrents size

This commit is contained in:
Simon Vieille 2015-08-13 22:21:11 +02:00
parent cfb5c3b7b8
commit 59154341ea

View file

@ -153,16 +153,25 @@ Usage: <comment>torrents:search</comment> <info>QUERY</info> [OPTIONS]
return; return;
} }
$output->writeln(' SEED LEECH ID NAME'); $output->writeln(' SEED LEECH SIZE ID NAME');
foreach ($torrents as $torrent) { foreach ($torrents as $torrent) {
$output->writeln(sprintf( $output->writeln(sprintf(
'[<info>%4d</info><comment>%6d</comment>] %9d %s', '[<info>%4d</info><comment>%6d</comment>] [%8s] %7d %s',
$torrent['seeders'], $torrent['seeders'],
$torrent['leechers'], $torrent['leechers'],
$this->formatBytes((int) $torrent['size']),
$torrent['id'], $torrent['id'],
$torrent['name'] $torrent['name']
)); ));
} }
} }
protected function formatBytes($size, $precision = 2)
{
$base = log($size, 1024);
$suffixes = array('', 'k', 'M', 'G', 'T');
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
}
} }