diff --git a/CHANGELOG.md b/CHANGELOG.md index f4b7d48..706c60c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ 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.26] - 2023-03-30 +### Changed +- Add some logging for Premiumize to better understand errors. +- Changed Premiumize to download each file individually instead of creating a zip first. +- Swapped the internal downloader for a new version. +- Fixed issue when switching providers and it not switching over properly. + ## [2.0.25] - 2023-03-17 ### Changed - Fixed docker run issues. diff --git a/client/src/app/navbar/navbar.component.html b/client/src/app/navbar/navbar.component.html index 7b55143..c847305 100644 --- a/client/src/app/navbar/navbar.component.html +++ b/client/src/app/navbar/navbar.component.html @@ -55,7 +55,7 @@ Profile Logout - + diff --git a/package.json b/package.json index 170ab77..35422f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rdt-client", - "version": "2.0.25", + "version": "2.0.26", "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 75d5101..827310e 100644 --- a/server/RdtClient.Data/Models/Internal/DbSettings.cs +++ b/server/RdtClient.Data/Models/Internal/DbSettings.cs @@ -95,10 +95,6 @@ public class DbSettingsDownloadClient [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; } = 0; - [DisplayName("Parallel chunks per download (only used for the Internal Downloader)")] - [Description("Split each parallel download in chunks.")] - public Int32 ChunkCount { get; set; } = 1; - [DisplayName("Connection Timeout (only used for the Internal Downloader)")] [Description("Timeout in milliseconds before the downloader times out.")] public Int32 Timeout { get; set; } = 5000; diff --git a/server/RdtClient.Service/RdtClient.Service.csproj b/server/RdtClient.Service/RdtClient.Service.csproj index 3a2bf20..d13e93c 100644 --- a/server/RdtClient.Service/RdtClient.Service.csproj +++ b/server/RdtClient.Service/RdtClient.Service.csproj @@ -11,13 +11,13 @@ - + - + - + diff --git a/server/RdtClient.Service/Services/DownloadClient.cs b/server/RdtClient.Service/Services/DownloadClient.cs index 0b2f83c..4747065 100644 --- a/server/RdtClient.Service/Services/DownloadClient.cs +++ b/server/RdtClient.Service/Services/DownloadClient.cs @@ -13,7 +13,7 @@ public class DownloadClient public IDownloader? Downloader; - public Data.Enums.DownloadClient Type { get; set; } + public Data.Enums.DownloadClient Type { get; private set; } public Boolean Finished { get; private set; } diff --git a/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs b/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs index d1d2ea8..8f88d69 100644 --- a/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs @@ -1,5 +1,4 @@ -using System.Net; -using Downloader; +using DownloaderNET; using Serilog; namespace RdtClient.Service.Services.Downloaders; @@ -9,14 +8,16 @@ public class InternalDownloader : IDownloader public event EventHandler? DownloadComplete; public event EventHandler? DownloadProgress; - private readonly DownloadService _downloadService; - private readonly DownloadConfiguration _downloadConfiguration; + private readonly Downloader _downloadService; + private readonly DownloaderNET.Settings _downloadConfiguration; private readonly String _filePath; private readonly String _uri; private readonly ILogger _logger; + private readonly CancellationTokenSource _cancellationToken = new(); + private Boolean _finished; public InternalDownloader(String uri, String filePath) @@ -25,40 +26,14 @@ public class InternalDownloader : IDownloader _uri = uri; _filePath = filePath; - - var settingProxyServer = Settings.Get.DownloadClient.ProxyServer; - - // For all options, see https://github.com/bezzad/Downloader - _downloadConfiguration = new DownloadConfiguration - { - BufferBlockSize = 1024 * 8, - MaxTryAgainOnFailover = 5, - RangeDownload = false, - ClearPackageOnCompletionWithFailure = false, - MinimumSizeOfChunking = 1024, - ReserveStorageSpaceBeforeStartingDownload = false, - CheckDiskSizeBeforeDownload = true, - RequestConfiguration = - { - Accept = "*/*", - UserAgent = $"rdt-client", - ProtocolVersion = HttpVersion.Version11, - AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, - KeepAlive = true, - UseDefaultCredentials = false - } - }; + + _downloadConfiguration = new DownloaderNET.Settings(); SetSettings(); - if (!String.IsNullOrWhiteSpace(settingProxyServer)) - { - _downloadConfiguration.RequestConfiguration.Proxy = new WebProxy(new Uri(settingProxyServer), false); - } + _downloadService = new Downloader(_uri, _filePath, _downloadConfiguration, _cancellationToken.Token); - _downloadService = new DownloadService(_downloadConfiguration); - - _downloadService.DownloadProgressChanged += (_, args) => + _downloadService.OnProgress += args => { if (DownloadProgress == null) { @@ -68,32 +43,23 @@ public class InternalDownloader : IDownloader DownloadProgress.Invoke(this, new DownloadProgressEventArgs { - Speed = (Int64)args.BytesPerSecondSpeed, - BytesDone = args.ReceivedBytesSize, - BytesTotal = args.TotalBytesToReceive + Speed = (Int64) args.Average(m => m.Speed), + BytesDone = args.Sum(m => m.DownloadBytes), + BytesTotal = args.Sum(m => m.LengthBytes) }); }; - _downloadService.DownloadFileCompleted += (_, args) => + _downloadService.OnComplete += error => { - String? error = null; - - if (args.Cancelled) - { - error = $"The download was cancelled"; - } - else if (args.Error != null) - { - error = args.Error.Message; - } - DownloadComplete?.Invoke(this, new DownloadCompleteEventArgs { - Error = error + Error = error?.Message }); _finished = true; + + return Task.CompletedTask; }; } @@ -101,11 +67,7 @@ public class InternalDownloader : IDownloader { _logger.Debug($"Starting download of {_uri}, writing to path: {_filePath}"); - Task.Run(async () => - { - await _downloadService.DownloadFileTaskAsync(_uri, _filePath); - }); - + Task.Run(_downloadService.Download); Task.Run(StartTimer); return Task.FromResult(null); @@ -115,7 +77,7 @@ public class InternalDownloader : IDownloader { _logger.Debug($"Cancelling download {_uri}"); - _downloadService.CancelAsync(); + _cancellationToken.Cancel(false); return Task.CompletedTask; } @@ -138,14 +100,7 @@ public class InternalDownloader : IDownloader { settingDownloadParallelCount = 1; } - - var settingDownloadChunkCount = Settings.Get.DownloadClient.ChunkCount; - - if (settingDownloadChunkCount <= 0) - { - settingDownloadChunkCount = 1; - } - + var settingDownloadMaxSpeed = Settings.Get.DownloadClient.MaxSpeed; if (settingDownloadMaxSpeed <= 0) @@ -162,10 +117,8 @@ public class InternalDownloader : IDownloader settingDownloadTimeout = 1000; } - _downloadConfiguration.ChunkCount = settingDownloadChunkCount; + _downloadConfiguration.ChunkCount = settingDownloadParallelCount; _downloadConfiguration.MaximumBytesPerSecond = settingDownloadMaxSpeed; - _downloadConfiguration.ParallelDownload = settingDownloadChunkCount > 1; - _downloadConfiguration.ParallelCount = settingDownloadParallelCount; _downloadConfiguration.Timeout = settingDownloadTimeout; } diff --git a/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs index 8c39440..e62d364 100644 --- a/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs @@ -228,29 +228,35 @@ public class PremiumizeTorrentClient : ITorrentClient } var transfers = await GetClient().Transfers.ListAsync(); + + Log($"Found {transfers.Count} transfers", torrent); + var transfer = transfers.FirstOrDefault(m => m.Id == torrent.RdId); if (transfer == null) { + Log($"Transfer {torrent.RdId} not found!", torrent); return null; } if (String.IsNullOrWhiteSpace(transfer.FolderId)) { + Log($"Transfer {torrent.RdId} has no folderId!", torrent); return null; } - var zip = await GetClient() - .Zip.Generate(new List(), - new List - { - transfer.FolderId - }); + var files = await GetClient().Folder.ListAsync(transfer.FolderId); - return new List + var downloadLinks = files.Content.Where(m => !String.IsNullOrWhiteSpace(m.Link)).Select(m => m.Link).ToList(); + + Log($"Found {downloadLinks.Count} links", torrent); + + foreach (var link in downloadLinks) { - zip - }; + Log($"{link}", torrent); + } + + return downloadLinks; } private async Task GetInfo(String id) diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index 0a7786c..d6894b8 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -23,8 +23,24 @@ public class Torrents private readonly ILogger _logger; private readonly TorrentData _torrentData; private readonly Downloads _downloads; - - private readonly ITorrentClient _torrentClient; + + private readonly AllDebridTorrentClient _allDebridTorrentClient; + private readonly PremiumizeTorrentClient _premiumizeTorrentClient; + private readonly RealDebridTorrentClient _realDebridTorrentClient; + + private ITorrentClient _torrentClient + { + get + { + return Settings.Get.Provider.Provider switch + { + Provider.Premiumize => _premiumizeTorrentClient, + Provider.RealDebrid => _realDebridTorrentClient, + Provider.AllDebrid => _allDebridTorrentClient, + _ => throw new Exception("Invalid Provider") + }; + } + } private static readonly SemaphoreSlim TorrentResetLock = new(1, 1); @@ -38,14 +54,9 @@ public class Torrents _logger = logger; _torrentData = torrentData; _downloads = downloads; - - _torrentClient = Settings.Get.Provider.Provider switch - { - Provider.Premiumize => premiumizeTorrentClient, - Provider.RealDebrid => realDebridTorrentClient, - Provider.AllDebrid => allDebridTorrentClient, - _ => throw new Exception("Invalid Provider") - }; + _allDebridTorrentClient = allDebridTorrentClient; + _premiumizeTorrentClient = premiumizeTorrentClient; + _realDebridTorrentClient = realDebridTorrentClient; } public async Task> Get() diff --git a/server/RdtClient.Web/RdtClient.Web.csproj b/server/RdtClient.Web/RdtClient.Web.csproj index 22f670f..e7ca979 100644 --- a/server/RdtClient.Web/RdtClient.Web.csproj +++ b/server/RdtClient.Web/RdtClient.Web.csproj @@ -4,7 +4,7 @@ net6.0 Exe 94c24cba-f03f-4453-a671-3640b517c573 - 2.0.25 + 2.0.26 enable enable latest