diff --git a/src/Console/Command/TorrentsSearchCommand.php b/src/Console/Command/TorrentsSearchCommand.php index 2b17c79..bed6358 100644 --- a/src/Console/Command/TorrentsSearchCommand.php +++ b/src/Console/Command/TorrentsSearchCommand.php @@ -153,16 +153,25 @@ Usage: torrents:search QUERY [OPTIONS] return; } - $output->writeln(' SEED LEECH ID NAME'); + $output->writeln(' SEED LEECH SIZE ID NAME'); foreach ($torrents as $torrent) { $output->writeln(sprintf( - '[%4d%6d] %9d %s', + '[%4d%6d] [%8s] %7d %s', $torrent['seeders'], $torrent['leechers'], + $this->formatBytes((int) $torrent['size']), $torrent['id'], $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)]; + } }