Added:
- Gettings chapters from non En/Fr sources - mercure fonctionne!
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Service\LelScansProviderService;
|
||||
use App\Service\MangaScraperService;
|
||||
use App\Service\NotificationService;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
@@ -17,7 +18,7 @@ use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
readonly class DownloadChapterHandler
|
||||
{
|
||||
public function __construct(
|
||||
private ChapterRepository $chapterRepository,
|
||||
private ChapterRepository $chapterRepository,
|
||||
private MangaScraperService $mangaScraperService,
|
||||
private NotificationService $notificationService
|
||||
)
|
||||
@@ -34,24 +35,52 @@ readonly class DownloadChapterHandler
|
||||
if (!$chapter) {
|
||||
$this->notificationService->sendUpdate('notification', ['status' => 'error', 'message' => 'Chapter not found.']);
|
||||
throw new BadRequestHttpException('Chapter not found');
|
||||
}elseif ($chapter->getLocalPath() !== null){
|
||||
} elseif ($chapter->getLocalPath() !== null) {
|
||||
$this->notificationService->sendUpdate('notification', ['status' => 'error', 'message' => 'Chapter already scraped.']);
|
||||
throw new BadRequestHttpException('Chapter already downloaded');
|
||||
}
|
||||
|
||||
$lelScanSource = new ContentSource();
|
||||
$lelScanSource->setBaseUrl('https://lelscans.net')
|
||||
->setImageSelector('#image img')
|
||||
->setChapterUrlFormat('https://lelscans.net/scan-%s/%s')
|
||||
->setNextPageSelector('a[title="Suivant"]')
|
||||
->setScrapingType('html');
|
||||
$sources = [
|
||||
(new ContentSource())
|
||||
->setBaseUrl('https://lelscans.net')
|
||||
->setImageSelector('#image img')
|
||||
->setChapterUrlFormat('https://lelscans.net/scan-%s/%s')
|
||||
->setNextPageSelector('a[title="Suivant"]')
|
||||
->setScrapingType('html'),
|
||||
|
||||
try {
|
||||
$this->mangaScraperService->scrapeChapter($chapter, $lelScanSource);
|
||||
} catch (Exception $e) {
|
||||
$this->notificationService->sendUpdate('notification', ['status' => 'error', 'message' => 'An error occurred while scraping the chapter.']);
|
||||
throw new Exception('Error scraping chapter: ' . $e->getMessage());
|
||||
(new ContentSource())
|
||||
->setBaseUrl('https://api.mangadex.org/')
|
||||
->setImageSelector('img')
|
||||
->setChapterUrlFormat('at-home/server/%s')
|
||||
->setScrapingType('mangadex')
|
||||
];
|
||||
|
||||
|
||||
$scrapedSuccessfully = false;
|
||||
|
||||
foreach ($sources as $source) {
|
||||
try {
|
||||
$this->mangaScraperService->scrapeChapter($chapter, $source);
|
||||
$scrapedSuccessfully = true;
|
||||
break;
|
||||
} catch (Exception $e) {
|
||||
$this->notificationService->sendUpdate('notification', [
|
||||
'status' => 'warning',
|
||||
'message' => 'An error occurred while scraping with source: ' . $source->getBaseUrl() . '. Trying next source...'
|
||||
]);
|
||||
} catch (GuzzleException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!$scrapedSuccessfully) {
|
||||
$this->notificationService->sendUpdate('notification', [
|
||||
'status' => 'error',
|
||||
'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() . '.');
|
||||
}
|
||||
|
||||
$this->notificationService->sendUpdate('notification', ['status' => 'success', 'message' => 'Chapter scraped successfully.']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user