From 486cea1006dd75a9fe77b895d35d42929d60e6dd Mon Sep 17 00:00:00 2001 From: Roger Far Date: Wed, 10 Jan 2024 18:11:46 -0700 Subject: [PATCH] Add ParallelCount setting back, don't calculate chunk count but use a setting value. --- CHANGELOG.md | 4 ++ client/src/app/navbar/navbar.component.html | 2 +- package.json | 2 +- .../Models/Internal/DbSettings.cs | 8 ++- .../Downloaders/InternalDownloader.cs | 60 ++++++++----------- server/RdtClient.Web/RdtClient.Web.csproj | 2 +- 6 files changed, 38 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4335333..6cf9177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.0.58] - 2024-01-10 +### Changed +- Don't automatically count the chunk count. + ## [2.0.57] - 2024-01-09 ### Changed - Fixed symlink retry. diff --git a/client/src/app/navbar/navbar.component.html b/client/src/app/navbar/navbar.component.html index 3011b0f..d880d2c 100644 --- a/client/src/app/navbar/navbar.component.html +++ b/client/src/app/navbar/navbar.component.html @@ -55,7 +55,7 @@ Profile Logout - Version 2.0.57 + Version 2.0.58 diff --git a/package.json b/package.json index 3ff2100..8b1688d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rdt-client", - "version": "2.0.57", + "version": "2.0.58", "description": "This is a web interface to manage your torrents on Real-Debrid.", "main": "index.js", "dependencies": { diff --git a/server/RdtClient.Data/Models/Internal/DbSettings.cs b/server/RdtClient.Data/Models/Internal/DbSettings.cs index 6359d01..87170a2 100644 --- a/server/RdtClient.Data/Models/Internal/DbSettings.cs +++ b/server/RdtClient.Data/Models/Internal/DbSettings.cs @@ -95,9 +95,13 @@ public class DbSettingsDownloadClient [Description("Maximum download speed in Megabytes per second. When set to 0 unlimited speed is used.")] public Int32 MaxSpeed { get; set; } = 0; + [DisplayName("Parallel connections per download (only used for the Internal Downloader)")] + [Description("Maximum amount of parallel threads that are used to download a single file to your host. If set to 0 no parallel downloading will be done.")] + public Int32 ParallelCount { get; set; } = 4; + [DisplayName("Chunk Count")] - [Description("Split the downloaded file in this amount of chunks. If left to 0, automatically deteremine the chunk size based on the file size.")] - public Int32 ChunkCount { get; set; } = 0; + [Description("Split the downloaded file in this amount of chunks.")] + public Int32 ChunkCount { get; set; } = 8; [DisplayName("Connection Timeout (only used for the Internal Downloader)")] [Description("Timeout in milliseconds before the downloader times out.")] diff --git a/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs b/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs index 30d547d..61b0c89 100644 --- a/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs @@ -1,5 +1,7 @@ -using System.Net; +using System.Diagnostics; +using System.Net; using Downloader; +using Newtonsoft.Json; using Serilog; namespace RdtClient.Service.Services.Downloaders; @@ -64,6 +66,8 @@ public class InternalDownloader : IDownloader return; } + Debug.WriteLine(JsonConvert.SerializeObject(args)); + DownloadProgress.Invoke(this, new DownloadProgressEventArgs { @@ -96,24 +100,10 @@ public class InternalDownloader : IDownloader }; } - public async Task Download() + public Task Download() { _logger.Debug($"Starting download of {_uri}, writing to path: {_filePath}"); - if (Settings.Get.DownloadClient.ChunkCount == 0) - { - var contentSize = await GetContentSize(); - - var chunkSize = contentSize switch - { - <= 1024 * 1024 * 10 => 1024 * 1024 * 10, - <= 1024 * 1024 * 100 => 1024 * 1024 * 25, - _ => 1024 * 1024 * 50 - }; - - _downloadConfiguration.ChunkCount = (Int32) Math.Ceiling(contentSize / (Double) chunkSize); - } - _ = Task.Run(async () => { await _downloadService.DownloadFileTaskAsync(_uri, _filePath); @@ -121,7 +111,7 @@ public class InternalDownloader : IDownloader _ = Task.Run(StartTimer); - return Guid.NewGuid().ToString(); + return Task.FromResult(Guid.NewGuid().ToString()); } public Task Cancel() @@ -160,9 +150,26 @@ public class InternalDownloader : IDownloader { settingDownloadTimeout = 1000; } + + var settingParallelCount = Settings.Get.DownloadClient.ParallelCount; + + if (settingParallelCount <= 0) + { + settingParallelCount = 4; + } + + if (Settings.Get.DownloadClient.ChunkCount <= 0) + { + _downloadConfiguration.ChunkCount = 8; + } + else + { + _downloadConfiguration.ChunkCount = Settings.Get.DownloadClient.ChunkCount; + } _downloadConfiguration.MaximumBytesPerSecond = settingDownloadMaxSpeed; - _downloadConfiguration.ParallelDownload = true; + _downloadConfiguration.ParallelDownload = settingParallelCount > 1; + _downloadConfiguration.ParallelCount = settingParallelCount; _downloadConfiguration.Timeout = settingDownloadTimeout; } @@ -180,21 +187,4 @@ public class InternalDownloader : IDownloader SetSettings(); } } - - private async Task GetContentSize() - { - var httpClient = new HttpClient(); - var responseHeaders = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, _uri)); - - if (!responseHeaders.IsSuccessStatusCode) - { - var content = await responseHeaders.Content.ReadAsStringAsync(); - var ex = new Exception($"Unable to retrieve content size before downloading, received response: {responseHeaders.StatusCode} {content}"); - - throw ex; - } - - var result = responseHeaders.Content.Headers.ContentLength ?? -1; - return result; - } } \ No newline at end of file diff --git a/server/RdtClient.Web/RdtClient.Web.csproj b/server/RdtClient.Web/RdtClient.Web.csproj index df66a08..29ca405 100644 --- a/server/RdtClient.Web/RdtClient.Web.csproj +++ b/server/RdtClient.Web/RdtClient.Web.csproj @@ -4,7 +4,7 @@ net8.0 Exe 94c24cba-f03f-4453-a671-3640b517c573 - 2.0.57 + 2.0.58 enable enable latest