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