1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Popstas\Transmission\Console\Command; |
4
|
|
|
|
5
|
|
|
use Martial\Transmission\API\Argument\Torrent; |
6
|
|
|
use Popstas\Transmission\Console\TransmissionClient; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
class TorrentAdd extends Command |
12
|
|
|
{ |
13
|
|
|
protected function configure() |
14
|
|
|
{ |
15
|
|
|
parent::configure(); |
16
|
|
|
$this |
17
|
|
|
->setName('torrent-add') |
18
|
|
|
->setAliases(['ta']) |
19
|
|
|
->setDescription('Remove torrents') |
20
|
|
|
->addArgument('torrent-files', InputArgument::IS_ARRAY, 'List of torrent files to add') |
21
|
|
|
->setHelp(<<<EOT |
22
|
|
|
By default, Transmission may to freeze if you add several torrents at same time. |
23
|
|
|
Therefore, preferred way to add torrents - with `torrent-add`. |
24
|
|
|
After each add file command sleeps for 10 seconds for give time to freeze Transmission. |
25
|
|
|
After that command waits for Transmission answer and add next file, etc. |
26
|
|
|
|
27
|
|
|
``` |
28
|
|
|
transmission-cli torrent-add file|url [file2] [fileX] |
29
|
|
|
``` |
30
|
|
|
EOT |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
35
|
|
|
{ |
36
|
|
|
$client = $this->getApplication()->getClient(); |
37
|
|
|
|
38
|
|
|
$torrentFiles = $input->getArgument('torrent-files'); |
39
|
|
|
|
40
|
|
|
foreach ($torrentFiles as $torrentFile) { |
41
|
|
|
$this->addFile($input, $output, $client, $torrentFile); |
42
|
|
|
$output->writeln($torrentFile . ' added. Waiting for Transmission...'); |
43
|
|
|
$client->waitForTransmission(10); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$output->writeln('All torrents added.'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function addFile(InputInterface $input, OutputInterface $output, TransmissionClient $client, $torrentFile) |
50
|
|
|
{ |
51
|
|
|
$this->dryRun($input, $output, function () use ($torrentFile, $client, $input, $output) { |
52
|
|
|
$client->addTorrent($torrentFile); |
53
|
|
|
}, 'dry-run, don\'t really add torrents'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|