예제 #1
0
 public function testGetTorrentAgeInDays()
 {
     // without doneDate
     $this->assertEquals(1, TorrentUtils::getTorrentAgeInDays(['doneDate' => 0, 'addedDate' => time() - 86400]));
     // with doneDate
     $this->assertEquals(2, TorrentUtils::getTorrentAgeInDays(['doneDate' => time() - 86400 * 2, 'addedDate' => time() - 86400]));
 }
예제 #2
0
 public static function buildTableData(array $torrentList)
 {
     $headers = ['Name', 'Id', 'Age', 'Size', 'Uploaded', 'Per day'];
     $rows = [];
     foreach ($torrentList as $torrent) {
         $age = TorrentUtils::getTorrentAgeInDays($torrent);
         $perDay = $age ? TorrentUtils::getSizeInGb($torrent[Torrent\Get::UPLOAD_EVER] / $age) : 0;
         $rows[] = [$torrent[Torrent\Get::NAME], $torrent[Torrent\Get::ID], $age, TorrentUtils::getSizeInGb($torrent[Torrent\Get::TOTAL_SIZE]), TorrentUtils::getSizeInGb($torrent[Torrent\Get::UPLOAD_EVER]), $perDay];
     }
     return ['headers' => $headers, 'rows' => $rows];
 }
예제 #3
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');
 }
예제 #4
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;
 }