2
0

Add Job UpdateMetadata --> untested!

This commit is contained in:
glax 2023-11-01 14:17:11 +01:00
parent 0a5ded2036
commit 963ad375e8
2 changed files with 64 additions and 1 deletions

View File

@ -4,7 +4,7 @@ namespace Tranga.Jobs;
public class DownloadNewChapters : Job public class DownloadNewChapters : Job
{ {
public Manga manga { get; init; } public Manga manga { get; set; }
public string translatedLanguage { get; init; } public string translatedLanguage { get; init; }
public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Manga manga, DateTime lastExecution, public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Manga manga, DateTime lastExecution,

View File

@ -0,0 +1,63 @@
using Tranga.MangaConnectors;
namespace Tranga.Jobs;
public class UpdateMetadata : Job
{
private Manga manga { get; set; }
private JobBoss jobBoss { get; init; }
public UpdateMetadata(GlobalBase clone, MangaConnector connector, Manga manga, JobBoss jobBoss, DateTime lastExecution, string? parentJobId = null) : base(clone, connector, lastExecution, parentJobId: parentJobId)
{
this.manga = manga;
this.jobBoss = jobBoss;
}
public UpdateMetadata(GlobalBase clone, MangaConnector connector, Manga manga, JobBoss jobBoss, string? parentJobId = null) : base(clone, connector, parentJobId: parentJobId)
{
this.manga = manga;
this.jobBoss = jobBoss;
}
protected override string GetId()
{
return $"{GetType()}-{manga.internalId}";
}
public override string ToString()
{
return $"{id} Manga: {manga}";
}
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal()
{
if(manga.websiteUrl is null)
{
Log($"Legacy manga {manga}");
return Array.Empty<Job>();
}
if (parentJobId is null)
{
Log($"Missing parentJob {this}");
return Array.Empty<Job>();
}
Manga? possibleUpdatedManga = mangaConnector.GetMangaFromUrl(manga.websiteUrl);
if (possibleUpdatedManga is { } updatedManga)
{
cachedPublications.Remove(this.manga);
this.manga = updatedManga;
cachedPublications.Add(updatedManga);
this.manga.SaveSeriesInfoJson(settings.downloadLocation, true);
DownloadNewChapters dncJob = this.jobBoss.GetJobById(this.parentJobId) as DownloadNewChapters ??
throw new Exception("Jobtype has to be DownloadNewChapters");
dncJob.manga = updatedManga;
}
else
{
Log($"Could not find Manga {manga}");
return Array.Empty<Job>();
}
return Array.Empty<Job>();
}
}