Compare commits
5 Commits
4fcaca1a6e
...
9fd8bf1741
Author | SHA1 | Date | |
---|---|---|---|
9fd8bf1741 | |||
d5c9c5ba96 | |||
c8e27921ab | |||
6eaba07801 | |||
41929e0c72 |
@ -252,7 +252,7 @@ public abstract class Connector
|
|||||||
string extension = split[^1];
|
string extension = split[^1];
|
||||||
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1:000}/{imageUrls.Length:000} {parentTask.publication.sortName} {parentTask.publication.internalId} Vol.{parentTask.chapter.volumeNumber} Ch.{parentTask.chapter.chapterNumber} {parentTask.progress:P2}");
|
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1:000}/{imageUrls.Length:000} {parentTask.publication.sortName} {parentTask.publication.internalId} Vol.{parentTask.chapter.volumeNumber} Ch.{parentTask.chapter.chapterNumber} {parentTask.progress:P2}");
|
||||||
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
|
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
|
||||||
parentTask.IncrementProgress(1f / imageUrls.Length);
|
parentTask.IncrementProgress(1.0 / imageUrls.Length);
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
if (cancellationToken?.IsCancellationRequested??false)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -428,6 +428,16 @@ public class TaskManager
|
|||||||
this._allTasks = JsonConvert.DeserializeObject<HashSet<TrangaTask>>(buffer, new JsonSerializerSettings() { Converters = { new TrangaTask.TrangaTaskJsonConverter() } })!;
|
this._allTasks = JsonConvert.DeserializeObject<HashSet<TrangaTask>>(buffer, new JsonSerializerSettings() { Converters = { new TrangaTask.TrangaTaskJsonConverter() } })!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (TrangaTask task in this._allTasks.Where(task => task.GetType() == typeof(DownloadChapterTask)))
|
||||||
|
{
|
||||||
|
DownloadChapterTask dcTask = (DownloadChapterTask)task;
|
||||||
|
IEnumerable<TrangaTask> dncTasks = this._allTasks.Where(pTask => pTask.GetType() == typeof(DownloadNewChaptersTask));
|
||||||
|
DownloadNewChaptersTask? parentTask = (DownloadNewChaptersTask?)dncTasks.FirstOrDefault(pTask => pTask.taskId.Equals(dcTask.parentTaskId));
|
||||||
|
dcTask.parentTask = parentTask;
|
||||||
|
parentTask?.AddChildTask(dcTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (File.Exists(settings.knownPublicationsPath))
|
if (File.Exists(settings.knownPublicationsPath))
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Importing known publications from {settings.knownPublicationsPath}");
|
logger?.WriteLine(this.GetType().ToString(), $"Importing known publications from {settings.knownPublicationsPath}");
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Globalization;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Logging;
|
using Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@ -20,8 +21,9 @@ public abstract class TrangaTask
|
|||||||
public TimeSpan reoccurrence { get; }
|
public TimeSpan reoccurrence { get; }
|
||||||
public DateTime lastExecuted { get; set; }
|
public DateTime lastExecuted { get; set; }
|
||||||
public Task task { get; }
|
public Task task { get; }
|
||||||
|
public string taskId { get; set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public ExecutionState state { get; set; }
|
[Newtonsoft.Json.JsonIgnore]public ExecutionState state { get; set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public float progress { get; protected set; }
|
[Newtonsoft.Json.JsonIgnore]public double progress { get; protected set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
|
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
|
||||||
|
|
||||||
@ -33,7 +35,7 @@ public abstract class TrangaTask
|
|||||||
[Newtonsoft.Json.JsonIgnore]
|
[Newtonsoft.Json.JsonIgnore]
|
||||||
public TimeSpan executionApproximatelyRemaining => this.executionApproximatelyFinished.Subtract(DateTime.Now);
|
public TimeSpan executionApproximatelyRemaining => this.executionApproximatelyFinished.Subtract(DateTime.Now);
|
||||||
|
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; protected set; }
|
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; private set; }
|
||||||
|
|
||||||
public enum ExecutionState
|
public enum ExecutionState
|
||||||
{
|
{
|
||||||
@ -50,16 +52,17 @@ public abstract class TrangaTask
|
|||||||
this.progress = 0f;
|
this.progress = 0f;
|
||||||
this.executionStarted = DateTime.Now;
|
this.executionStarted = DateTime.Now;
|
||||||
this.lastChange = DateTime.MaxValue;
|
this.lastChange = DateTime.MaxValue;
|
||||||
|
this.taskId = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(this.executionStarted.ToString(CultureInfo.InvariantCulture)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public float IncrementProgress(float amount)
|
public double IncrementProgress(double amount)
|
||||||
{
|
{
|
||||||
this.progress += amount;
|
this.progress += amount;
|
||||||
this.lastChange = DateTime.Now;
|
this.lastChange = DateTime.Now;
|
||||||
return this.progress;
|
return this.progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float DecrementProgress(float amount)
|
public double DecrementProgress(double amount)
|
||||||
{
|
{
|
||||||
this.progress -= amount;
|
this.progress -= amount;
|
||||||
this.lastChange = DateTime.Now;
|
this.lastChange = DateTime.Now;
|
||||||
|
@ -9,7 +9,9 @@ public class DownloadChapterTask : TrangaTask
|
|||||||
public Publication publication { get; }
|
public Publication publication { get; }
|
||||||
public string language { get; }
|
public string language { get; }
|
||||||
public Chapter chapter { get; }
|
public Chapter chapter { get; }
|
||||||
[JsonIgnore]public DownloadNewChaptersTask? parentTask { get; init; }
|
[JsonIgnore]public DownloadNewChaptersTask? parentTask { get; set; }
|
||||||
|
public string? parentTaskId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public DownloadChapterTask(Task task, string connectorName, Publication publication, Chapter chapter, string language = "en", DownloadNewChaptersTask? parentTask = null) : base(task, TimeSpan.Zero)
|
public DownloadChapterTask(Task task, string connectorName, Publication publication, Chapter chapter, string language = "en", DownloadNewChaptersTask? parentTask = null) : base(task, TimeSpan.Zero)
|
||||||
{
|
{
|
||||||
@ -18,24 +20,21 @@ public class DownloadChapterTask : TrangaTask
|
|||||||
this.publication = publication;
|
this.publication = publication;
|
||||||
this.language = language;
|
this.language = language;
|
||||||
this.parentTask = parentTask;
|
this.parentTask = parentTask;
|
||||||
|
this.parentTaskId = parentTask?.taskId;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
if (cancellationToken?.IsCancellationRequested??false)
|
||||||
return;
|
return;
|
||||||
|
if(this.parentTask is not null)
|
||||||
|
this.parentTask.state = ExecutionState.Running;
|
||||||
Connector connector = taskManager.GetConnector(this.connectorName);
|
Connector connector = taskManager.GetConnector(this.connectorName);
|
||||||
connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken);
|
connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken);
|
||||||
|
if(this.parentTask is not null)
|
||||||
|
this.parentTask.state = ExecutionState.Waiting;
|
||||||
taskManager.DeleteTask(this);
|
taskManager.DeleteTask(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public new float IncrementProgress(float amount)
|
|
||||||
{
|
|
||||||
this.progress += amount;
|
|
||||||
this.lastChange = DateTime.Now;
|
|
||||||
parentTask?.IncrementProgress(amount);
|
|
||||||
return this.progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,7 @@ public class DownloadNewChaptersTask : TrangaTask
|
|||||||
public Publication publication { get; }
|
public Publication publication { get; }
|
||||||
public string language { get; }
|
public string language { get; }
|
||||||
[JsonIgnore]private HashSet<DownloadChapterTask> childTasks { get; }
|
[JsonIgnore]private HashSet<DownloadChapterTask> childTasks { get; }
|
||||||
|
[JsonIgnore]public new double progress => childTasks.Count > 0 ? childTasks.Sum(childTask => childTask.progress) / childTasks.Count : 0;
|
||||||
|
|
||||||
public DownloadNewChaptersTask(Task task, string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(task, reoccurrence)
|
public DownloadNewChaptersTask(Task task, string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(task, reoccurrence)
|
||||||
{
|
{
|
||||||
@ -17,20 +18,6 @@ public class DownloadNewChaptersTask : TrangaTask
|
|||||||
this.language = language;
|
this.language = language;
|
||||||
this.childTasks = new();
|
this.childTasks = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public new float IncrementProgress(float amount)
|
|
||||||
{
|
|
||||||
this.progress += amount / this.childTasks.Count;
|
|
||||||
this.lastChange = DateTime.Now;
|
|
||||||
return this.progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public new float DecrementProgress(float amount)
|
|
||||||
{
|
|
||||||
this.progress -= amount / this.childTasks.Count;
|
|
||||||
this.lastChange = DateTime.Now;
|
|
||||||
return this.progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
@ -62,6 +49,11 @@ public class DownloadNewChaptersTask : TrangaTask
|
|||||||
this.childTasks.Remove(failed);
|
this.childTasks.Remove(failed);
|
||||||
this.childTasks.Add(newTask);
|
this.childTasks.Add(newTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddChildTask(DownloadChapterTask childTask)
|
||||||
|
{
|
||||||
|
this.childTasks.Add(childTask);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the available Chapters of a Publication
|
/// Updates the available Chapters of a Publication
|
||||||
|
@ -367,14 +367,8 @@ function ShowTasksQueue(){
|
|||||||
tagTasksRunning.innerText = json.length;
|
tagTasksRunning.innerText = json.length;
|
||||||
json.forEach(task => {
|
json.forEach(task => {
|
||||||
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
||||||
|
document.querySelector(`#progress${task.taskId.replaceAll('=','')}`).value = task.progress;
|
||||||
if(task.chapter != undefined){
|
document.querySelector(`#progressStr${task.taskId.replaceAll('=','')}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
||||||
document.querySelector(`#progress${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`).value = task.progress;
|
|
||||||
document.querySelector(`#progressStr${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
|
||||||
}else{
|
|
||||||
document.querySelector(`#progress${task.publication.internalId.replace('=','')}`).value = task.progress;
|
|
||||||
document.querySelector(`#progressStr${task.publication.internalId.replace('=','')}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -401,11 +395,13 @@ function CreateProgressChild(task){
|
|||||||
|
|
||||||
|
|
||||||
var progress = document.createElement("progress");
|
var progress = document.createElement("progress");
|
||||||
|
progress.id = `progress${task.taskId.replaceAll('=','')}`;
|
||||||
child.appendChild(progress);
|
child.appendChild(progress);
|
||||||
|
|
||||||
var progressStr = document.createElement("span");
|
var progressStr = document.createElement("span");
|
||||||
progressStr.innerText = "00.00%";
|
progressStr.innerText = "00.00%";
|
||||||
progressStr.className = "progressStr";
|
progressStr.className = "progressStr";
|
||||||
|
progressStr.id = `progressStr${task.taskId.replaceAll('=','')}`;
|
||||||
child.appendChild(progressStr);
|
child.appendChild(progressStr);
|
||||||
|
|
||||||
if(task.chapter != undefined){
|
if(task.chapter != undefined){
|
||||||
@ -418,12 +414,6 @@ function CreateProgressChild(task){
|
|||||||
chapterName.className = "chapterName";
|
chapterName.className = "chapterName";
|
||||||
chapterName.innerText = task.chapter.name;
|
chapterName.innerText = task.chapter.name;
|
||||||
child.appendChild(chapterName);
|
child.appendChild(chapterName);
|
||||||
|
|
||||||
progress.id = `progress${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`;
|
|
||||||
progressStr.id = `progressStr${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`;
|
|
||||||
}else{
|
|
||||||
progress.id = `progress${task.publication.internalId.replace('=','')}`;
|
|
||||||
progressStr.id = `progressStr${task.publication.internalId.replace('=','')}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -494,13 +484,8 @@ setInterval(() => {
|
|||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
GetRunningTasks().then((json) => {
|
GetRunningTasks().then((json) => {
|
||||||
json.forEach(task => {
|
json.forEach(task => {
|
||||||
if(task.chapter != undefined){
|
document.querySelector(`#progress${task.taskId.replaceAll('=','')}`).value = task.progress;
|
||||||
document.querySelector(`#progress${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`).value = task.progress;
|
document.querySelector(`#progressStr${task.taskId.replaceAll('=','')}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
||||||
document.querySelector(`#progressStr${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
|
||||||
}else{
|
|
||||||
document.querySelector(`#progress${task.publication.internalId.replace('=','')}`).value = task.progress;
|
|
||||||
document.querySelector(`#progressStr${task.publication.internalId.replace('=','')}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},500);
|
},500);
|
Loading…
Reference in New Issue
Block a user