#32 Added progress tracking to task (internal and log use for now)
This commit is contained in:
parent
15fc367263
commit
1bca99cb6a
@ -58,7 +58,8 @@ public abstract class Connector
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="publication">Publication that contains Chapter</param>
|
/// <param name="publication">Publication that contains Chapter</param>
|
||||||
/// <param name="chapter">Chapter with Images to retrieve</param>
|
/// <param name="chapter">Chapter with Images to retrieve</param>
|
||||||
public abstract void DownloadChapter(Publication publication, Chapter chapter);
|
/// <param name="parentTask">Will be used for progress-tracking</param>
|
||||||
|
public abstract void DownloadChapter(Publication publication, Chapter chapter, TrangaTask parentTask);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies the already downloaded cover from cache to downloadLocation
|
/// Copies the already downloaded cover from cache to downloadLocation
|
||||||
@ -128,6 +129,7 @@ public abstract class Connector
|
|||||||
/// <param name="imageUrl"></param>
|
/// <param name="imageUrl"></param>
|
||||||
/// <param name="fullPath"></param>
|
/// <param name="fullPath"></param>
|
||||||
/// <param name="requestType">RequestType for Rate-Limit</param>
|
/// <param name="requestType">RequestType for Rate-Limit</param>
|
||||||
|
/// <param name="referrer">referrer used in html request header</param>
|
||||||
private void DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
|
private void DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
|
||||||
{
|
{
|
||||||
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer);
|
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer);
|
||||||
@ -145,9 +147,11 @@ public abstract class Connector
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="imageUrls">List of URLs to download Images from</param>
|
/// <param name="imageUrls">List of URLs to download Images from</param>
|
||||||
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
||||||
|
/// <param name="parentTask">Used for progress tracking</param>
|
||||||
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
||||||
/// <param name="requestType">RequestType for RateLimits</param>
|
/// <param name="requestType">RequestType for RateLimits</param>
|
||||||
protected void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, string? comicInfoPath = null, string? referrer = null)
|
/// <param name="referrer">Used in http request header</param>
|
||||||
|
protected void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, TrangaTask parentTask, string? comicInfoPath = null, string? referrer = null)
|
||||||
{
|
{
|
||||||
logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}");
|
logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}");
|
||||||
//Check if Publication Directory already exists
|
//Check if Publication Directory already exists
|
||||||
@ -167,8 +171,9 @@ public abstract class Connector
|
|||||||
{
|
{
|
||||||
string[] split = imageUrl.Split('.');
|
string[] split = imageUrl.Split('.');
|
||||||
string extension = split[^1];
|
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);
|
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
|
||||||
|
parentTask.tasksFinished++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(comicInfoPath is not null)
|
if(comicInfoPath is not null)
|
||||||
@ -226,6 +231,7 @@ public abstract class Connector
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
/// <param name="requestType">For RateLimits: Same Endpoints use same type</param>
|
/// <param name="requestType">For RateLimits: Same Endpoints use same type</param>
|
||||||
|
/// <param name="referrer">Used in http request header</param>
|
||||||
/// <returns>RequestResult with StatusCode and Stream of received data</returns>
|
/// <returns>RequestResult with StatusCode and Stream of received data</returns>
|
||||||
public RequestResult MakeRequest(string url, byte requestType, string? referrer = null)
|
public RequestResult MakeRequest(string url, byte requestType, string? referrer = null)
|
||||||
{
|
{
|
||||||
|
@ -204,7 +204,7 @@ public class MangaDex : Connector
|
|||||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
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}");
|
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
//Request URLs for Chapter-Images
|
//Request URLs for Chapter-Images
|
||||||
@ -228,7 +228,7 @@ public class MangaDex : Connector
|
|||||||
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
|
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
|
||||||
|
|
||||||
//Download Chapter-Images
|
//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)
|
private string? GetCoverUrl(string publicationId, string? posterId)
|
||||||
|
@ -162,7 +162,7 @@ public class Manganato : Connector
|
|||||||
return ret.ToArray();
|
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}");
|
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
string requestUrl = chapter.url;
|
string requestUrl = chapter.url;
|
||||||
@ -176,7 +176,7 @@ public class Manganato : Connector
|
|||||||
string comicInfoPath = Path.GetTempFileName();
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
|
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)
|
private string[] ParseImageUrlsFromHtml(Stream html)
|
||||||
|
@ -19,6 +19,9 @@ public abstract class TrangaTask
|
|||||||
public Publication? publication { get; }
|
public Publication? publication { get; }
|
||||||
public string? language { get; }
|
public string? language { get; }
|
||||||
[JsonIgnore]public ExecutionState state { get; set; }
|
[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
|
public enum ExecutionState
|
||||||
{
|
{
|
||||||
@ -35,6 +38,8 @@ public abstract class TrangaTask
|
|||||||
this.connectorName = connectorName;
|
this.connectorName = connectorName;
|
||||||
this.task = task;
|
this.task = task;
|
||||||
this.language = language;
|
this.language = language;
|
||||||
|
this.tasksCount = 1;
|
||||||
|
this.tasksFinished = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -18,13 +18,14 @@ public class DownloadNewChaptersTask : TrangaTask
|
|||||||
if(!Directory.Exists(publicationFolder))
|
if(!Directory.Exists(publicationFolder))
|
||||||
Directory.CreateDirectory(publicationFolder);
|
Directory.CreateDirectory(publicationFolder);
|
||||||
List<Chapter> newChapters = UpdateChapters(connector, pub, language!, ref taskManager.chapterCollection);
|
List<Chapter> newChapters = UpdateChapters(connector, pub, language!, ref taskManager.chapterCollection);
|
||||||
|
this.tasksCount = newChapters.Count;
|
||||||
|
|
||||||
connector.CopyCoverFromCacheToDownloadLocation(pub, taskManager.settings);
|
connector.CopyCoverFromCacheToDownloadLocation(pub, taskManager.settings);
|
||||||
|
|
||||||
pub.SaveSeriesInfoJson(connector.downloadLocation);
|
pub.SaveSeriesInfoJson(connector.downloadLocation);
|
||||||
|
|
||||||
foreach(Chapter newChapter in newChapters)
|
foreach(Chapter newChapter in newChapters)
|
||||||
connector.DownloadChapter(pub, newChapter);
|
connector.DownloadChapter(pub, newChapter, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user