feat: ajout de la gestion des slugs alternatifs pour le scraping des chapitres, mise à jour du service de scraping pour essayer plusieurs slugs, et amélioration de la configuration des services pour le dépôt de chapitres et le service de fichiers.

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-07-03 18:41:13 +02:00
parent 9255509042
commit a6ca8a2c9a
4 changed files with 94 additions and 59 deletions

View File

@@ -120,3 +120,16 @@ services:
App\Domain\Manga\Infrastructure\EventListener\MangaCreatedListener: App\Domain\Manga\Infrastructure\EventListener\MangaCreatedListener:
tags: tags:
- { name: messenger.message_handler } - { name: messenger.message_handler }
# Chapter Repository
App\Domain\Manga\Domain\Contract\Repository\ChapterRepositoryInterface:
alias: App\Domain\Manga\Infrastructure\Persistence\Repository\LegacyChapterRepository
# File Service
App\Domain\Manga\Domain\Contract\Service\FileServiceInterface:
alias: App\Domain\Manga\Infrastructure\Service\FileService
# File Service Configuration
App\Domain\Manga\Infrastructure\Service\FileService:
arguments:
$cbzStoragePath: '%kernel.project_dir%/public/cbz'

View File

@@ -65,6 +65,10 @@ readonly class ScrapeChapterHandler
$lastException = null; $lastException = null;
foreach ($sources as $source) { foreach ($sources as $source) {
// Préparer la liste des slugs à essayer : slug principal + slugs alternatifs
$slugsToTry = array_merge([$manga->getSlug()], $manga->getAlternativeSlugs());
foreach ($slugsToTry as $slug) {
$job = new ScrapingJob( $job = new ScrapingJob(
Uuid::uuid4()->toString(), Uuid::uuid4()->toString(),
$chapter->mangaId, $chapter->mangaId,
@@ -72,8 +76,9 @@ readonly class ScrapeChapterHandler
$source->getId()->getValue() $source->getId()->getValue()
); );
// Ajout de l'ID du chapitre dans le contexte du job // Ajout de l'ID du chapitre et du slug dans le contexte du job
$job->context['chapterId'] = $command->chapterId; $job->context['chapterId'] = $command->chapterId;
$job->context['slug'] = $slug;
$job->start(); $job->start();
$this->jobRepository->save($job); $this->jobRepository->save($job);
@@ -81,10 +86,10 @@ readonly class ScrapeChapterHandler
try { try {
$this->entityManager->beginTransaction(); $this->entityManager->beginTransaction();
// 5. Scraping des URLs // 5. Scraping des URLs avec le slug courant
$scrapingRequest = new ScrapingRequest( $scrapingRequest = new ScrapingRequest(
'html', 'html',
$source->buildChapterUrl($manga->getSlug(), $chapter->chapterNumber), $source->buildChapterUrl($slug, $chapter->chapterNumber),
$source->getScrappingParameters() $source->getScrappingParameters()
); );
@@ -124,7 +129,7 @@ readonly class ScrapeChapterHandler
// 9. Nettoyage // 9. Nettoyage
$tempDir->cleanup(); $tempDir->cleanup();
// Scraping réussi, pas besoin d'essayer d'autres sources // Scraping réussi, pas besoin d'essayer d'autres slugs ni d'autres sources
$success = true; $success = true;
break; break;
@@ -138,7 +143,13 @@ readonly class ScrapeChapterHandler
$lastException = $e; $lastException = $e;
// Continuer avec la source suivante // Continuer avec le slug suivant pour cette source
}
}
// Si le scraping a réussi avec un des slugs, sortir de la boucle des sources
if ($success) {
break;
} }
} }

View File

@@ -6,6 +6,7 @@ class Manga
{ {
/** /**
* @param string[] $preferredSources * @param string[] $preferredSources
* @param string[] $alternativeSlugs
*/ */
public function __construct( public function __construct(
private readonly string $id, private readonly string $id,
@@ -15,6 +16,7 @@ class Manga
private readonly string $author, private readonly string $author,
private readonly string $publicationYear, private readonly string $publicationYear,
private readonly array $preferredSources = [], private readonly array $preferredSources = [],
private readonly array $alternativeSlugs = [],
) { ) {
} }
@@ -63,4 +65,12 @@ class Manga
{ {
return !empty($this->preferredSources); return !empty($this->preferredSources);
} }
/**
* @return string[]
*/
public function getAlternativeSlugs(): array
{
return $this->alternativeSlugs;
}
} }

View File

@@ -42,6 +42,7 @@ readonly class LegacyMangaRepository implements MangaRepositoryInterface
$mangaEntity->getAuthor() ?? '', $mangaEntity->getAuthor() ?? '',
(string) ($mangaEntity->getPublicationYear() ?? ''), (string) ($mangaEntity->getPublicationYear() ?? ''),
$preferredSourceIds, $preferredSourceIds,
$mangaEntity->getAlternativeSlugs() ?? []
); );
} }