diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs
index f8e223d..a1c1424 100644
--- a/Tranga/Connector.cs
+++ b/Tranga/Connector.cs
@@ -58,7 +58,8 @@ public abstract class Connector
///
/// Publication that contains Chapter
/// Chapter with Images to retrieve
- public abstract void DownloadChapter(Publication publication, Chapter chapter);
+ /// Will be used for progress-tracking
+ public abstract void DownloadChapter(Publication publication, Chapter chapter, TrangaTask parentTask);
///
/// Copies the already downloaded cover from cache to downloadLocation
@@ -128,6 +129,7 @@ public abstract class Connector
///
///
/// RequestType for Rate-Limit
+ /// referrer used in html request header
private void DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
{
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer);
@@ -145,9 +147,11 @@ public abstract class Connector
///
/// List of URLs to download Images from
/// Full path to save archive to (without file ending .cbz)
+ /// Used for progress tracking
/// Path of the generate Chapter ComicInfo.xml, if it was generated
/// RequestType for RateLimits
- protected void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, string? comicInfoPath = null, string? referrer = null)
+ /// Used in http request header
+ protected void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, TrangaTask parentTask, string? comicInfoPath = null, string? referrer = null)
{
logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}");
//Check if Publication Directory already exists
@@ -167,8 +171,9 @@ public abstract class Connector
{
string[] split = imageUrl.Split('.');
string extension = split[^1];
- logger?.WriteLine("Connector", $"Downloading Image {chapter + 1}/{imageUrls.Length} {imageUrl}");
+ logger?.WriteLine("Connector", $"Downloading Image {chapter + 1}/{imageUrls.Length} {parentTask.publication?.sortName,20} {parentTask.publication?.internalId,20} Total Task Progress: {parentTask.progress:00.0}%");
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
+ parentTask.tasksFinished++;
}
if(comicInfoPath is not null)
@@ -226,6 +231,7 @@ public abstract class Connector
///
///
/// For RateLimits: Same Endpoints use same type
+ /// Used in http request header
/// RequestResult with StatusCode and Stream of received data
public RequestResult MakeRequest(string url, byte requestType, string? referrer = null)
{
diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs
index dd2cdb4..4bfa5ee 100644
--- a/Tranga/Connectors/MangaDex.cs
+++ b/Tranga/Connectors/MangaDex.cs
@@ -204,7 +204,7 @@ public class MangaDex : Connector
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
}
- public override void DownloadChapter(Publication publication, Chapter chapter)
+ public override void DownloadChapter(Publication publication, Chapter chapter, TrangaTask parentTask)
{
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
//Request URLs for Chapter-Images
@@ -228,7 +228,7 @@ public class MangaDex : Connector
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
//Download Chapter-Images
- DownloadChapterImages(imageUrls.ToArray(), GetArchiveFilePath(publication, chapter), (byte)RequestType.AtHomeServer, comicInfoPath);
+ DownloadChapterImages(imageUrls.ToArray(), GetArchiveFilePath(publication, chapter), (byte)RequestType.AtHomeServer, parentTask, comicInfoPath);
}
private string? GetCoverUrl(string publicationId, string? posterId)
diff --git a/Tranga/Connectors/Manganato.cs b/Tranga/Connectors/Manganato.cs
index 561b209..2b79fb0 100644
--- a/Tranga/Connectors/Manganato.cs
+++ b/Tranga/Connectors/Manganato.cs
@@ -162,7 +162,7 @@ public class Manganato : Connector
return ret.ToArray();
}
- public override void DownloadChapter(Publication publication, Chapter chapter)
+ public override void DownloadChapter(Publication publication, Chapter chapter, TrangaTask parentTask)
{
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
string requestUrl = chapter.url;
@@ -176,7 +176,7 @@ public class Manganato : Connector
string comicInfoPath = Path.GetTempFileName();
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
- DownloadChapterImages(imageUrls, GetArchiveFilePath(publication, chapter), (byte)1, comicInfoPath, "https://chapmanganato.com/");
+ DownloadChapterImages(imageUrls, GetArchiveFilePath(publication, chapter), (byte)1, parentTask, comicInfoPath, "https://chapmanganato.com/");
}
private string[] ParseImageUrlsFromHtml(Stream html)
diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTask.cs
index 4663a29..cba6a16 100644
--- a/Tranga/TrangaTask.cs
+++ b/Tranga/TrangaTask.cs
@@ -19,6 +19,9 @@ public abstract class TrangaTask
public Publication? publication { get; }
public string? language { get; }
[JsonIgnore]public ExecutionState state { get; set; }
+ [JsonIgnore] public float progress => (tasksFinished != 0f ? tasksFinished / tasksCount : 0f);
+ [JsonIgnore]public float tasksCount { get; set; }
+ [JsonIgnore]public float tasksFinished { get; set; }
public enum ExecutionState
{
@@ -35,6 +38,8 @@ public abstract class TrangaTask
this.connectorName = connectorName;
this.task = task;
this.language = language;
+ this.tasksCount = 1;
+ this.tasksFinished = 0;
}
///
diff --git a/Tranga/TrangaTasks/DownloadNewChaptersTask.cs b/Tranga/TrangaTasks/DownloadNewChaptersTask.cs
index 7be44d2..03c3a80 100644
--- a/Tranga/TrangaTasks/DownloadNewChaptersTask.cs
+++ b/Tranga/TrangaTasks/DownloadNewChaptersTask.cs
@@ -18,13 +18,14 @@ public class DownloadNewChaptersTask : TrangaTask
if(!Directory.Exists(publicationFolder))
Directory.CreateDirectory(publicationFolder);
List newChapters = UpdateChapters(connector, pub, language!, ref taskManager.chapterCollection);
+ this.tasksCount = newChapters.Count;
connector.CopyCoverFromCacheToDownloadLocation(pub, taskManager.settings);
pub.SaveSeriesInfoJson(connector.downloadLocation);
foreach(Chapter newChapter in newChapters)
- connector.DownloadChapter(pub, newChapter);
+ connector.DownloadChapter(pub, newChapter, this);
}
///