Convertion des images webp et png vers jpeg
This commit is contained in:
parent
21b2adfa07
commit
5f15d14ae1
@@ -8,7 +8,6 @@ use App\Repository\ChapterRepository;
|
||||
use App\Repository\ContentSourceRepository;
|
||||
use App\Service\NotificationService;
|
||||
use App\Service\Scraper\MangaScraperService;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
@@ -17,17 +16,15 @@ use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
readonly class DownloadChapterHandler
|
||||
{
|
||||
public function __construct(
|
||||
private ChapterRepository $chapterRepository,
|
||||
private MangaScraperService $mangaScraperService,
|
||||
private NotificationService $notificationService,
|
||||
private ChapterRepository $chapterRepository,
|
||||
private MangaScraperService $mangaScraperService,
|
||||
private NotificationService $notificationService,
|
||||
private ContentSourceRepository $contentSourceRepository
|
||||
)
|
||||
{
|
||||
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __invoke(DownloadChapter $message): void
|
||||
{
|
||||
@@ -35,7 +32,7 @@ readonly class DownloadChapterHandler
|
||||
if (!$chapter) {
|
||||
$this->notificationService->sendUpdate(['status' => 'error', 'message' => 'Chapter not found.']);
|
||||
throw new BadRequestHttpException('Chapter not found');
|
||||
} elseif ($chapter->getCbzPath() !== null) {
|
||||
} elseif (null !== $chapter->getCbzPath()) {
|
||||
$this->notificationService->sendUpdate(['status' => 'error', 'message' => 'Chapter already scraped.']);
|
||||
throw new BadRequestHttpException('Chapter already downloaded');
|
||||
}
|
||||
@@ -44,11 +41,17 @@ readonly class DownloadChapterHandler
|
||||
$preferredSources = $manga->getPreferredSources()->toArray();
|
||||
$allSources = $this->contentSourceRepository->findAll();
|
||||
|
||||
$filteredSources = array_udiff($allSources, $preferredSources, function ($a, $b) {
|
||||
return $a->getId() - $b->getId();
|
||||
});
|
||||
// $filteredSources = array_udiff($allSources, $preferredSources, function ($a, $b) {
|
||||
// return $a->getId() - $b->getId();
|
||||
// });
|
||||
//
|
||||
// $sources = array_merge($preferredSources, $filteredSources);
|
||||
|
||||
$sources = array_merge($preferredSources, $filteredSources);
|
||||
if (count($preferredSources) > 0) {
|
||||
$sources = $preferredSources;
|
||||
} else {
|
||||
$sources = $allSources;
|
||||
}
|
||||
|
||||
$sources[] =
|
||||
(new ContentSource())
|
||||
@@ -57,19 +60,18 @@ readonly class DownloadChapterHandler
|
||||
->setChapterUrlFormat('at-home/server/%s')
|
||||
->setScrapingType('mangadex');
|
||||
|
||||
|
||||
// (new ContentSource())
|
||||
// ->setBaseUrl('https://lelscans.net')
|
||||
// ->setImageSelector('#image img')
|
||||
// ->setChapterUrlFormat('https://lelscans.net/scan-%s/%s')
|
||||
// ->setNextPageSelector('a[title="Suivant"]')
|
||||
// ->setScrapingType('html'),
|
||||
// (new ContentSource())
|
||||
// ->setBaseUrl('https://darkscans.net/')
|
||||
// ->setImageSelector('.reading-content img')
|
||||
// ->setChapterUrlFormat('https://darkscans.net/mangas/%s/chapter-%s/')
|
||||
// ->setNextPageSelector(null)
|
||||
// ->setScrapingType('html')
|
||||
// (new ContentSource())
|
||||
// ->setBaseUrl('https://lelscans.net')
|
||||
// ->setImageSelector('#image img')
|
||||
// ->setChapterUrlFormat('https://lelscans.net/scan-%s/%s')
|
||||
// ->setNextPageSelector('a[title="Suivant"]')
|
||||
// ->setScrapingType('html'),
|
||||
// (new ContentSource())
|
||||
// ->setBaseUrl('https://darkscans.net/')
|
||||
// ->setImageSelector('.reading-content img')
|
||||
// ->setChapterUrlFormat('https://darkscans.net/mangas/%s/chapter-%s/')
|
||||
// ->setNextPageSelector(null)
|
||||
// ->setScrapingType('html')
|
||||
|
||||
$scrapedSuccessfully = false;
|
||||
|
||||
@@ -78,10 +80,10 @@ readonly class DownloadChapterHandler
|
||||
$this->mangaScraperService->scrapeChapter($chapter, $source);
|
||||
$scrapedSuccessfully = true;
|
||||
break;
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->notificationService->sendUpdate([
|
||||
'status' => 'warning',
|
||||
'message' => 'An error occurred while scraping with source: ' . $source->getBaseUrl() . '. Trying next source...'
|
||||
'message' => 'An error occurred while scraping with source: '.$source->getBaseUrl().'. Trying next source...',
|
||||
]);
|
||||
} catch (GuzzleException $e) {
|
||||
|
||||
@@ -91,9 +93,9 @@ readonly class DownloadChapterHandler
|
||||
if (!$scrapedSuccessfully) {
|
||||
$this->notificationService->sendUpdate([
|
||||
'status' => 'error',
|
||||
'message' => 'All sources failed to scrape the chapter ' . $chapter->getManga()->getTitle() . ' ' . $chapter->getNumber() . '.'
|
||||
'message' => 'All sources failed to scrape the chapter '.$chapter->getManga()->getTitle().' '.$chapter->getNumber().'.',
|
||||
]);
|
||||
throw new Exception('All sources failed to scrape the chapter ' . $chapter->getManga()->getTitle() . ' ' . $chapter->getNumber() . '.');
|
||||
throw new \Exception('All sources failed to scrape the chapter '.$chapter->getManga()->getTitle().' '.$chapter->getNumber().'.');
|
||||
}
|
||||
|
||||
$this->notificationService->sendUpdate(['status' => 'success', 'message' => 'Chapter scraped successfully.']);
|
||||
|
||||
Reference in New Issue
Block a user