From 7be9358f75403799524e0a90ba7d3dc333036bd2 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 15 Feb 2015 21:35:44 +0100 Subject: [PATCH 1/4] transmission client --- composer.json | 9 ++++----- console | 1 + src/Console/Application.php | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index c27b75b..b8a4650 100644 --- a/composer.json +++ b/composer.json @@ -11,21 +11,20 @@ "email": "simon+github@deblan.fr" } ], - "require": { - "php": ">=5.5", - "symfony/process": "~2.6" - }, "autoload": { "psr-0": { "": "src/" } }, "require": { + "php": ">=5.5", + "symfony/process": "~2.6", "symfony/console": "2.*", "psr/log": "1.0.0", "symfony/finder": "~2.6", "symfony/yaml": "~2.6", "symfony/filesystem": "3.0.x-dev", - "guzzlehttp/guzzle": "~5.2" + "guzzlehttp/guzzle": "~5.2", + "vohof/transmission": "~1.0" } } diff --git a/console b/console index fa3fe68..68107ef 100755 --- a/console +++ b/console @@ -9,5 +9,6 @@ $app = new Application(); $app ->chdir(__DIR__) + ->addCommandsPath('src/Transmission/Command', 'Transmission\\Command') ->loadCommands() ->run(); diff --git a/src/Console/Application.php b/src/Console/Application.php index bd52d6e..d31ce38 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -27,9 +27,8 @@ class Application extends BaseApplication public function loadCommands() { - $finder = new Finder(); - foreach ($this->commandsPaths as $path => $namespace) { + $finder = new Finder(); $finder->files('*Command.php')->in($path); foreach ($finder as $file) { From 6f363676fff02df4d235bd14b89aa4a4c8c6656b Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 15 Feb 2015 21:38:49 +0100 Subject: [PATCH 2/4] indent --- console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console b/console index 68107ef..38e88c4 100755 --- a/console +++ b/console @@ -9,6 +9,6 @@ $app = new Application(); $app ->chdir(__DIR__) - ->addCommandsPath('src/Transmission/Command', 'Transmission\\Command') + ->addCommandsPath('src/Transmission/Command', 'Transmission\\Command') ->loadCommands() ->run(); From d0cca49d75fac532ad11f14ce44e7eb38d0a8eb2 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 15 Feb 2015 21:39:44 +0100 Subject: [PATCH 3/4] Transmission commands --- src/Transmission/Client/GuzzleClient.php | 15 ++++ .../Command/TransmissionConfigureCommand.php | 43 +++++++++ .../Command/TransmissionDownloadCommand.php | 88 +++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 src/Transmission/Client/GuzzleClient.php create mode 100644 src/Transmission/Command/TransmissionConfigureCommand.php create mode 100644 src/Transmission/Command/TransmissionDownloadCommand.php diff --git a/src/Transmission/Client/GuzzleClient.php b/src/Transmission/Client/GuzzleClient.php new file mode 100644 index 0000000..633b18c --- /dev/null +++ b/src/Transmission/Client/GuzzleClient.php @@ -0,0 +1,15 @@ +client->setDefaultOption('verify', false); + } +} diff --git a/src/Transmission/Command/TransmissionConfigureCommand.php b/src/Transmission/Command/TransmissionConfigureCommand.php new file mode 100644 index 0000000..9492bda --- /dev/null +++ b/src/Transmission/Command/TransmissionConfigureCommand.php @@ -0,0 +1,43 @@ +setName('transmission:configure') + ->setDescription('') + // ->addArgument('foo', InputArgument::OPTIONAL, '') + // ->addOption('bar', null, InputOption::VALUE_NONE, '') + ->setHelp("The %command.name% "); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $configLoader = new ConfigLoader(); + $dialog = $this->getHelperSet()->get('dialog'); + + $host = $dialog->ask($output, 'Host (eg: https://seedox.example.com/): ', null); + $endPoint = $dialog->ask($output, 'End point [/transmission/rpc]: ', null); + $username = $dialog->ask($output, 'Username: ', null); + $password = $dialog->askHiddenResponse($output, 'Password (hidden): ', null); + + $configLoader->save(array( + 'transmission' => array( + 'host' => $host, + 'endpoint' => $endPoint ? $endPoint : '/transmission/rpc', + 'username' => $username, + 'password' => $password, + ) + )); + } +} diff --git a/src/Transmission/Command/TransmissionDownloadCommand.php b/src/Transmission/Command/TransmissionDownloadCommand.php new file mode 100644 index 0000000..5d05a3c --- /dev/null +++ b/src/Transmission/Command/TransmissionDownloadCommand.php @@ -0,0 +1,88 @@ +setName('transmission:download') + ->setDescription('Download a torrent') + ->addArgument('id', InputArgument::REQUIRED, 'Torrent ID') + ->setHelp("%command.name% + +Download a torrent. + +Usage: transmission:download TORRENT_ID"); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $configLoader = new ConfigLoader(); + + if (!isset($configLoader->getConfig()['transmission'])) { + $output->writeln('No configuration found.'); + + return; + } + + $config = $configLoader->getConfig()['transmission']; + + $outputFile = sprintf('.%d', time()); + + $inputData = array( + 'command' => 'torrents:download', + 'id' => $input->getArgument('id'), + 'output_file' => $outputFile, + '-q' => true, + ); + + $options = []; + + if (!empty($config['username']) and !empty($config['password'])) { + $options = array( + 'request.options' => array( + 'auth' => array($config['username'], $config['password']) + ) + ); + } + + try { + $client = new GuzzleClient($config['host'], $options); + + $transmission = new Transmission($configLoader->getConfig()['transmission'], $client); + + $this->getApplication()->doRun(new ArrayInput($inputData), $output); + + $content = base64_encode(file_get_contents($outputFile)); + + $torrent = $transmission->add($content, true); + } catch (\Exception $e) { + unlink($outputFile); + + $output->writeln(sprintf( + 'An error occured. %s', + $e->getMessage() + )); + + $output->writeln(sprintf('Torrent %s removed', $outputFile)); + + return; + } + + unlink($outputFile); + + $output->writeln(sprintf('Download started.', $outputFile)); + $output->writeln(sprintf('Torrent %s removed', $outputFile)); + } +} From 276020b75943fc427fc2e8e9c06777b4e8b2e01d Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 23 Feb 2015 09:59:29 +0100 Subject: [PATCH 4/4] Help --- src/Transmission/Command/TransmissionConfigureCommand.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Transmission/Command/TransmissionConfigureCommand.php b/src/Transmission/Command/TransmissionConfigureCommand.php index 9492bda..025574b 100644 --- a/src/Transmission/Command/TransmissionConfigureCommand.php +++ b/src/Transmission/Command/TransmissionConfigureCommand.php @@ -18,7 +18,11 @@ class TransmissionConfigureCommand extends Command ->setDescription('') // ->addArgument('foo', InputArgument::OPTIONAL, '') // ->addOption('bar', null, InputOption::VALUE_NONE, '') - ->setHelp("The %command.name% "); + ->setHelp("%command.name% + +Configure your transmission web remote access. + +Usage: transmission:configure"); } protected function execute(InputInterface $input, OutputInterface $output)