From 7958f50ff7968e7e4217a96db2d06b5807c4b311 Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Fri, 6 Feb 2026 15:23:18 -0600 Subject: [PATCH] fix: includes missing files from last commit --- .../Repository/DownloadRepository.php | 12 +++++++++ src/Torrentio/Client/Torrentio.php | 25 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Download/Framework/Repository/DownloadRepository.php b/src/Download/Framework/Repository/DownloadRepository.php index e2c6f43..8461dc3 100644 --- a/src/Download/Framework/Repository/DownloadRepository.php +++ b/src/Download/Framework/Repository/DownloadRepository.php @@ -123,4 +123,16 @@ class DownloadRepository extends ServiceEntityRepository ->getQuery() ->getResult(); } + + public function badDownloadUrls() + { + return $this->createQueryBuilder('d') + ->select('d.url') + ->andWhere('d.status = :status') + ->andWhere('d.progress = 100') + ->setParameter('status', 'Failed') + ->distinct() + ->getQuery() + ->getResult(); + } } diff --git a/src/Torrentio/Client/Torrentio.php b/src/Torrentio/Client/Torrentio.php index 02a71b3..c6348c2 100644 --- a/src/Torrentio/Client/Torrentio.php +++ b/src/Torrentio/Client/Torrentio.php @@ -2,14 +2,25 @@ namespace App\Torrentio\Client; +use Aimeos\Map; +use App\Download\Framework\Repository\DownloadRepository; use App\Torrentio\Result\ResultFactory; use App\Torrentio\Exception\TorrentioRateLimitException; +use Psr\Log\LoggerInterface; class Torrentio { + private array $badDownloadUrls = []; + public function __construct( - private readonly HttpClient $client, - ) {} + private readonly HttpClient $client, + private readonly DownloadRepository $downloadRepository, private readonly LoggerInterface $logger, + ) { + $badDownloadUrls = $this->downloadRepository->badDownloadUrls(); + $this->badDownloadUrls = Map::from($badDownloadUrls) + ->map(fn ($url) => $url['url']) + ->toArray(); + } public function search(string $imdbCode, string $type, bool $parseResults = true): array { @@ -47,6 +58,16 @@ class Torrentio continue; } + $url = explode('/', $stream['url']); + $filename = urldecode(end($url)); + $url[count($url) - 1] = $filename; + $url = implode('/', $url); + + if (in_array($stream['url'], $this->badDownloadUrls)) { + $this->logger->warning($stream['url'] . ' was skipped because it was identified as a bad download url.'); + continue; + } + if ( array_key_exists('behaviorHints', $stream) && array_key_exists('bingeGroup', $stream['behaviorHints'])