Convertion des images webp et png vers jpeg

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2024-09-30 22:16:20 +02:00
parent 21b2adfa07
commit 5f15d14ae1
13 changed files with 226 additions and 158 deletions

View File

@@ -18,19 +18,20 @@ readonly class MangadexProvider implements MetadataProviderInterface
public function search(?string $title): Collection
{
if ($title === null) {
if (null === $title) {
return new ArrayCollection();
}
try {
$results = $this->client->get('/manga', [
'title' => $title,
'contentRating' => ['safe', 'suggestive'],
'contentRating' => ['safe', 'suggestive', 'erotica'],
'includes' => ['cover_art', 'author'],
'limit' => 25
'limit' => 50,
]);
} catch (\Exception $e) {
$this->notificationService->sendUpdate('notification', ['status' => 'error', 'message' => 'An error occurred while fetching data from Mangadex.']);
return new ArrayCollection();
}
@@ -51,32 +52,34 @@ readonly class MangadexProvider implements MetadataProviderInterface
$mangas[count($mangas) - 1]->setGenres($tags);
foreach ($result['relationships'] as $relationship) {
if ($relationship['type'] === 'author') {
if ('author' === $relationship['type']) {
$mangas[count($mangas) - 1]->setAuthor($relationship['attributes']['name']);
}
if ($relationship['type'] === 'cover_art') {
$mangas[count($mangas) - 1]->setImageUrl('https://mangadex.org/covers/' . $result['id'] . '/' . $relationship['attributes']['fileName']);
if ('cover_art' === $relationship['type']) {
$mangas[count($mangas) - 1]->setImageUrl('https://mangadex.org/covers/'.$result['id'].'/'.$relationship['attributes']['fileName']);
}
}
}
$test = array_map(fn($manga) => $manga->getExternalId(), $mangas);
$test = array_map(fn ($manga) => $manga->getExternalId(), $mangas);
$ratings = $this->client->get('/statistics/manga', [
'manga' => $test
'manga' => $test,
]);
foreach ($mangas as $manga) {
$manga->setRating($ratings['statistics'][$manga->getExternalId()]['rating']['average']);
}
usort($mangas, fn ($a, $b) => $b->getRating() <=> $a->getRating());
return new ArrayCollection($mangas);
}
public function getFeed(Manga $manga): array
{
if ($manga->getExternalId() === null) {
if (null === $manga->getExternalId()) {
return [];
}
@@ -90,7 +93,7 @@ readonly class MangadexProvider implements MetadataProviderInterface
} else {
break;
}
$page++;
++$page;
} while (count($chapters) < $results['total']);
return $this->getChaptersFromFeed($chapters, $manga);
@@ -98,7 +101,7 @@ readonly class MangadexProvider implements MetadataProviderInterface
public function getLastFeed(Manga $manga, int $limit = 100): array
{
if ($manga->getExternalId() === null) {
if (null === $manga->getExternalId()) {
return [];
}
@@ -111,6 +114,7 @@ readonly class MangadexProvider implements MetadataProviderInterface
}
} catch (\Exception $e) {
$this->notificationService->sendUpdate(['status' => 'error', 'message' => 'An error occurred while fetching recent chapters from Mangadex.']);
return [];
}
@@ -120,14 +124,15 @@ readonly class MangadexProvider implements MetadataProviderInterface
private function getFeedWithPagination(string $externalId, int $page, int $limit = 500, string $order = 'asc'): array
{
try {
$response = $this->client->get('/manga/' . $externalId . '/feed', [
$response = $this->client->get('/manga/'.$externalId.'/feed', [
'limit' => $limit,
'translatedLanguage' => ['en', 'fr'],
'order' => ['chapter' => $order],
'offset' => $page * $limit
'offset' => $page * $limit,
]);
} catch (\Exception $e) {
$this->notificationService->sendUpdate(['status' => 'error', 'message' => 'An error occurred while fetching data from Mangadex.']);
return [];
}
@@ -136,49 +141,44 @@ readonly class MangadexProvider implements MetadataProviderInterface
public function getMangaAggregate(Manga $manga): array
{
if ($manga->getExternalId() === null) {
if (null === $manga->getExternalId()) {
return [];
}
try {
$response = $this->client->get('/manga/' . $manga->getExternalId() . '/aggregate');
$response = $this->client->get('/manga/'.$manga->getExternalId().'/aggregate');
} catch (\Exception $e) {
// $this->notificationService->sendUpdate(['status' => 'error', 'message' => 'An error occurred while fetching data from Mangadex.']);
// $this->notificationService->sendUpdate(['status' => 'error', 'message' => 'An error occurred while fetching data from Mangadex.']);
return [];
}
$chapterEntities = [];
if ($response['result'] === 'ok') {
if ('ok' === $response['result']) {
foreach ($response['volumes'] as $volume) {
$volumeNumber = $volume['volume'] === 'none' ? 0 : (float)$volume['volume'];
$volumeNumber = 'none' === $volume['volume'] ? 0 : (float) $volume['volume'];
foreach ($volume['chapters'] as $chapter) {
$chapterEntity = new Chapter();
$chapterEntity->setNumber((float)$chapter['chapter'])
->setTitle('Chapter ' . $chapter['chapter'])
$chapterEntity->setNumber((float) $chapter['chapter'])
->setTitle('Chapter '.$chapter['chapter'])
->setVolume($volumeNumber)
->setExternalId('');
$chapterEntities[] = $chapterEntity;
// $manga->addChapter($chapterEntity);
// $manga->addChapter($chapterEntity);
}
}
}
return $chapterEntities;
}
/**
* @param mixed $chapters
* @param Manga $manga
* @param array $chapterEntities
* @return array
*/
public function getChaptersFromFeed(mixed $chapters, Manga $manga): array
{
$chapterEntities = [];
$uniqueChapterNumbers = [];
foreach ($chapters as $result) {
$chapterNumber = (float)$result['attributes']['chapter'];
$chapterNumber = (float) $result['attributes']['chapter'];
// Vérifiez si le chapitre existe déjà dans la base de données
$chapterExists = $manga->getChapters()->exists(function ($key, $existingChapter) use ($chapterNumber) {
@@ -194,7 +194,7 @@ readonly class MangadexProvider implements MetadataProviderInterface
$chapter = new Chapter();
$chapter->setNumber($chapterNumber)
->setTitle($result['attributes']['title'])
->setVolume((int)$result['attributes']['volume'] ?? null)
->setVolume((int) $result['attributes']['volume'] ?? null)
->setExternalId($result['id']);
$chapterEntities[] = $chapter;
@@ -219,8 +219,9 @@ readonly class MangadexProvider implements MetadataProviderInterface
if (empty($allChapters)) {
$this->notificationService->sendUpdate([
'status' => 'error',
'message' => 'No chapters found for this manga.'
'message' => 'No chapters found for this manga.',
]);
return [];
}
@@ -247,6 +248,5 @@ readonly class MangadexProvider implements MetadataProviderInterface
{
$existingChapter->setVolume($newChapter->getVolume());
$existingChapter->setExternalId($newChapter->getExternalId());
}
}