Restrcutured the database, and updated pipeline to include cover art.
This commit is contained in:
@@ -20,14 +20,21 @@ public partial class MangaPipeline(MangaContext context) : IMangaPipeline
|
||||
SourceManga sourceManga = request.SourceManga;
|
||||
|
||||
Source source = await GetOrAddSourceAsync(sourceName);
|
||||
Manga manga = await GetOrAddMangaAsync(sourceManga);
|
||||
Manga manga = await GetOrAddMangaAsync(sourceManga, sourceUrl);
|
||||
MangaSource mangaSource = await AddMangaSourceAsync(sourceUrl, manga, source);
|
||||
|
||||
await AddSourceTitleAsync(mangaSource, sourceManga.Title, TitleType.Primary);
|
||||
await AddTitleAsync(manga, sourceManga.Title, TitleType.Primary);
|
||||
await AddDescriptionAsync(mangaSource, sourceManga.Description);
|
||||
|
||||
foreach (SourceMangaDescription description in sourceManga.Descriptions)
|
||||
{
|
||||
await AddSourceDescriptionAsync(mangaSource, description);
|
||||
//await AddDescriptionAsync(mangaSource, description);
|
||||
}
|
||||
|
||||
foreach (SourceMangaTitle alternateTitle in sourceManga.AlternateTitles)
|
||||
{
|
||||
await AddSourceTitleAsync(mangaSource, alternateTitle, TitleType.Secondary);
|
||||
await AddTitleAsync(manga, alternateTitle, TitleType.Secondary);
|
||||
}
|
||||
|
||||
@@ -46,6 +53,11 @@ public partial class MangaPipeline(MangaContext context) : IMangaPipeline
|
||||
await AddChapterAsync(mangaSource, chapter);
|
||||
}
|
||||
|
||||
foreach (string coverArtUrl in sourceManga.CoverArtUrls)
|
||||
{
|
||||
await AddCoverAsync(mangaSource, coverArtUrl);
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -66,10 +78,13 @@ public partial class MangaPipeline(MangaContext context) : IMangaPipeline
|
||||
return source;
|
||||
}
|
||||
|
||||
private async Task<Manga> GetOrAddMangaAsync(SourceManga sourceManga)
|
||||
private async Task<Manga> GetOrAddMangaAsync(SourceManga sourceManga, string sourceUrl)
|
||||
{
|
||||
//Manga? manga = await context.Mangas.FirstOrDefaultAsync(manga =>
|
||||
// manga.Titles.Any(mangaTitle => mangaTitle.Name == sourceManga.Title.Name));
|
||||
|
||||
Manga? manga = await context.Mangas.FirstOrDefaultAsync(manga =>
|
||||
manga.Titles.Any(mangaTitle => mangaTitle.Name == sourceManga.Title.Name));
|
||||
manga.Sources.Any(mangaSource => mangaSource.Url == sourceUrl));
|
||||
|
||||
if (manga != null)
|
||||
return manga;
|
||||
@@ -119,6 +134,49 @@ public partial class MangaPipeline(MangaContext context) : IMangaPipeline
|
||||
return mangaSource;
|
||||
}
|
||||
|
||||
private async Task AddSourceTitleAsync(MangaSource mangaSource, SourceMangaTitle sourceMangaTitle, TitleType titleType)
|
||||
{
|
||||
SourceTitle? sourceTitle = await context.SourceTitles.FirstOrDefaultAsync(mt =>
|
||||
mt.MangaSource == mangaSource && mt.Name == sourceMangaTitle.Name);
|
||||
|
||||
if (sourceTitle != null)
|
||||
return;
|
||||
|
||||
sourceTitle = new()
|
||||
{
|
||||
MangaSource = mangaSource,
|
||||
Name = sourceMangaTitle.Name,
|
||||
Language = sourceMangaTitle.Language,
|
||||
IsPrimary = titleType == TitleType.Primary
|
||||
};
|
||||
|
||||
context.SourceTitles.Add(sourceTitle);
|
||||
}
|
||||
|
||||
private async Task AddSourceDescriptionAsync(MangaSource mangaSource, SourceMangaDescription? sourceMangaDescription)
|
||||
{
|
||||
if (sourceMangaDescription == null)
|
||||
return;
|
||||
|
||||
SourceDescription? sourceDescription = await context.SourceDescriptions.FirstOrDefaultAsync(md =>
|
||||
md.MangaSource == mangaSource && md.Language == sourceMangaDescription.Language);
|
||||
|
||||
if (sourceDescription != null)
|
||||
{
|
||||
sourceDescription.Text = sourceMangaDescription.Name;
|
||||
return;
|
||||
}
|
||||
|
||||
sourceDescription = new()
|
||||
{
|
||||
MangaSource = mangaSource,
|
||||
Text = sourceMangaDescription.Name,
|
||||
Language = sourceMangaDescription.Language
|
||||
};
|
||||
|
||||
context.SourceDescriptions.Add(sourceDescription);
|
||||
}
|
||||
|
||||
private async Task AddTitleAsync(Manga manga, SourceMangaTitle sourceMangaTitle, TitleType titleType)
|
||||
{
|
||||
MangaTitle? mangaTitle = await context.MangaTitles.FirstOrDefaultAsync(mt =>
|
||||
@@ -138,24 +196,24 @@ public partial class MangaPipeline(MangaContext context) : IMangaPipeline
|
||||
context.MangaTitles.Add(mangaTitle);
|
||||
}
|
||||
|
||||
private async Task AddDescriptionAsync(MangaSource mangaSource, SourceMangaDescription? sourceMangaDescription)
|
||||
private async Task AddDescriptionAsync(Manga manga, SourceMangaDescription? sourceMangaDescription)
|
||||
{
|
||||
if (sourceMangaDescription == null)
|
||||
return;
|
||||
|
||||
MangaDescription? mangaDescription = await context.MangaDescriptions.FirstOrDefaultAsync(md =>
|
||||
md.MangaSource == mangaSource && md.Language == sourceMangaDescription.Language);
|
||||
md.Manga == manga && md.Language == sourceMangaDescription.Language);
|
||||
|
||||
if (mangaDescription != null)
|
||||
{
|
||||
mangaDescription.Name = sourceMangaDescription.Name;
|
||||
mangaDescription.Text = sourceMangaDescription.Name;
|
||||
return;
|
||||
}
|
||||
|
||||
mangaDescription = new()
|
||||
{
|
||||
MangaSource = mangaSource,
|
||||
Name = sourceMangaDescription.Name,
|
||||
Manga = manga,
|
||||
Text = sourceMangaDescription.Name,
|
||||
Language = sourceMangaDescription.Language
|
||||
};
|
||||
|
||||
@@ -278,6 +336,23 @@ public partial class MangaPipeline(MangaContext context) : IMangaPipeline
|
||||
return sourceChapter;
|
||||
}
|
||||
|
||||
private async Task AddCoverAsync(MangaSource mangaSource, string coverArtUrl)
|
||||
{
|
||||
SourceCover? sourceCover = await context.SourceCovers.FirstOrDefaultAsync(x =>
|
||||
x.MangaSource == mangaSource && x.Url == coverArtUrl);
|
||||
|
||||
if (sourceCover == null)
|
||||
{
|
||||
sourceCover = new()
|
||||
{
|
||||
MangaSource = mangaSource,
|
||||
Url = coverArtUrl
|
||||
};
|
||||
|
||||
context.SourceCovers.Add(sourceCover);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RunPagesAsync(MangaPagePipelineRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
SourceChapter? sourceChapter = await context.SourceChapters.FirstOrDefaultAsync(x => x.SourceChapterId == request.SourceChapterId, cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user