2
0
Tranga/Tranga/Jobs/DownloadChapter.cs

46 lines
1.6 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; }
2023-11-02 15:18:41 +01:00
public DownloadChapter(GlobalBase clone, MangaConnector connector, Chapter chapter, DateTime lastExecution, string? parentJobId = null) : base(clone, JobType.DownloadChapterJob, connector, lastExecution, parentJobId: parentJobId)
{
this.chapter = chapter;
}
2023-08-04 14:51:40 +02:00
2023-11-02 15:18:41 +01:00
public DownloadChapter(GlobalBase clone, MangaConnector connector, Chapter chapter, string? parentJobId = null) : base(clone, JobType.DownloadChapterJob, connector, 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
}
2023-08-04 14:51:40 +02:00
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal()
{
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>();
}
}