2023-09-20 14:40:03 +02:00
|
|
|
|
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-09-02 16:11:56 +02:00
|
|
|
|
|
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)
|
2023-09-02 16:11:56 +02:00
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
{
|
2023-09-09 19:14:47 +02:00
|
|
|
|
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);
|
2023-09-20 14:40:03 +02:00
|
|
|
|
HttpStatusCode success = mangaConnector.DownloadChapter(chapter, this.progressToken);
|
2023-10-27 14:07:15 +02:00
|
|
|
|
chapter.parentManga.UpdateLatestDownloadedChapter(chapter);
|
2023-09-20 14:40:03 +02:00
|
|
|
|
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>();
|
|
|
|
|
}
|
|
|
|
|
}
|