- début refonte graphique

- début MangaDbProvider
This commit is contained in:
Jérémy Guillot
2024-06-05 00:05:28 +02:00
parent 2f9ff7facb
commit 9595831aa3
23 changed files with 607 additions and 515 deletions

View File

@@ -2,10 +2,9 @@
namespace App\Service;
use App\Event\MangaScrapedEvent;
use App\EventSubscriber\MangaScrapedEvent;
use GuzzleHttp\Client;
use PHPUnit\Util\PHP\AbstractPhpProcess;
use Psr\Container\ContainerInterface;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
@@ -15,7 +14,7 @@ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class MangaScraperService
{
const IMG_BASE_DIR = '/public/manga-images';
const string IMG_BASE_DIR = '/public/manga-images';
private string $projectDir;
private EventDispatcherInterface $eventDispatcher;
@@ -28,9 +27,10 @@ class MangaScraperService
public function extractMangaPageData(string $html): array
{
$baseUrl = 'https://lelscans.net';
//pour éviter à PhpStorm de gueuler...
$selector = 'img';
$crawler = new Crawler($html);
$imgUrl = $crawler->filter('img')->attr('src');
$imgUrl = $crawler->filter($selector)->attr('src');
$nextLink = $crawler->filter('a[title="Suivant"]');
if (!preg_match('/^https?:\/\//', $imgUrl)) {
@@ -54,7 +54,10 @@ class MangaScraperService
];
}
public function scrapeMangaChapter(string $chapterUrl, string $mangaTitle, float $chapterNumber): array|bool
/**
* @throws GuzzleException
*/
public function scrapeMangaChapter(string $chapterUrl, string $mangaTitle, float $chapterNumber): array|bool
{
if(!$this->isChapterAvailable($chapterUrl, $chapterNumber)){
return false;
@@ -101,7 +104,10 @@ class MangaScraperService
return $pageData;
}
private function fetchHtml(string $url): string
/**
* @throws GuzzleException
*/
private function fetchHtml(string $url): string
{
$client = new Client();
$response = $client->get($url);
@@ -109,7 +115,10 @@ class MangaScraperService
return (string) $response->getBody();
}
private function downloadAndSaveImage(string $imageUrl, string $destinationPath): void
/**
* @throws GuzzleException
*/
private function downloadAndSaveImage(string $imageUrl, string $destinationPath): void
{
$client = new Client();
$response = $client->get($imageUrl);
@@ -117,7 +126,10 @@ class MangaScraperService
file_put_contents($destinationPath, $response->getBody()->getContents());
}
private function isChapterAvailable(string $chapterUrl, float $chapterNumber): bool
/**
* @throws GuzzleException
*/
private function isChapterAvailable(string $chapterUrl, float $chapterNumber): bool
{
$html = $this->fetchHtml($chapterUrl);
$crawler = new Crawler($html);
@@ -142,4 +154,4 @@ class MangaScraperService
return true;
}
}
}