diff --git a/Tranga/Jobs/DownloadNewChapters.cs b/Tranga/Jobs/DownloadNewChapters.cs index 9f2268f..8f02c69 100644 --- a/Tranga/Jobs/DownloadNewChapters.cs +++ b/Tranga/Jobs/DownloadNewChapters.cs @@ -4,7 +4,7 @@ namespace Tranga.Jobs; public class DownloadNewChapters : Job { - public Manga manga { get; init; } + public Manga manga { get; set; } public string translatedLanguage { get; init; } public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Manga manga, DateTime lastExecution, diff --git a/Tranga/Jobs/UpdateMetadata.cs b/Tranga/Jobs/UpdateMetadata.cs new file mode 100644 index 0000000..2dbb625 --- /dev/null +++ b/Tranga/Jobs/UpdateMetadata.cs @@ -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 ExecuteReturnSubTasksInternal() + { + if(manga.websiteUrl is null) + { + Log($"Legacy manga {manga}"); + return Array.Empty(); + } + if (parentJobId is null) + { + Log($"Missing parentJob {this}"); + return Array.Empty(); + } + 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(); + } + return Array.Empty(); + } +} \ No newline at end of file