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

@@ -8,4 +8,5 @@ public interface IMangaDexClient
Task<MangaDexResponse?> GetMangaAsync(Guid mangaGuid, CancellationToken cancellationToken);
Task<MangaDexResponse?> GetFeedAsync(Guid mangaGuid, CancellationToken cancellationToken);
Task<MangaDexChapterResponse?> GetChapterAsync(Guid chapterGuid, CancellationToken cancellationToken);
Task<MangaDexResponse?> GetCoverArtAsync(Guid mangaGuid, CancellationToken cancellationToken);
}

View File

@@ -69,5 +69,10 @@ namespace MangaReader.Core.Sources.MangaDex.Api
return JsonSerializer.Deserialize<MangaDexChapterResponse>(response, _jsonSerializerOptions);
}
public async Task<MangaDexResponse?> GetCoverArtAsync(Guid mangaGuid, CancellationToken cancellationToken)
{
return await GetAsync($"https://api.mangadex.org/cover?order[volume]=asc&manga[]={mangaGuid}&limit=100&offset=0", cancellationToken);
}
}
}

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];
}
}