fix: allows local or queued downloads
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Search\Framework\Command;
|
|||||||
use Aimeos\Map;
|
use Aimeos\Map;
|
||||||
use App\Download\Action\Command\DownloadMediaCommand;
|
use App\Download\Action\Command\DownloadMediaCommand;
|
||||||
use App\Download\Action\Handler\DownloadMediaHandler;
|
use App\Download\Action\Handler\DownloadMediaHandler;
|
||||||
use App\Download\Framework\Entity\Download;
|
|
||||||
use App\Download\Framework\Repository\DownloadRepository;
|
use App\Download\Framework\Repository\DownloadRepository;
|
||||||
use App\Search\Action\Handler\SearchHandler;
|
use App\Search\Action\Handler\SearchHandler;
|
||||||
use App\Search\Action\Command\SearchCommand as CommandInput;
|
use App\Search\Action\Command\SearchCommand as CommandInput;
|
||||||
@@ -22,10 +21,12 @@ use Symfony\Component\Console\Command\Command;
|
|||||||
use Symfony\Component\Console\Helper\Table;
|
use Symfony\Component\Console\Helper\Table;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||||
use Symfony\Component\Console\Question\Question;
|
use Symfony\Component\Console\Question\Question;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
|
|
||||||
#[AsCommand('search')]
|
#[AsCommand('search')]
|
||||||
class SearchCommand extends Command
|
class SearchCommand extends Command
|
||||||
@@ -36,12 +37,14 @@ class SearchCommand extends Command
|
|||||||
private UserRepository $userRepository;
|
private UserRepository $userRepository;
|
||||||
private DownloadRepository $downloadRepository;
|
private DownloadRepository $downloadRepository;
|
||||||
private DownloadMediaHandler $downloadMediaHandler;
|
private DownloadMediaHandler $downloadMediaHandler;
|
||||||
|
private MessageBusInterface $bus;
|
||||||
|
|
||||||
public function __construct(SearchHandler $searchHandler, GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
public function __construct(SearchHandler $searchHandler, GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
||||||
GetMovieOptionsHandler $getMovieOptionsHandler,
|
GetMovieOptionsHandler $getMovieOptionsHandler,
|
||||||
UserRepository $userRepository,
|
UserRepository $userRepository,
|
||||||
DownloadRepository $downloadRepository,
|
DownloadRepository $downloadRepository,
|
||||||
DownloadMediaHandler $downloadMediaHandler,
|
DownloadMediaHandler $downloadMediaHandler,
|
||||||
|
MessageBusInterface $bus,
|
||||||
?string $name = null
|
?string $name = null
|
||||||
) {
|
) {
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
@@ -51,33 +54,44 @@ class SearchCommand extends Command
|
|||||||
$this->userRepository = $userRepository;
|
$this->userRepository = $userRepository;
|
||||||
$this->downloadRepository = $downloadRepository;
|
$this->downloadRepository = $downloadRepository;
|
||||||
$this->downloadMediaHandler = $downloadMediaHandler;
|
$this->downloadMediaHandler = $downloadMediaHandler;
|
||||||
|
$this->bus = $bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this->addArgument('term', InputArgument::REQUIRED);
|
$this->addArgument('term', InputArgument::REQUIRED);
|
||||||
|
$this->addOption('local', 'l', InputOption::VALUE_NONE, 'Perform the download locally instead of submitting it to the queue.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(InputInterface $input, OutputInterface $output): int
|
public function run(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$command = new CommandInput($input->getArgument('term'));
|
$command = new CommandInput($input->getArgument('term'));
|
||||||
|
|
||||||
|
// Perform search
|
||||||
$mediaOptions = $this->searchHandler->handle($command);
|
$mediaOptions = $this->searchHandler->handle($command);
|
||||||
|
|
||||||
|
// Render results and ask the User to pick one
|
||||||
$mediaChoice = $this->askToChooseMediaOption($io, $output, $mediaOptions);
|
$mediaChoice = $this->askToChooseMediaOption($io, $output, $mediaOptions);
|
||||||
|
|
||||||
|
// Find download options based on the User's choice
|
||||||
$downloadOptions = $this->fetchDownloadOptions($mediaChoice);
|
$downloadOptions = $this->fetchDownloadOptions($mediaChoice);
|
||||||
|
|
||||||
|
// Render results and ask the User to pick one
|
||||||
$downloadChoice = $this->askToChooseDownloadOption($io, $output, $downloadOptions);
|
$downloadChoice = $this->askToChooseDownloadOption($io, $output, $downloadOptions);
|
||||||
|
|
||||||
|
// Have user confirm download action
|
||||||
$confirmation = $this->askToConfirmDownload($io, $output, $downloadChoice);
|
$confirmation = $this->askToConfirmDownload($io, $output, $downloadChoice);
|
||||||
|
|
||||||
|
// Begin download or submit to the queue
|
||||||
if (true === $confirmation) {
|
if (true === $confirmation) {
|
||||||
$this->submitDownload($io, $mediaChoice, $downloadChoice);
|
$downloadLocally = $input->getOption('local');
|
||||||
|
$this->submitDownload($io, $mediaChoice, $downloadChoice, $downloadLocally);
|
||||||
} else {
|
} else {
|
||||||
$io->success('No results found.');
|
$io->success('No results found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$io->success('Success!');
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -162,7 +176,7 @@ class SearchCommand extends Command
|
|||||||
return $choice === 'yes';
|
return $choice === 'yes';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function submitDownload(SymfonyStyle $io, TmdbResult $mediaChoice, TorrentioResult $downloadOption): void
|
private function submitDownload(SymfonyStyle $io, TmdbResult $mediaChoice, TorrentioResult $downloadOption, bool $downloadLocally = false): void
|
||||||
{
|
{
|
||||||
$io->writeln('> Adding download record');
|
$io->writeln('> Adding download record');
|
||||||
$user = $this->userRepository->find(1);
|
$user = $this->userRepository->find(1);
|
||||||
@@ -186,8 +200,13 @@ class SearchCommand extends Command
|
|||||||
$download->getId()
|
$download->getId()
|
||||||
);
|
);
|
||||||
|
|
||||||
$io->writeln('> Submitting download to queue');
|
if (true === $downloadLocally) {
|
||||||
$this->downloadMediaHandler->handle($downloadCommand);
|
$io->writeln('> Beginning local download');
|
||||||
|
$this->downloadMediaHandler->handle($downloadCommand);
|
||||||
|
} else {
|
||||||
|
$io->writeln('> Submitting download to queue');
|
||||||
|
$this->bus->dispatch($downloadCommand);
|
||||||
|
}
|
||||||
|
|
||||||
$io->writeln('> Download added to queue');
|
$io->writeln('> Download added to queue');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user