2023-05-31 22:32:37 +02:00
|
|
|
|
using Logging;
|
2023-06-06 20:54:21 +02:00
|
|
|
|
using Newtonsoft.Json;
|
2023-05-31 22:32:37 +02:00
|
|
|
|
|
|
|
|
|
namespace Tranga.TrangaTasks;
|
2023-05-31 21:15:32 +02:00
|
|
|
|
|
|
|
|
|
public class DownloadNewChaptersTask : TrangaTask
|
|
|
|
|
{
|
2023-06-05 00:35:57 +02:00
|
|
|
|
public string connectorName { get; }
|
|
|
|
|
public Publication publication { get; }
|
|
|
|
|
public string language { get; }
|
|
|
|
|
public DownloadNewChaptersTask(Task task, string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(task, reoccurrence)
|
2023-05-31 21:15:32 +02:00
|
|
|
|
{
|
2023-06-05 00:35:57 +02:00
|
|
|
|
this.connectorName = connectorName;
|
|
|
|
|
this.publication = publication;
|
|
|
|
|
this.language = language;
|
2023-06-06 20:54:21 +02:00
|
|
|
|
}
|
2023-05-31 21:15:32 +02:00
|
|
|
|
|
2023-06-10 14:27:09 +02:00
|
|
|
|
protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
2023-05-31 21:15:32 +02:00
|
|
|
|
{
|
2023-06-10 14:27:09 +02:00
|
|
|
|
if (cancellationToken?.IsCancellationRequested??false)
|
|
|
|
|
return;
|
2023-06-05 00:35:57 +02:00
|
|
|
|
Publication pub = publication!;
|
2023-05-31 21:15:32 +02:00
|
|
|
|
Connector connector = taskManager.GetConnector(this.connectorName);
|
2023-06-05 00:35:57 +02:00
|
|
|
|
|
2023-05-31 21:15:32 +02:00
|
|
|
|
//Check if Publication already has a Folder
|
2023-06-01 22:59:04 +02:00
|
|
|
|
pub.CreatePublicationFolder(taskManager.settings.downloadLocation);
|
2023-06-15 17:07:32 +02:00
|
|
|
|
List<Chapter> newChapters = taskManager.GetNewChaptersList(connector, pub, language!);
|
2023-05-31 21:15:32 +02:00
|
|
|
|
|
|
|
|
|
connector.CopyCoverFromCacheToDownloadLocation(pub, taskManager.settings);
|
|
|
|
|
|
|
|
|
|
pub.SaveSeriesInfoJson(connector.downloadLocation);
|
|
|
|
|
|
2023-06-05 00:35:57 +02:00
|
|
|
|
foreach (Chapter newChapter in newChapters)
|
2023-06-10 14:27:09 +02:00
|
|
|
|
{
|
2023-06-11 18:24:26 +02:00
|
|
|
|
DownloadChapterTask newTask = new (Task.DownloadChapter, this.connectorName, pub, newChapter, this.language, this);
|
2023-06-10 14:27:09 +02:00
|
|
|
|
taskManager.AddTask(newTask);
|
|
|
|
|
this.childTasks.Add(newTask);
|
|
|
|
|
}
|
2023-06-15 18:25:32 +02:00
|
|
|
|
if(newChapters.Count > 0)
|
|
|
|
|
foreach(NotificationManager nm in taskManager.settings.notificationManagers)
|
|
|
|
|
nm.SendNotification(pub.sortName, $"Downloading {newChapters.Count} new Chapters.");
|
2023-06-10 14:27:09 +02:00
|
|
|
|
}
|
2023-06-05 00:35:57 +02:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"{base.ToString()}, {connectorName}, {publication.sortName} {publication.internalId}";
|
|
|
|
|
}
|
2023-05-31 21:15:32 +02:00
|
|
|
|
}
|