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
|
|
|
|
|
2024-04-22 23:45:51 +02:00
|
|
|
|
public DownloadChapter(GlobalBase clone, Chapter chapter, DateTime lastExecution, string? parentJobId = null) : base(clone, JobType.DownloadChapterJob, lastExecution, parentJobId: parentJobId)
|
2023-09-02 16:11:56 +02:00
|
|
|
|
{
|
|
|
|
|
this.chapter = chapter;
|
|
|
|
|
}
|
2023-08-04 14:51:40 +02:00
|
|
|
|
|
2024-04-22 23:45:51 +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()
|
|
|
|
|
{
|
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-11-02 15:19:36 +01: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);
|
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>();
|
|
|
|
|
}
|
2024-01-11 20:19:04 +01:00
|
|
|
|
|
2024-04-22 23:45:51 +02:00
|
|
|
|
protected override MangaConnector GetMangaConnector()
|
|
|
|
|
{
|
|
|
|
|
return chapter.parentManga.mangaConnector;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 20:19:04 +01:00
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj is not DownloadChapter otherJob)
|
|
|
|
|
return false;
|
2024-04-22 23:45:51 +02:00
|
|
|
|
return otherJob.chapter.Equals(this.chapter);
|
2024-01-11 20:19:04 +01:00
|
|
|
|
}
|
2023-08-04 14:51:40 +02:00
|
|
|
|
}
|