Skip to content

Commit

Permalink
Add Job UpdateMetadata --> untested!
Browse files Browse the repository at this point in the history
  • Loading branch information
C9Glax committed Nov 1, 2023
1 parent 0a5ded2 commit 963ad37
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Tranga/Jobs/DownloadNewChapters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 63 additions & 0 deletions Tranga/Jobs/UpdateMetadata.cs
Original file line number Diff line number Diff line change
@@ -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>();
}
}

0 comments on commit 963ad37

Please sign in to comment.