fix-feat: ajax download call

This commit is contained in:
2025-04-23 16:17:03 -05:00
parent 5402680abf
commit 6dc6fbd449
15 changed files with 153 additions and 19 deletions

View File

@@ -18,7 +18,11 @@ class DownloadController extends AbstractController
public function download(
DownloadMediaInput $input,
): Response {
$this->bus->dispatch($input->toCommand());
try {
$this->bus->dispatch($input->toCommand());
} catch (\Throwable $exception) {
return $this->json(['error' => $exception->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
}
return $this->json(['status' => 200, 'message' => 'Added to Queue']);
}

View File

@@ -17,7 +17,7 @@ final class TorrentioController extends AbstractController
private readonly GetTvShowOptionsHandler $getTvShowOptionsHandler,
) {}
#[Route('/torrentio/movies/{imdbId}', name: 'app_torrentio_movies')]
#[Route('/torrentio/movies/{tmdbId}/{imdbId}', name: 'app_torrentio_movies')]
public function movieOptions(GetMovieOptionsInput $input): Response
{
$results = $this->getMovieOptionsHandler->handle($input->toCommand());

View File

@@ -7,6 +7,7 @@ use OneToMany\RichBundle\Contract\CommandInterface;
class GetMovieOptionsCommand implements CommandInterface
{
public function __construct(
public string $tmdbId,
public string $imdbId,
) {}
}

View File

@@ -2,6 +2,7 @@
namespace App\Torrentio\Action\Handler;
use App\Tmdb\Tmdb;
use App\Torrentio\Action\Result\GetMovieOptionsResult;
use App\Torrentio\Client\Torrentio;
use OneToMany\RichBundle\Contract\CommandInterface;
@@ -11,13 +12,15 @@ use OneToMany\RichBundle\Contract\ResultInterface;
class GetMovieOptionsHandler implements HandlerInterface
{
public function __construct(
private readonly Tmdb $tmdb,
private readonly Torrentio $torrentio,
) {}
public function handle(CommandInterface $command): ResultInterface
{
return new GetMovieOptionsResult(
results: $this->torrentio->search($command->imdbId, 'movies')
media: $this->tmdb->mediaDetails($command->tmdbId, 'movies'),
results: $this->torrentio->search($command->imdbId, 'movies'),
);
}
}

View File

@@ -10,12 +10,15 @@ use OneToMany\RichBundle\Contract\InputInterface;
class GetMovieOptionsInput implements InputInterface
{
public function __construct(
#[SourceRoute('tmdbId')]
public string $tmdbId,
#[SourceRoute('imdbId')]
public string $imdbId,
) {}
public function toCommand(): CommandInterface
{
return new GetMovieOptionsCommand($this->imdbId);
return new GetMovieOptionsCommand($this->tmdbId, $this->imdbId);
}
}

View File

@@ -2,11 +2,13 @@
namespace App\Torrentio\Action\Result;
use App\Tmdb\TmdbResult;
use OneToMany\RichBundle\Contract\ResultInterface;
class GetMovieOptionsResult implements ResultInterface
{
public function __construct(
public TmdbResult $media,
public array $results
) {}
}

View File

@@ -15,7 +15,8 @@ class ResultFactory
$ptn = (object) (new PTN())->parse($title);
return new TorrentioResult(
self::trimTitle($title),
$url,
urldecode($url),
self::setFilename($url),
self::setSize($title),
self::setSeeders($title),
self::setProvider($title),
@@ -33,6 +34,12 @@ class ResultFactory
);
}
public static function setFilename(string $url)
{
$file = explode("/", urldecode($url));
return end($file);
}
public static function setSize(string $title): string
{
$sizeMatch = [];

View File

@@ -7,6 +7,7 @@ class TorrentioResult
public function __construct(
public ?string $title = "-",
public ?string $url = "-",
public ?string $filename = "-",
public ?string $size = "-",
public ?string $seeders = "-",
public ?string $provider = "-",