diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index f984c4c..867d9c2 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -18,7 +18,15 @@ public abstract class Connector protected abstract void DownloadImage(string url, string savePath); public abstract void DownloadCover(Publication publication); - protected void DownloadChapter(string[] imageUrls, string saveArchiveFilePath) + protected void DownloadImage(string imageUrl, string fullPath, DownloadClient downloadClient) + { + DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl); + byte[] buffer = new byte[requestResult.result.Length]; + requestResult.result.ReadExactly(buffer, 0, buffer.Length); + File.WriteAllBytes(fullPath, buffer); + } + + protected void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient) { string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar); string directoryPath = Path.Combine(splitPath.Take(splitPath.Length - 1).ToArray()); @@ -38,7 +46,7 @@ public abstract class Connector { string[] split = imageUrl.Split('.'); string extension = split[split.Length - 1]; - DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}")); + DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient); } ZipFile.CreateFromDirectory(tempFolder, fullPath); @@ -51,7 +59,7 @@ public abstract class Connector File.WriteAllText(seriesInfoPath,publication.GetSeriesInfo()); } - internal class DownloadClient + protected class DownloadClient { private readonly TimeSpan _requestSpeed; private DateTime _lastRequest; diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index a248385..0eaf256 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -184,15 +184,7 @@ public class MangaDex : Connector foreach (JsonNode? image in imageFileNames) imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue()}"); - DownloadChapter(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName)); - } - - protected override void DownloadImage(string url, string savePath) - { - DownloadClient.RequestResult requestResult = _downloadClient.MakeRequest(url); - byte[] buffer = new byte[requestResult.result.Length]; - requestResult.result.ReadExactly(buffer, 0, buffer.Length); - File.WriteAllBytes(savePath, buffer); + DownloadChapterImages(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName), this._downloadClient); } public override void DownloadCover(Publication publication) @@ -220,6 +212,6 @@ public class MangaDex : Connector string outFolderPath = Path.Join(downloadLocation, publication.folderName); Directory.CreateDirectory(outFolderPath); - DownloadImage(coverUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}")); + DownloadImage(coverUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"), this._downloadClient); } } \ No newline at end of file