transmission-client branch merged
This commit is contained in:
commit
e4ec4e5e1c
|
@ -24,6 +24,7 @@
|
||||||
"symfony/finder": "~2.6",
|
"symfony/finder": "~2.6",
|
||||||
"symfony/yaml": "~2.6",
|
"symfony/yaml": "~2.6",
|
||||||
"symfony/filesystem": "3.0.x-dev",
|
"symfony/filesystem": "3.0.x-dev",
|
||||||
"guzzlehttp/guzzle": "~5.2"
|
"guzzlehttp/guzzle": "~5.2",
|
||||||
|
"vohof/transmission": "~1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
console
8
console
|
@ -7,6 +7,8 @@ use Console\Application;
|
||||||
|
|
||||||
$app = new Application();
|
$app = new Application();
|
||||||
|
|
||||||
$app->chdir(__DIR__);
|
$app
|
||||||
$app->loadCommands();
|
->chdir(__DIR__)
|
||||||
$app->run();
|
->addCommandsPath('src/Transmission/Command', 'Transmission\\Command')
|
||||||
|
->loadCommands()
|
||||||
|
->run();
|
||||||
|
|
15
src/Transmission/Client/GuzzleClient.php
Normal file
15
src/Transmission/Client/GuzzleClient.php
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Transmission\Client;
|
||||||
|
|
||||||
|
use Vohof\GuzzleClient as BaseGuzzleClient;
|
||||||
|
|
||||||
|
class GuzzleClient extends BaseGuzzleClient
|
||||||
|
{
|
||||||
|
public function __construct($host, $options = array())
|
||||||
|
{
|
||||||
|
parent::__construct($host, $options);
|
||||||
|
|
||||||
|
$this->client->setDefaultOption('verify', false);
|
||||||
|
}
|
||||||
|
}
|
47
src/Transmission/Command/TransmissionConfigureCommand.php
Normal file
47
src/Transmission/Command/TransmissionConfigureCommand.php
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Transmission\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Api\ConfigLoader;
|
||||||
|
|
||||||
|
class TransmissionConfigureCommand extends Command
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName('transmission:configure')
|
||||||
|
->setDescription('')
|
||||||
|
// ->addArgument('foo', InputArgument::OPTIONAL, '')
|
||||||
|
// ->addOption('bar', null, InputOption::VALUE_NONE, '')
|
||||||
|
->setHelp("<info>%command.name%</info>
|
||||||
|
|
||||||
|
Configure your transmission web remote access.
|
||||||
|
|
||||||
|
Usage: <comment>transmission:configure</comment>");
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
88
src/Transmission/Command/TransmissionDownloadCommand.php
Normal file
88
src/Transmission/Command/TransmissionDownloadCommand.php
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Transmission\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Api\ConfigLoader;
|
||||||
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
|
use Vohof\Transmission;
|
||||||
|
use Transmission\Client\GuzzleClient;
|
||||||
|
|
||||||
|
class TransmissionDownloadCommand extends Command
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName('transmission:download')
|
||||||
|
->setDescription('Download a torrent')
|
||||||
|
->addArgument('id', InputArgument::REQUIRED, 'Torrent ID')
|
||||||
|
->setHelp("<info>%command.name%</info>
|
||||||
|
|
||||||
|
Download a torrent.
|
||||||
|
|
||||||
|
Usage: <comment>transmission:download</comment> <info>TORRENT_ID</info>");
|
||||||
|
}
|
||||||
|
|
||||||
|
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. <error>%s</error>',
|
||||||
|
$e->getMessage()
|
||||||
|
));
|
||||||
|
|
||||||
|
$output->writeln(sprintf('Torrent %s removed', $outputFile));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink($outputFile);
|
||||||
|
|
||||||
|
$output->writeln(sprintf('Download <info>started</info>.', $outputFile));
|
||||||
|
$output->writeln(sprintf('Torrent %s removed', $outputFile));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue