2
0
Tranga/Tranga/Jobs/DownloadChapter.cs

58 lines
1.8 KiB
C#
Raw Normal View History

using System.Net;
using Tranga.MangaConnectors;
2023-08-04 14:51:40 +02:00
namespace Tranga.Jobs;
public class DownloadChapter : Job
{
public Chapter chapter { get; init; }
public DownloadChapter(GlobalBase clone, Chapter chapter, DateTime lastExecution, string? parentJobId = null) : base(clone, JobType.DownloadChapterJob, lastExecution, parentJobId: parentJobId)
{
this.chapter = chapter;
}
2023-08-04 14:51:40 +02:00
public DownloadChapter(GlobalBase clone, Chapter chapter, string? parentJobId = null) : base(clone, JobType.DownloadChapterJob, parentJobId: parentJobId)
2023-08-04 14:51:40 +02:00
{
this.chapter = chapter;
}
2023-08-26 02:40:24 +02:00
protected override string GetId()
{
return $"{GetType()}-{chapter.parentManga.internalId}-{chapter.chapterNumber}";
2023-08-26 02:40:24 +02:00
}
2023-08-04 14:51:40 +02:00
2023-08-27 01:21:23 +02:00
public override string ToString()
{
2023-09-19 16:30:55 +02:00
return $"{id} Chapter: {chapter}";
2023-08-27 01:21:23 +02:00
}
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal(JobBoss jobBoss)
2023-08-04 14:51:40 +02:00
{
Task downloadTask = new(delegate
{
2023-09-19 19:42:50 +02:00
mangaConnector.CopyCoverFromCacheToDownloadLocation(chapter.parentManga);
HttpStatusCode success = mangaConnector.DownloadChapter(chapter, this.progressToken);
2023-10-27 14:07:15 +02:00
chapter.parentManga.UpdateLatestDownloadedChapter(chapter);
if (success == HttpStatusCode.OK)
{
UpdateLibraries();
SendNotifications("Chapter downloaded", $"{chapter.parentManga.sortName} - {chapter.chapterNumber}");
}
2023-08-04 14:51:40 +02:00
});
downloadTask.Start();
return Array.Empty<Job>();
}
protected override MangaConnector GetMangaConnector()
{
return chapter.parentManga.mangaConnector;
}
public override bool Equals(object? obj)
{
if (obj is not DownloadChapter otherJob)
return false;
return otherJob.chapter.Equals(this.chapter);
}
2023-08-04 14:51:40 +02:00
}