Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc88660c07 | ||
|
|
dbcc24c49f | ||
|
|
939b059872 |
@@ -10,6 +10,8 @@ use App\Download\Action\Command\DownloadSeasonCommand;
|
|||||||
use App\Download\Action\Result\DownloadMediaResult;
|
use App\Download\Action\Result\DownloadMediaResult;
|
||||||
use App\Download\Action\Result\DownloadSeasonResult;
|
use App\Download\Action\Result\DownloadSeasonResult;
|
||||||
use App\Download\DownloadOptionEvaluator;
|
use App\Download\DownloadOptionEvaluator;
|
||||||
|
use App\Download\Framework\Entity\Download;
|
||||||
|
use App\Download\Framework\Repository\DownloadRepository;
|
||||||
use App\Tmdb\TmdbClient;
|
use App\Tmdb\TmdbClient;
|
||||||
use App\Torrentio\Action\Command\GetTvShowOptionsCommand;
|
use App\Torrentio\Action\Command\GetTvShowOptionsCommand;
|
||||||
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
use App\Torrentio\Action\Handler\GetTvShowOptionsHandler;
|
||||||
@@ -32,7 +34,7 @@ readonly class DownloadSeasonHandler implements HandlerInterface
|
|||||||
private MessageBusInterface $bus,
|
private MessageBusInterface $bus,
|
||||||
private DownloadOptionEvaluator $downloadOptionEvaluator,
|
private DownloadOptionEvaluator $downloadOptionEvaluator,
|
||||||
private GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
private GetTvShowOptionsHandler $getTvShowOptionsHandler,
|
||||||
private UserRepository $userRepository,
|
private UserRepository $userRepository, private DownloadRepository $downloadRepository,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function handle(CommandInterface $command): ResultInterface
|
public function handle(CommandInterface $command): ResultInterface
|
||||||
@@ -68,13 +70,15 @@ readonly class DownloadSeasonHandler implements HandlerInterface
|
|||||||
if (null !== $result) {
|
if (null !== $result) {
|
||||||
$this->logger->info('> [DownloadTvSeasonHandler] ......Found 1 matching result');
|
$this->logger->info('> [DownloadTvSeasonHandler] ......Found 1 matching result');
|
||||||
$this->logger->info('> [DownloadTvSeasonHandler] ......Dispatching DownloadMediaCommand for "' . $series->title . '" season ' . $command->season . ' episode ' . $episode->episodeNumber);
|
$this->logger->info('> [DownloadTvSeasonHandler] ......Dispatching DownloadMediaCommand for "' . $series->title . '" season ' . $command->season . ' episode ' . $episode->episodeNumber);
|
||||||
|
$download = $this->createDownload($command, $result->url, $series->title, $result->filename, $episode->episodeNumber);
|
||||||
$downloadCommand = new DownloadMediaCommand(
|
$downloadCommand = new DownloadMediaCommand(
|
||||||
$result->url,
|
$download->getUrl(),
|
||||||
$series->title,
|
$download->getTitle(),
|
||||||
$result->filename,
|
$download->getFilename(),
|
||||||
'tvshows',
|
$download->getMediaType(),
|
||||||
$command->imdbId,
|
$download->getImdbId(),
|
||||||
$command->userId,
|
$download->getUser()->getId(),
|
||||||
|
$download->getId()
|
||||||
);
|
);
|
||||||
$this->bus->dispatch($downloadCommand);
|
$this->bus->dispatch($downloadCommand);
|
||||||
$downloadCommands[] = $downloadCommand;
|
$downloadCommands[] = $downloadCommand;
|
||||||
@@ -90,19 +94,26 @@ readonly class DownloadSeasonHandler implements HandlerInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDownloadedEpisodes(string $title)
|
private function createDownload(DownloadSeasonCommand $command, string $url, string $title, string $filename, int $episodeNumber): Download
|
||||||
{
|
{
|
||||||
// Check current episodes
|
$download = new Download();
|
||||||
$downloadedEpisodes = $this->mediaFiles
|
$download->setUrl($url);
|
||||||
->getEpisodes($title)
|
$download->setTitle($title);
|
||||||
->map(fn($episode) => (object) (new PTN())->parse($episode))
|
$download->setFilename($filename);
|
||||||
->filter(fn ($episode) =>
|
$download->setImdbId($command->imdbId);
|
||||||
property_exists($episode, 'episode')
|
$download->setMediaType(MediaType::TvShow->value);
|
||||||
&& property_exists($episode, 'season')
|
$download->setEpisodeId($this->getEpisodeNumber($command->season, $episodeNumber));
|
||||||
&& null !== $episode->episodeNumber
|
$download->setUser($this->userRepository->find($command->userId));
|
||||||
&& null !== $episode->season
|
$this->downloadRepository->getEntityManager()->persist($download);
|
||||||
)
|
return $download;
|
||||||
->rekey(fn($episode) => $episode->episodeNumber);
|
}
|
||||||
$this->logger->info('> [MonitorTvSeasonHandler] Found ' . count($downloadedEpisodes) . ' downloaded episodes for title: ' . $monitor->getTitle());
|
|
||||||
|
private function getEpisodeNumber(int $season, int $episode): string
|
||||||
|
{
|
||||||
|
return sprintf(
|
||||||
|
"S%sE%s",
|
||||||
|
str_pad($season, 2, "0", STR_PAD_LEFT),
|
||||||
|
str_pad($episode, 2, "0", STR_PAD_LEFT)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,12 @@ class DownloadOptionEvaluator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false === $this->validateSize($result, $filter)) {
|
// todo: This is arbitrary- revisit in the future
|
||||||
|
//if (false === $this->validateSize($result, $filter)) {
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
|
if (false === $this->validateDownloadUrl($result->url)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,15 +52,15 @@ class DownloadOptionEvaluator
|
|||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $filter->codec && in_array($result->codec, $filter->codec)) {
|
if (null !== $filter->codec && !in_array($result->codec, $filter->codec)) {
|
||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $filter->quality && in_array($result->quality, $filter->quality)) {
|
if (null !== $filter->quality && !in_array($result->quality, $filter->quality)) {
|
||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $filter->provider && in_array($result->provider, $filter->provider)) {
|
if (null !== $filter->provider && !in_array($result->provider, $filter->provider)) {
|
||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,4 +84,18 @@ class DownloadOptionEvaluator
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function validateDownloadUrl(string $downloadUrl)
|
||||||
|
{
|
||||||
|
$badFileLocations = [
|
||||||
|
'https://torrentio.strem.fun/videos/failed_infringement_v2.mp4' => 'Removed for Copyright Infringement.',
|
||||||
|
];
|
||||||
|
|
||||||
|
$headers = get_headers($downloadUrl, true);
|
||||||
|
if (array_key_exists($headers['Location'], $badFileLocations)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user