Added MangaDex cover art logic. Added "Search Manga" test for MangaDex client.
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user