Skip to content

Commit

Permalink
Fixed the queue example
Browse files Browse the repository at this point in the history
  • Loading branch information
kleiram committed Apr 13, 2013
1 parent c708449 commit 4da1e63
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions examples/queue.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,11 @@
<?php
require_once __DIR__.'/../vendor/autoload.php';

function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');

$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);

// Uncomment one of the following alternatives
$bytes /= pow(1024, $pow);
// $bytes /= (1 << (10 * $pow));

return round($bytes, $precision) . ' ' . $units[$pow];
}

// Find all the torrents
$queue = Transmission\Torrent::all();

echo sprintf("Found %d torrents\n", count($queue));

$totalSize = 0;

foreach ($queue as $torrent) {
$size = formatBytes($torrent->getSize(), 2);
echo "#{$torrent->getId()}: {$torrent->getName()} ({$size})\n";

$totalSize += $torrent->getSize();
}

$totalSize = formatBytes($totalSize);
echo "\nTotal queue size: {$totalSize}\n";

foreach ($queue as $torrent) {
$count = count($torrent->getFiles());

echo "{$count} files in {$torrent->getName()}:\n";

foreach ($torrent->getFiles() as $file) {
echo "- {$file->getName()}\n";
}

echo "\n";
}

0 comments on commit 4da1e63

Please sign in to comment.