Added MangaDex cover art logic. Added "Search Manga" test for MangaDex client.

This commit is contained in:
2025-05-28 08:52:40 -04:00
parent 4e5be6c910
commit 1348684144
8 changed files with 362 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ public class MangaDexMetadataProvider(IMangaDexClient mangaDexClient) : IMangaMe
MangaAttributes mangaAttributes = mangaEntity.Attributes;
List<MangaDexEntity> mangaRelationships = mangaEntity.Relationships;
MangaDexResponse? mangaDexFeedResponse = await mangaDexClient.GetFeedAsync(mangaGuid, cancellationToken);
MangaDexResponse? coverArtResponse = await mangaDexClient.GetCoverArtAsync(mangaGuid, cancellationToken);
return new SourceManga()
{
@@ -31,7 +32,8 @@ public class MangaDexMetadataProvider(IMangaDexClient mangaDexClient) : IMangaMe
AlternateTitles = GetAlternateTitles(mangaAttributes),
Genres = GetGenres(mangaAttributes),
Contributors = GetContributors(mangaRelationships),
Chapters = GetChapters(mangaDexFeedResponse)
Chapters = GetChapters(mangaDexFeedResponse),
CoverArt = GetCoverArt(mangaGuid, coverArtResponse)
};
}
@@ -181,4 +183,25 @@ public class MangaDexMetadataProvider(IMangaDexClient mangaDexClient) : IMangaMe
return chapters;
}
private static string[] GetCoverArt(Guid mangaGuid, MangaDexResponse? coverArtResponse)
{
if (coverArtResponse == null || coverArtResponse is not MangaDexCollectionResponse collectionResponse)
return [];
List<string> coverArtUrls = [];
CoverArtEntity[] coverArtEntities = [.. collectionResponse.Data.Where(entity => entity is CoverArtEntity).Cast<CoverArtEntity>()];
foreach (CoverArtEntity coverArtEntity in coverArtEntities)
{
if (coverArtEntity.Attributes == null || string.IsNullOrWhiteSpace(coverArtEntity.Attributes.FileName))
continue;
string url = $"https://mangadex.org/covers/{mangaGuid}/{coverArtEntity.Attributes.FileName}";
coverArtUrls.Add(url);
}
return [.. coverArtUrls];
}
}