Пример #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $client = $this->getApplication()->getClient();
     $torrentList = $client->getTorrentData();
     $torrentList = array_map(function ($torrent) {
         $torrent['age'] = TorrentUtils::getTorrentAgeInDays($torrent);
         return $torrent;
     }, $torrentList);
     $torrentList = TorrentListUtils::filterTorrents($torrentList, ['age' => $input->getOption('age'), 'name' => $input->getOption('name')]);
     TorrentListUtils::printTorrentsTable($torrentList, $output, $input->getOption('sort'), $input->getOption('limit'));
     $freeSpace = $client->getFreeSpace();
     $output->writeln('Free space: ' . TorrentUtils::getSizeInGb($freeSpace) . ' GB');
 }
Пример #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = $this->getApplication()->getConfig();
     $logger = $this->getApplication()->getLogger();
     $client = $this->getApplication()->getClient();
     try {
         $influxDbClient = $this->getApplication()->getInfluxDbClient($config->get('influxdb-host'), $config->get('influxdb-port'), $config->get('influxdb-user'), $config->get('influxdb-password'), $config->get('influxdb-database'));
         $lastDays = (int) $input->getOption('days') ? (int) $input->getOption('days') : 0;
         $limit = (int) $input->getOption('limit') ? (int) $input->getOption('limit') : 0;
         $torrentList = $client->getTorrentData();
         $torrentList = array_map(function ($torrent) {
             $torrent['age'] = TorrentUtils::getTorrentAgeInDays($torrent);
             return $torrent;
         }, $torrentList);
         $torrentList = TorrentListUtils::filterTorrents($torrentList, ['age' => $input->getOption('age'), 'name' => $input->getOption('name')]);
         $transmissionHost = $config->get('transmission-host');
         $torrentList = array_map(function ($torrent) use($influxDbClient, $transmissionHost, $lastDays) {
             $torrent['uploaded'] = $influxDbClient->getTorrentSum($torrent, 'uploaded_last', $transmissionHost, $lastDays);
             $days = max(1, min($torrent['age'], $lastDays));
             $torrent['per_day'] = $days ? TorrentUtils::getSizeInGb($torrent['uploaded'] / $days) : 0;
             $torrent['profit'] = round($torrent['uploaded'] / $torrent[Torrent\Get::TOTAL_SIZE] / $days * 100, 2);
             return $torrent;
         }, $torrentList);
     } catch (\Exception $e) {
         $logger->critical($e->getMessage());
         return 1;
     }
     $torrentList = TorrentListUtils::filterTorrents($torrentList, ['profit' => ['type' => 'numeric', 'value' => $input->getOption('profit')]]);
     $tableData = $this->buildTableData($torrentList, $input->getOption('sort'), $limit);
     TableUtils::printTable($tableData, $output);
     $freeSpace = $client->getFreeSpace();
     $output->writeln('Free space: ' . TorrentUtils::getSizeInGb($freeSpace) . ' GB');
     if ($input->getOption('rm')) {
         return $this->removeTorrents($input, $output, $tableData['rows']);
     }
     return 0;
 }
 /**
  * @dataProvider invalidFilterProvider
  * @expectedException \InvalidArgumentException
  * @param array $filters
  */
 public function testInvalidFilter(array $filters)
 {
     TorrentListUtils::filterTorrents([], $filters);
 }