WIP: working direct URL download
This commit is contained in:
@@ -117,6 +117,7 @@ export default class DownloadOptionTr extends HTMLTableRowElement {
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url: this.url,
|
||||
mediaType: this.mediaType,
|
||||
imdbId: this.imdbId,
|
||||
season: this.season,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Download\Action\Handler;
|
||||
|
||||
use Aimeos\Map;
|
||||
use App\Base\Enum\MediaType;
|
||||
use App\Base\Service\Broadcaster;
|
||||
use App\Base\Service\MediaFiles;
|
||||
@@ -14,7 +15,6 @@ use App\Download\Framework\Entity\Download;
|
||||
use App\Download\Framework\Repository\DownloadRepository;
|
||||
use App\Download\Downloader\DownloaderInterface;
|
||||
use App\EventLog\Action\Command\AddEventLogCommand;
|
||||
use App\Library\Dto\MediaFileDto;
|
||||
use App\Search\Action\Command\GetMediaInfoCommand;
|
||||
use App\Search\Action\Handler\GetMediaInfoHandler;
|
||||
use App\Search\Action\Result\GetMediaInfoResult;
|
||||
@@ -22,7 +22,10 @@ use App\Torrentio\Action\Command\GetMovieOptionsCommand;
|
||||
use App\Torrentio\Action\Command\GetTvShowOptionsCommand;
|
||||
use App\Torrentio\Action\Handler\GetMovieOptionsHandler;
|
||||
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
||||
use App\Torrentio\Action\Result\GetMovieOptionsResult;
|
||||
use App\Torrentio\Action\Result\GetTvShowOptionsResult;
|
||||
use App\Torrentio\Result\TorrentioResult;
|
||||
use App\User\Dto\UserPreferences;
|
||||
use App\User\Dto\UserPreferencesFactory;
|
||||
use App\User\Framework\Repository\UserRepository;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
@@ -76,26 +79,19 @@ readonly class DownloadMediaHandler implements HandlerInterface
|
||||
)
|
||||
};
|
||||
|
||||
if (null === $command->url) {
|
||||
$filter = $command->filter !== null
|
||||
? UserPreferencesFactory::createFromArray($command->filter)
|
||||
: UserPreferencesFactory::createFromUser($user);
|
||||
|
||||
$matchingOption = $this->downloadOptionEvaluator->evaluateOptions($downloadOptions->results, $filter);
|
||||
|
||||
if ($matchingOption === null) {
|
||||
$download->setProgress(100);
|
||||
$download->setStatus('Failed');
|
||||
$this->downloadRepository->getEntityManager()->flush();
|
||||
$this->broadcaster->alert(
|
||||
title:'Uh oh',
|
||||
message: 'No matching download options found.',
|
||||
type: 'warning',
|
||||
mercureAlertTopic: $command->mercureAlertTopic
|
||||
);
|
||||
throw new UnrecoverableMessageHandlingException('No matching download options found.', 404);
|
||||
$matchingOption = $this->findMatchingDownloadOption($download, $downloadOptions, $filter, $command);
|
||||
$download->setUrl($matchingOption->url);
|
||||
} else {
|
||||
$matchingOption = Map::from($downloadOptions->results)
|
||||
->filter(fn (TorrentioResult $result) => $result->url === $command->url)
|
||||
->first();
|
||||
$download->setUrl($command->url);
|
||||
}
|
||||
|
||||
$download->setUrl($matchingOption->url);
|
||||
$download->setTitle($media->media->title);
|
||||
$download->setFileName(
|
||||
$this->getFilename(MediaType::from($command->mediaType), $media, $matchingOption)
|
||||
@@ -146,6 +142,29 @@ readonly class DownloadMediaHandler implements HandlerInterface
|
||||
return new DownloadMediaResult(200, "Success.");
|
||||
}
|
||||
|
||||
private function findMatchingDownloadOption(
|
||||
Download $download,
|
||||
GetMovieOptionsResult|GetTvShowOptionsResult $downloadOptions,
|
||||
UserPreferences $filter,
|
||||
CommandInterface $command
|
||||
): ?TorrentioResult {
|
||||
$matchingOption = $this->downloadOptionEvaluator->evaluateOptions($downloadOptions->results, $filter);
|
||||
|
||||
if ($matchingOption === null) {
|
||||
$download->setProgress(100);
|
||||
$download->setStatus('Failed');
|
||||
$this->downloadRepository->getEntityManager()->flush();
|
||||
$this->broadcaster->alert(
|
||||
title:'Uh oh',
|
||||
message: 'No matching download options found.',
|
||||
type: 'warning',
|
||||
mercureAlertTopic: $command->mercureAlertTopic
|
||||
);
|
||||
throw new UnrecoverableMessageHandlingException('No matching download options found.', 404);
|
||||
}
|
||||
return $matchingOption;
|
||||
}
|
||||
|
||||
private function getFilepath(MediaType $mediaType, GetMediaInfoResult $media, TorrentioResult $option): ?string
|
||||
{
|
||||
return match ($mediaType) {
|
||||
|
||||
@@ -60,7 +60,7 @@ class ApiController extends AbstractController
|
||||
));
|
||||
|
||||
try {
|
||||
$this->bus->dispatch($input->toCommand());
|
||||
$handler->handle($input->toCommand());
|
||||
} catch (\Throwable $exception) {
|
||||
return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user