Finished MangaDexMetadataProvider logic.

This commit is contained in:
2025-05-27 23:49:38 -04:00
parent df1e8a2360
commit 4e5be6c910
15 changed files with 563 additions and 93 deletions

View File

@@ -0,0 +1,252 @@
using MangaReader.Core.Metadata;
using MangaReader.Core.Sources.MangaDex.Api;
using MangaReader.Core.Sources.MangaDex.Metadata;
using NSubstitute;
using Shouldly;
namespace MangaReader.Tests.Sources.MangaDex.Metadata;
public class MangaDexMetadataTests
{
[Fact]
public async Task Get_Manga()
{
MangaDexEntityResponse entityResponse = new()
{
Result = "ok",
Response = "entity",
Data = new MangaEntity()
{
Id = new Guid("ee96e2b7-9af2-4864-9656-649f4d3b6fec"),
Type = "manga",
Attributes = new()
{
Title =
{
{ "en", "Gals Cant Be Kind to Otaku!?" }
},
AltTitles =
[
new()
{
{ "ja", "オタクに優しいギャルはいない!?" }
},
new()
{
{ "ja-ro", "Otaku ni Yasashii Gal wa Inai!?" }
},
new()
{
{ "ja-ro", "Otaku ni Yasashii Gyaru ha Inai!?" }
},
new()
{
{ "en", "Gal Can't Be Kind to Otaku!?" }
},
new()
{
{ "en", "Gals Can't Be Kind To A Geek!?" }
}
],
Tags =
[
new()
{
Id = new Guid("423e2eae-a7a2-4a8b-ac03-a8351462d71d"),
Type = "tag",
Attributes = new()
{
Group = "genre",
Name =
{
{ "en", "Romance" }
}
}
},
new()
{
Id = new Guid("4d32cc48-9f00-4cca-9b5a-a839f0764984"),
Type = "tag",
Attributes = new()
{
Group = "genre",
Name =
{
{ "en", "Comedy" }
}
}
},
new()
{
Id = new Guid("caaa44eb-cd40-4177-b930-79d3ef2afe87"),
Type = "tag",
Attributes = new()
{
Group = "theme",
Name =
{
{ "en", "School Life" }
}
}
},
new()
{
Id = new Guid("e5301a23-ebd9-49dd-a0cb-2add944c7fe9"),
Type = "tag",
Attributes = new()
{
Group = "genre",
Name =
{
{ "en", "Slice of Life" }
}
}
},
new()
{
Id = new Guid("fad12b5e-68ba-460e-b933-9ae8318f5b65"),
Type = "tag",
Attributes = new()
{
Group = "theme",
Name =
{
{ "en", "Gyaru" }
}
}
}
],
},
Relationships =
[
new AuthorEntity()
{
Id = new Guid(),
Type = "author",
Attributes = new()
{
Name = "Norishiro-chan"
}
},
new ArtistEntity()
{
Id = new Guid(),
Type = "artist",
Attributes = new()
{
Name = "Sakana Uozimi"
}
}
]
}
};
MangaDexCollectionResponse collectionResponse = new()
{
Result = "ok",
Response = "collection",
Data =
[
new ChapterEntity()
{
Id = new Guid("46084762-855c-46dd-a7b6-66e5cd15604d"),
Type = "chapter",
Attributes = new()
{
TranslatedLanguage = "en",
Volume = null,
Chapter = "69",
Title = "Otaku & Gyaru & Playing Couple"
}
},
new ChapterEntity()
{
Id = new Guid("7521d1eb-0caf-4c4d-b96a-adc816ada3ec"),
Type = "chapter",
Attributes = new()
{
TranslatedLanguage = "en",
Volume = "9",
Chapter = "68",
Title = "Otaku & Gyaru & A Couple Date"
}
},
new ChapterEntity()
{
Id = new Guid("b5206e9b-6e3e-4ef0-aa62-381fd0ff75a5"),
Type = "chapter",
Attributes = new()
{
TranslatedLanguage = "en",
Volume = "2",
Chapter = "8.1",
Title = "Otaku & Gyaru & Protegee"
}
}
]
};
IMangaDexClient mangaDexClient = Substitute.For<IMangaDexClient>();
mangaDexClient.GetMangaAsync(Arg.Any<Guid>(), CancellationToken.None)
.Returns(entityResponse);
mangaDexClient.GetFeedAsync(Arg.Any<Guid>(), CancellationToken.None)
.Returns(collectionResponse);
MangaDexMetadataProvider metadataProvider = new(mangaDexClient);
SourceManga? sourceManga = await metadataProvider.GetMangaAsync("https://mangadex.org/title/ee96e2b7-9af2-4864-9656-649f4d3b6fec/gals-can-t-be-kind-to-otaku", CancellationToken.None);
sourceManga.ShouldNotBeNull();
sourceManga.Title.ShouldBe("Gals Cant Be Kind to Otaku!?");
sourceManga.AlternateTitles.Count.ShouldBe(5);
sourceManga.AlternateTitles[0].Title.ShouldBe("オタクに優しいギャルはいない!?");
sourceManga.AlternateTitles[0].Language.ShouldBe(SourceMangaLanguage.Japanese);
sourceManga.AlternateTitles[1].Title.ShouldBe("Otaku ni Yasashii Gal wa Inai!?");
sourceManga.AlternateTitles[1].Language.ShouldBe(SourceMangaLanguage.Romanji);
sourceManga.AlternateTitles[2].Title.ShouldBe("Otaku ni Yasashii Gyaru ha Inai!?");
sourceManga.AlternateTitles[2].Language.ShouldBe(SourceMangaLanguage.Romanji);
sourceManga.AlternateTitles[3].Title.ShouldBe("Gal Can't Be Kind to Otaku!?");
sourceManga.AlternateTitles[3].Language.ShouldBe(SourceMangaLanguage.English);
sourceManga.AlternateTitles[4].Title.ShouldBe("Gals Can't Be Kind To A Geek!?");
sourceManga.AlternateTitles[4].Language.ShouldBe(SourceMangaLanguage.English);
sourceManga.Genres.Count.ShouldBe(5);
sourceManga.Genres[0].ShouldBe("Romance");
sourceManga.Genres[1].ShouldBe("Comedy");
sourceManga.Genres[2].ShouldBe("School Life");
sourceManga.Genres[3].ShouldBe("Slice of Life");
sourceManga.Genres[4].ShouldBe("Gyaru");
sourceManga.Contributors.Length.ShouldBe(2);
sourceManga.Contributors[0].Name.ShouldBe("Norishiro-chan");
sourceManga.Contributors[0].Role.ShouldBe(SourceMangaContributorRole.Author);
sourceManga.Contributors[1].Name.ShouldBe("Sakana Uozimi");
sourceManga.Contributors[1].Role.ShouldBe(SourceMangaContributorRole.Artist);
sourceManga.Chapters.Count.ShouldBe(3);
sourceManga.Chapters[0].Volume.ShouldBeNull();
sourceManga.Chapters[0].Number.ShouldBe(69);
sourceManga.Chapters[0].Title.ShouldBe("Otaku & Gyaru & Playing Couple");
sourceManga.Chapters[0].Url.ShouldBe("https://mangadex.org/chapter/46084762-855c-46dd-a7b6-66e5cd15604d");
sourceManga.Chapters[1].Volume.ShouldBe(9);
sourceManga.Chapters[1].Number.ShouldBe(68);
sourceManga.Chapters[1].Title.ShouldBe("Otaku & Gyaru & A Couple Date");
sourceManga.Chapters[1].Url.ShouldBe("https://mangadex.org/chapter/7521d1eb-0caf-4c4d-b96a-adc816ada3ec");
sourceManga.Chapters[2].Volume.ShouldBe(2);
sourceManga.Chapters[2].Number.ShouldBe(8.1f);
sourceManga.Chapters[2].Title.ShouldBe("Otaku & Gyaru & Protegee");
sourceManga.Chapters[2].Url.ShouldBe("https://mangadex.org/chapter/b5206e9b-6e3e-4ef0-aa62-381fd0ff75a5");
}
}

View File

@@ -53,13 +53,13 @@ public class NatoMangaWebCrawlerTests
manga.Chapters[0].Url.ShouldBe("https://www.natomanga.com/manga/gal-cant-be-kind-to-otaku/chapter-69");
manga.Chapters[0].Number.ShouldBe(69);
manga.Chapters[0].Name.ShouldBe("Chapter 69");
manga.Chapters[0].Title.ShouldBe("Chapter 69");
manga.Chapters[0].Views.ShouldBe(8146);
//manga.Chapters[0].UploadDate.ShouldBe(new DateTime(2025, 4, 23, 17, 17, 0));
//manga.Chapters[235].URL.ShouldBe("https://chapmanganato.to/manga-hf984788/chapter-0.1");
//manga.Chapters[235].Number.ShouldBe(0.1f);
//manga.Chapters[235].Name.ShouldBe("Vol.0 Chapter : Oneshot");
//manga.Chapters[235].Title.ShouldBe("Vol.0 Chapter : Oneshot");
//manga.Chapters[235].Views.ShouldBe(232_200);
//manga.Chapters[235].UploadDate.ShouldBe(new DateTime(2021, 8, 24, 1, 8, 0));
}

View File

@@ -2,6 +2,8 @@
using MangaReader.Core.Metadata;
using MangaReader.Core.Sources.MangaNato.Metadata;
using Shouldly;
using System.Data;
using System.Xml.Linq;
namespace MangaReader.Tests.WebCrawlers;
@@ -39,13 +41,19 @@ public class UnitTest1
manga.Title.ShouldBe("Please Go Home, Akutsu-San!");
manga.AlternateTitles.ShouldBe([
manga.AlternateTitles.Select(x => x.Title).ShouldBe([
"Kaette kudasai! Akutsu-san",
"Yankee Musume",
"ヤンキー娘",
"帰ってください! 阿久津さん"]);
manga.Authors.ShouldBe(["Nagaoka Taichi"]);
SourceMangaContributor[] expectedContributors =
[
new() { Name = "Nagaoka Taichi", Role = SourceMangaContributorRole.Author }
];
manga.Contributors.ShouldBeEquivalentTo(expectedContributors);
manga.Status.ShouldBe(MangaStatus.Ongoing);
manga.Genres.ShouldBe(["Comedy", "Romance", "School life"]);
manga.UpdateDate.ShouldBe(new DateTime(2024, 9, 26, 0, 12, 0));
@@ -61,13 +69,13 @@ public class UnitTest1
manga.Chapters[0].Url.ShouldBe("https://chapmanganato.to/manga-hf984788/chapter-186");
manga.Chapters[0].Number.ShouldBe(186);
manga.Chapters[0].Name.ShouldBe("Chapter 186");
manga.Chapters[0].Title.ShouldBe("Chapter 186");
manga.Chapters[0].Views.ShouldBe(37_900);
manga.Chapters[0].UploadDate.ShouldBe(new DateTime(2024, 9, 26, 0, 9, 0));
manga.Chapters[235].Url.ShouldBe("https://chapmanganato.to/manga-hf984788/chapter-0.1");
manga.Chapters[235].Number.ShouldBe(0.1f);
manga.Chapters[235].Name.ShouldBe("Vol.0 Chapter : Oneshot");
manga.Chapters[235].Title.ShouldBe("Vol.0 Chapter : Oneshot");
manga.Chapters[235].Views.ShouldBe(232_200);
manga.Chapters[235].UploadDate.ShouldBe(new DateTime(2021, 8, 24, 1, 8, 0));
}