top torrents command
This commit is contained in:
parent
2b05131589
commit
2d8f3b4e79
|
@ -75,6 +75,11 @@ class Client
|
||||||
return $this->get(true, '/torrents/details/'.$id);
|
return $this->get(true, '/torrents/details/'.$id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTopTorrents($period)
|
||||||
|
{
|
||||||
|
return $this->get(true, '/torrents/top/'.$period);
|
||||||
|
}
|
||||||
|
|
||||||
public function get($needAuthorization, $uri, array $options = array())
|
public function get($needAuthorization, $uri, array $options = array())
|
||||||
{
|
{
|
||||||
return $this->send($needAuthorization, 'get', $uri, $options);
|
return $this->send($needAuthorization, 'get', $uri, $options);
|
||||||
|
|
|
@ -40,5 +40,4 @@ class Application extends BaseApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
76
src/Console/Command/TorrentsTopCommand.php
Normal file
76
src/Console/Command/TorrentsTopCommand.php
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Console\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Api\Client;
|
||||||
|
use Api\ConfigLoader;
|
||||||
|
use Api\ClientResponse;
|
||||||
|
|
||||||
|
class TorrentsTopCommand extends Command
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName('torrents:top')
|
||||||
|
->setDescription('Top torrents')
|
||||||
|
->addOption('period', 'p', InputOption::VALUE_OPTIONAL, 'Period')
|
||||||
|
->setHelp("The <info>%command.name%</info> show top torrents");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$client = new Client();
|
||||||
|
$configLoader = new ConfigLoader();
|
||||||
|
|
||||||
|
if (!isset($configLoader->getConfig()['auth']['token'])) {
|
||||||
|
$output->writeln('You must login.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$client->setAuthorization($configLoader->getConfig()['auth']['token']);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$period = $input->getOption('period');
|
||||||
|
|
||||||
|
if (!in_array($period, ['100', 'today', 'week', 'month'])) {
|
||||||
|
$period = '100';
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $client->getTopTorrents($period);
|
||||||
|
|
||||||
|
return $this->showResults($response, $output);
|
||||||
|
} catch (ClientException $e) {
|
||||||
|
$output->writeln(sprintf('An error occured. <error>%s</error>', $e->getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function showResults(ClientResponse $response, OutputInterface $output)
|
||||||
|
{
|
||||||
|
if ($response->hasError()) {
|
||||||
|
$output->writeln(sprintf(
|
||||||
|
'<error>%s</error> <comment>(%d)</comment>',
|
||||||
|
$response->getErrorMessage(),
|
||||||
|
$response->getErrorCode()
|
||||||
|
));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output->writeln(' SEED LEECH ID NAME');
|
||||||
|
|
||||||
|
foreach ($response->getData() as $torrent) {
|
||||||
|
$output->writeln(sprintf(
|
||||||
|
'[<info>%4d</info><comment>%6d</comment>] %9d %s',
|
||||||
|
$torrent['seeders'],
|
||||||
|
$torrent['leechers'],
|
||||||
|
$torrent['id'],
|
||||||
|
$torrent['name']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue