diff --git a/src/Console/Command/TorrentsSearchCommand.php b/src/Console/Command/TorrentsSearchCommand.php
index 9baafdb..07b0110 100644
--- a/src/Console/Command/TorrentsSearchCommand.php
+++ b/src/Console/Command/TorrentsSearchCommand.php
@@ -12,6 +12,7 @@ use Api\ConfigLoader;
use Api\ClientResponse;
use Api\ClientException;
use Helper\Formater;
+use Helper\Render;
class TorrentsSearchCommand extends Command
{
@@ -84,8 +85,18 @@ Usage: torrents:search QUERY [OPTIONS]
}
$response = $this->searchTorrents($client, $input, $termsTree);
+
+ if ($response->hasError()) {
+ $output->writeln(sprintf(
+ '%s (%d)',
+ $response->getErrorMessage(),
+ $response->getErrorCode()
+ ));
- $this->showResults($response, $output);
+ return;
+ }
+
+ Render::torrents($response->getData()['torrents'], $output);
} catch (ClientException $e) {
$output->writeln(sprintf('An error occured. %s', $e->getMessage()));
}
diff --git a/src/Console/Command/TorrentsTopCommand.php b/src/Console/Command/TorrentsTopCommand.php
index 7123d82..0d8770b 100644
--- a/src/Console/Command/TorrentsTopCommand.php
+++ b/src/Console/Command/TorrentsTopCommand.php
@@ -10,6 +10,7 @@ use Api\Client;
use Api\ConfigLoader;
use Api\ClientResponse;
use Api\ClientException;
+use Helper\Render;
class TorrentsTopCommand extends Command
{
@@ -49,35 +50,20 @@ Usage: torrents:search:top [OPTIONS]
}
$response = $client->getTopTorrents($period);
+
+ if ($response->hasError()) {
+ $output->writeln(sprintf(
+ '%s (%d)',
+ $response->getErrorMessage(),
+ $response->getErrorCode()
+ ));
- return $this->showResults($response, $output);
+ return;
+ }
+
+ Render::torrents($response->getData(), $output);
} catch (ClientException $e) {
$output->writeln(sprintf('An error occured. %s', $e->getMessage()));
}
}
-
- protected function showResults(ClientResponse $response, OutputInterface $output)
- {
- if ($response->hasError()) {
- $output->writeln(sprintf(
- '%s (%d)',
- $response->getErrorMessage(),
- $response->getErrorCode()
- ));
-
- return;
- }
-
- $output->writeln(' SEED LEECH ID NAME');
-
- foreach ($response->getData() as $torrent) {
- $output->writeln(sprintf(
- '[%4d%6d] %9d %s',
- $torrent['seeders'],
- $torrent['leechers'],
- $torrent['id'],
- $torrent['name']
- ));
- }
- }
}
diff --git a/src/Helper/Render.php b/src/Helper/Render.php
new file mode 100644
index 0000000..3387c7e
--- /dev/null
+++ b/src/Helper/Render.php
@@ -0,0 +1,34 @@
+
+ */
+class Render
+{
+ public static function torrents(array $torrents, OutputInterface $output)
+ {
+ if (empty($torrents)) {
+ return;
+ }
+
+ $output->writeln(' SEED LEECH SIZE ID NAME');
+
+ foreach ($torrents as $torrent) {
+ $output->writeln(sprintf(
+ '[%4d%6d] [%8s] %7d %s',
+ $torrent['seeders'],
+ $torrent['leechers'],
+ Formater::humanSize((int) $torrent['size']),
+ $torrent['id'],
+ $torrent['name']
+ ));
+ }
+ }
+}
+