Beispiel #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = $this->getApplication()->getConfig();
     $logger = $this->getApplication()->getLogger();
     $client = $this->getApplication()->getClient();
     $torrentList = $client->getTorrentData();
     $obsoleteList = TorrentListUtils::getObsoleteTorrents($torrentList);
     if (!empty($obsoleteList)) {
         $output->writeln('<comment>Found obsolete torrents,
                           remove it using transmission-cli torrent-remove-duplicates</comment>');
         return 1;
     }
     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'));
         $points = [];
         $transmissionHost = $config->get('transmission-host');
         foreach ($torrentList as $torrent) {
             $age = TorrentUtils::getTorrentAge($torrent);
             $torrentPoint = $influxDbClient->buildPoint($torrent, $transmissionHost);
             if ($age) {
                 $points[] = $torrentPoint;
             } else {
                 $logger->debug('Skip point: {point}', ['point' => $torrentPoint]);
             }
         }
         $this->dryRun($input, $output, function () use($influxDbClient, $points) {
             $influxDbClient->writePoints($points);
         }, 'dry-run, don\'t really send points');
     } catch (\Exception $e) {
         $logger->critical($e->getMessage());
         return 1;
     }
     return 0;
 }
 public function testSortRowsByColumnNumber()
 {
     $data = TorrentListUtils::buildTableData($this->expectedTorrentList);
     $rows = $data['rows'];
     $sortedRows = TableUtils::sortRowsByColumnNumber($rows, 2);
     $sortedIds = TorrentListUtils::getArrayField($sortedRows, 1);
     $this->assertEquals([1, 2, 3, 4], $sortedIds);
     $sortedRows = TableUtils::sortRowsByColumnNumber($rows, -2);
     $sortedIds = TorrentListUtils::getArrayField($sortedRows, 1);
     $this->assertEquals([4, 3, 2, 1], $sortedIds);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = $this->getApplication()->getConfig();
     $client = $this->getApplication()->getClient();
     $torrentList = $client->getTorrentData();
     $obsoleteList = TorrentListUtils::getObsoleteTorrents($torrentList);
     if (empty($obsoleteList)) {
         $output->writeln('There are no obsolete torrents in Transmission.');
         return 0;
     }
     $this->dryRun($input, $output, function () use($client, $obsoleteList, $config, $input, $output) {
         $influxDbClient = $this->getApplication()->getInfluxDbClient($config->get('influxdb-host'), $config->get('influxdb-port'), $config->get('influxdb-user'), $config->get('influxdb-password'), $config->get('influxdb-database'));
         $transmissionHost = $config->get('transmission-host');
         $influxDbClient->sendTorrentPoints($obsoleteList, $transmissionHost);
         $client->removeTorrents($obsoleteList);
         $names = TorrentListUtils::getArrayField($obsoleteList, Torrent\Get::NAME);
         $output->writeln('Removed torrents:' . implode(', ', $names));
     }, 'dry-run, don\'t really remove');
     $output->writeln('Found and deleted ' . count($obsoleteList) . ' obsolete torrents from transmission:');
     TorrentListUtils::printTorrentsTable($obsoleteList, $output);
     return 0;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $client = $this->getApplication()->getClient();
     $config = $this->getApplication()->getConfig();
     $torrentIds = $input->getArgument('torrent-ids');
     $torrentList = $client->getTorrentData($torrentIds);
     $notExistsIds = array_diff($torrentIds, TorrentListUtils::getArrayField($torrentList, Torrent\Get::ID));
     if (count($notExistsIds)) {
         foreach ($notExistsIds as $notExistsId) {
             $output->writeln($notExistsId . ' not exists');
         }
         return 1;
     }
     $output->writeln('Torrents for remove:');
     TorrentListUtils::printTorrentsTable($torrentList, $output);
     if (!$input->getOption('yes')) {
         $helper = $this->getHelper('question');
         $question = new ConfirmationQuestion('Continue with this action? ', false);
         if (!$helper->ask($input, $output, $question)) {
             $output->writeln('Aborting.');
             return 1;
         }
     }
     $this->dryRun($input, $output, function () use($config, $torrentList, $client, $input, $output) {
         $influxDbClient = $this->getApplication()->getInfluxDbClient($config->get('influxdb-host'), $config->get('influxdb-port'), $config->get('influxdb-user'), $config->get('influxdb-password'), $config->get('influxdb-database'));
         $transmissionHost = $config->get('transmission-host');
         $influxDbClient->sendTorrentPoints($torrentList, $transmissionHost);
         $deleteLocalData = !$input->getOption('soft');
         $client->removeTorrents($torrentList, $deleteLocalData);
         $output->writeln('Torrents removed.');
         if (!$deleteLocalData) {
             $output->writeln('Data don\'t removed.');
         }
     }, 'dry-run, don\'t really remove torrents');
     return 0;
 }
Beispiel #5
0
 private function buildTableData(array $torrentList, $sort, $limit)
 {
     $rows = [];
     foreach ($torrentList as $torrent) {
         $rows[] = [$torrent[Torrent\Get::NAME], $torrent[Torrent\Get::ID], $torrent['age'], TorrentUtils::getSizeInGb($torrent[Torrent\Get::TOTAL_SIZE]), TorrentUtils::getSizeInGb($torrent['uploaded']), $torrent['per_day'], $torrent['profit']];
     }
     $rows = TableUtils::sortRowsByColumnNumber($rows, $sort);
     $rows = TableUtils::limitRows($rows, $limit);
     return ['headers' => ['Name', 'Id', 'Age, days', 'Size, GB', 'Uploaded, GB', 'Per day, GB', 'Profit, %'], 'rows' => $rows, 'totals' => ['Total: ' . count($rows), '', '', TorrentListUtils::sumArrayField($rows, 3), TorrentListUtils::sumArrayField($rows, 4), TorrentListUtils::sumArrayField($rows, 5), TorrentListUtils::sumArrayField($rows, 6)]];
 }
 public function testGetObsoleteTorrents()
 {
     $obsolete = TorrentListUtils::getObsoleteTorrents($this->expectedTorrentList);
     $this->assertCount(1, $obsolete);
     $this->assertEquals(1, $obsolete[0]['id']);
 }
 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');
 }