setName('torrents:details') ->setDescription('Show a torrent details') ->addArgument('id', InputArgument::REQUIRED, 'Torrent ID') ->setHelp("%command.name% Show torrent details. Usage: torrents:details TORRENT_ID"); } 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 { $response = $client->getTorrentDetails($input->getArgument('id')); if ($response->hasError()) { $output->writeln(sprintf( '%s (%d)', $response->getErrorMessage(), $response->getErrorCode() )); return; } $data = $response->getData(); $output->writeln(sprintf('%s', $data['name'])); $output->writeln(''); $output->writeln(sprintf('Category : %s', $data['categoryname'])); foreach ($data['terms'] as $title => $value) { $output->writeln(sprintf('%-16s: %s', $title, $value)); } $output->writeln(''); $output->writeln($this->parseDescription($data['description'])); } catch (ClientException $e) { $output->writeln(sprintf('An error occured. %s', $e->getMessage())); } } protected function parseDescription($description) { $description = str_replace('
', PHP_EOL, $description); $description = trim(html_entity_decode(strip_tags($description))); return $description; } }