From b6cd6ceddd5032eb0823c612d7963ca70184e98c Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Tue, 11 Mar 2025 20:44:11 +0000 Subject: [PATCH 01/19] Fix typo in bug report issue template --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 308884d..98653b2 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -9,7 +9,7 @@ assignees: '' **What version are you using?** -**Wat OS are you running?** +**What OS are you running?** **Are you using Docker or as a service?** From dc9c7ff050917acdf629bb575badd25791f967d0 Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Wed, 12 Mar 2025 18:19:24 +1000 Subject: [PATCH 02/19] [TB] Add downloading via zip functionality --- .../TorrentClients/TorBoxTorrentClient.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 556faa7..d68b249 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -288,9 +288,21 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien { var torrentId = await GetClient().Torrents.GetHashInfoAsync(torrent.Hash, skipCache: true); - return torrent.Files.Where(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes)) - .Select(file => $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}") - .ToList(); + bool allFilesDownloadable = torrent.Files.All(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes)); + + if (allFilesDownloadable && torrent.DownloadClient != Data.Enums.DownloadClient.Symlink) + { + logger.LogDebug("Downloading files from TorBox as a zip."); + return [$"https://torbox.app/fakedl/{torrentId?.Id}/zip"]; + } + else + { + logger.LogDebug("Downloading files from TorBox individually."); + return torrent.Files + .Where(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes)) + .Select(file => $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}") + .ToList(); + } } public async Task GetFileName(String downloadUrl) From 85a0e7b04fe3a951753b2ea8a2deffb095900bf8 Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Wed, 12 Mar 2025 22:18:15 +1000 Subject: [PATCH 03/19] [TB] fix nit about bool -> var --- .../Services/TorrentClients/TorBoxTorrentClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index d68b249..64b3308 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -288,7 +288,7 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien { var torrentId = await GetClient().Torrents.GetHashInfoAsync(torrent.Hash, skipCache: true); - bool allFilesDownloadable = torrent.Files.All(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes)); + var allFilesDownloadable = torrent.Files.All(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes)); if (allFilesDownloadable && torrent.DownloadClient != Data.Enums.DownloadClient.Symlink) { From 087653e5b6e62e3011dfb8f9d9ca752d1a8a844f Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Wed, 12 Mar 2025 22:27:33 +1000 Subject: [PATCH 04/19] [TB] fix: calling fileFilter twice in getdllinks --- .../Services/TorrentClients/TorBoxTorrentClient.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 64b3308..a354675 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -287,10 +287,9 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien public async Task?> GetDownloadLinks(Torrent torrent) { var torrentId = await GetClient().Torrents.GetHashInfoAsync(torrent.Hash, skipCache: true); + var downloadableFiles = torrent.Files.Where(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes)).ToList(); - var allFilesDownloadable = torrent.Files.All(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes)); - - if (allFilesDownloadable && torrent.DownloadClient != Data.Enums.DownloadClient.Symlink) + if (downloadableFiles.Count == torrent.Files.Count && torrent.DownloadClient != Data.Enums.DownloadClient.Symlink) { logger.LogDebug("Downloading files from TorBox as a zip."); return [$"https://torbox.app/fakedl/{torrentId?.Id}/zip"]; @@ -298,10 +297,7 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien else { logger.LogDebug("Downloading files from TorBox individually."); - return torrent.Files - .Where(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes)) - .Select(file => $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}") - .ToList(); + return downloadableFiles.Select(file => $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}").ToList(); } } @@ -316,6 +312,7 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien using (HttpClient client = new()) { + client.Timeout = TimeSpan.FromSeconds(30); var request = new HttpRequestMessage(HttpMethod.Head, uri); var response = await client.SendAsync(request); if (response.Content.Headers.ContentDisposition != null) From ea9c90552bdc00e4b91c495d9a0be38f79f7f09b Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Wed, 12 Mar 2025 22:50:18 +1000 Subject: [PATCH 05/19] [TB] fix: timeout to use settings timeout val --- .../Services/TorrentClients/TorBoxTorrentClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index a354675..0c028f8 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -312,7 +312,7 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien using (HttpClient client = new()) { - client.Timeout = TimeSpan.FromSeconds(30); + client.Timeout = TimeSpan.FromSeconds(Settings.Get.Provider.Timeout); var request = new HttpRequestMessage(HttpMethod.Head, uri); var response = await client.SendAsync(request); if (response.Content.Headers.ContentDisposition != null) From 10176357e4610c153d1caac51d00e1700202572c Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Wed, 12 Mar 2025 23:05:19 +1000 Subject: [PATCH 06/19] [TB] fix: unpacking zip downloads may have unintended consequences by fixing this as it may now unpack zips in individual file downloads that aren't intended to be unpacked? --- server/RdtClient.Service/Services/TorrentRunner.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentRunner.cs b/server/RdtClient.Service/Services/TorrentRunner.cs index 6151100..a5b8072 100644 --- a/server/RdtClient.Service/Services/TorrentRunner.cs +++ b/server/RdtClient.Service/Services/TorrentRunner.cs @@ -447,13 +447,8 @@ public class TorrentRunner(ILogger logger, Torrents torrents, Dow // Check if the unpacking process is even needed var uri = new Uri(download.Link); - var fileName = uri.Segments.Last(); - fileName = HttpUtility.UrlDecode(fileName); - - Log($"Found file name {fileName}", download, torrent); - - var extension = Path.GetExtension(fileName); + var extension = Path.GetExtension(download.FileName); if ((extension != ".rar" && extension != ".zip") || torrent.DownloadClient == Data.Enums.DownloadClient.Symlink) From edf443adfc3a7564caeb63ba7860cca6fd1b37f7 Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Thu, 13 Mar 2025 00:24:30 +1000 Subject: [PATCH 07/19] [TB] fix: move files from hash folder in TB zips to root download dir --- .../Services/UnpackClient.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index 2724f43..3ca36c9 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -80,6 +80,11 @@ public class UnpackClient(Download download, String destinationPath) { Extract(filePath, extractPathTemp, cancellationToken); + if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) + { + MoveHashDirectoryUpTB(extractPathTemp); + } + await FileHelper.Delete(filePath); var rarFiles = Directory.GetFiles(extractPathTemp, "*.r00", SearchOption.TopDirectoryOnly); @@ -91,6 +96,11 @@ public class UnpackClient(Download download, String destinationPath) if (File.Exists(mainRarFile)) { Extract(mainRarFile, extractPath, cancellationToken); + + if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) + { + MoveHashDirectoryUpTB(extractPath); + } } await FileHelper.DeleteDirectory(extractPathTemp); @@ -100,6 +110,11 @@ public class UnpackClient(Download download, String destinationPath) { Extract(filePath, extractPath, cancellationToken); + if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) + { + MoveHashDirectoryUpTB(extractPath); + } + await FileHelper.Delete(filePath); } } @@ -113,6 +128,28 @@ public class UnpackClient(Download download, String destinationPath) } } + + private void MoveHashDirectoryUpTB(string extractPath) + { + var hashDir = Path.Combine(extractPath, _torrent.Hash); + if (Directory.Exists(hashDir)) + { + foreach (var file in Directory.GetFiles(hashDir)) + { + var destFile = Path.Combine(extractPath, Path.GetFileName(file)); + File.Move(file, destFile); + } + + foreach (var dir in Directory.GetDirectories(hashDir)) + { + var destDir = Path.Combine(extractPath, Path.GetFileName(dir)); + Directory.Move(dir, destDir); + } + + Directory.Delete(hashDir, true); + } + } + private static async Task> GetArchiveFiles(String filePath) { await using Stream stream = File.OpenRead(filePath); From 9525498671a198e7f9ddf5f622825bd1cc1a762a Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Thu, 13 Mar 2025 00:35:42 +1000 Subject: [PATCH 08/19] [TB] fix: get files from torrent name folder in TB zip --- server/RdtClient.Service/Services/UnpackClient.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index 3ca36c9..94b02d7 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -134,13 +134,15 @@ public class UnpackClient(Download download, String destinationPath) var hashDir = Path.Combine(extractPath, _torrent.Hash); if (Directory.Exists(hashDir)) { - foreach (var file in Directory.GetFiles(hashDir)) + var innerFolder = Directory.GetDirectories(hashDir)[0]; + + foreach (var file in Directory.GetFiles(innerFolder)) { var destFile = Path.Combine(extractPath, Path.GetFileName(file)); File.Move(file, destFile); } - foreach (var dir in Directory.GetDirectories(hashDir)) + foreach (var dir in Directory.GetDirectories(innerFolder)) { var destDir = Path.Combine(extractPath, Path.GetFileName(dir)); Directory.Move(dir, destDir); From 6b211c6e7cbcec933cda4ba9463eef06fd5087aa Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Thu, 13 Mar 2025 17:17:40 +1000 Subject: [PATCH 09/19] [TB] fix: getting provider in UnpackClient Co-Authored-By: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> --- server/RdtClient.Service/Services/UnpackClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index 94b02d7..7c1b122 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -80,7 +80,7 @@ public class UnpackClient(Download download, String destinationPath) { Extract(filePath, extractPathTemp, cancellationToken); - if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) + if (_torrent.ClientKind == Data.Enums.Provider.TorBox) { MoveHashDirectoryUpTB(extractPathTemp); } From 7019c79814c0a2093bdd51c617a76d38aa8a812b Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Sat, 15 Mar 2025 22:20:50 +1000 Subject: [PATCH 10/19] [TB] fix: CLR type names in UnpackClient Co-authored-by: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> --- server/RdtClient.Service/Services/UnpackClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index 7c1b122..7305757 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -129,7 +129,7 @@ public class UnpackClient(Download download, String destinationPath) } - private void MoveHashDirectoryUpTB(string extractPath) + private void MoveHashDirectoryUpTB(String extractPath) { var hashDir = Path.Combine(extractPath, _torrent.Hash); if (Directory.Exists(hashDir)) From bf023b333b50f1199b682c832b681ab919f29b32 Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Sun, 16 Mar 2025 19:04:49 +1000 Subject: [PATCH 11/19] [TB] fix: run MoveHashDirectoryUpTB only once Signed-off-by: Sam Heinz <54530346+asylumexp@users.noreply.github.com> --- .../Services/UnpackClient.cs | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index 7305757..5a90ef1 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -80,11 +80,6 @@ public class UnpackClient(Download download, String destinationPath) { Extract(filePath, extractPathTemp, cancellationToken); - if (_torrent.ClientKind == Data.Enums.Provider.TorBox) - { - MoveHashDirectoryUpTB(extractPathTemp); - } - await FileHelper.Delete(filePath); var rarFiles = Directory.GetFiles(extractPathTemp, "*.r00", SearchOption.TopDirectoryOnly); @@ -96,11 +91,6 @@ public class UnpackClient(Download download, String destinationPath) if (File.Exists(mainRarFile)) { Extract(mainRarFile, extractPath, cancellationToken); - - if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) - { - MoveHashDirectoryUpTB(extractPath); - } } await FileHelper.DeleteDirectory(extractPathTemp); @@ -110,13 +100,13 @@ public class UnpackClient(Download download, String destinationPath) { Extract(filePath, extractPath, cancellationToken); - if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) - { - MoveHashDirectoryUpTB(extractPath); - } - await FileHelper.Delete(filePath); } + + if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) + { + MoveHashDirectoryUpTB(extractPath); + } } catch (Exception ex) { From fd7bc529c86c7a745de47ed55c5afe3ebbc0be45 Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Sun, 16 Mar 2025 19:09:30 +1000 Subject: [PATCH 12/19] [TB] fix: move MoveHashDirectoryUpTB to TorBoxTorrentClient --- .../TorrentClients/TorBoxTorrentClient.cs | 25 +++++++++++++++++- .../Services/UnpackClient.cs | 26 ++----------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 0c028f8..e953193 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -344,7 +344,30 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien return Map(result!); } - + + public static void MoveHashDirectoryUpTB(String extractPath, Torrent _torrent) + { + var hashDir = Path.Combine(extractPath, _torrent.Hash); + if (Directory.Exists(hashDir)) + { + var innerFolder = Directory.GetDirectories(hashDir)[0]; + + foreach (var file in Directory.GetFiles(innerFolder)) + { + var destFile = Path.Combine(extractPath, Path.GetFileName(file)); + File.Move(file, destFile); + } + + foreach (var dir in Directory.GetDirectories(innerFolder)) + { + var destDir = Path.Combine(extractPath, Path.GetFileName(dir)); + Directory.Move(dir, destDir); + } + + Directory.Delete(hashDir, true); + } + } + private void Log(String message, Torrent? torrent = null) { if (torrent != null) diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index 5a90ef1..b94cb14 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using RdtClient.Data.Models.Data; using RdtClient.Service.Helpers; +using RdtClient.Service.Services.TorrentClients; using SharpCompress.Archives; using SharpCompress.Archives.Rar; using SharpCompress.Archives.Zip; @@ -105,7 +106,7 @@ public class UnpackClient(Download download, String destinationPath) if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) { - MoveHashDirectoryUpTB(extractPath); + TorBoxTorrentClient.MoveHashDirectoryUpTB(extractPath, _torrent); } } catch (Exception ex) @@ -119,29 +120,6 @@ public class UnpackClient(Download download, String destinationPath) } - private void MoveHashDirectoryUpTB(String extractPath) - { - var hashDir = Path.Combine(extractPath, _torrent.Hash); - if (Directory.Exists(hashDir)) - { - var innerFolder = Directory.GetDirectories(hashDir)[0]; - - foreach (var file in Directory.GetFiles(innerFolder)) - { - var destFile = Path.Combine(extractPath, Path.GetFileName(file)); - File.Move(file, destFile); - } - - foreach (var dir in Directory.GetDirectories(innerFolder)) - { - var destDir = Path.Combine(extractPath, Path.GetFileName(dir)); - Directory.Move(dir, destDir); - } - - Directory.Delete(hashDir, true); - } - } - private static async Task> GetArchiveFiles(String filePath) { await using Stream stream = File.OpenRead(filePath); From 9d574664727108551a0c2efdc6a9d1d6df2b305a Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Sun, 16 Mar 2025 19:49:03 +1000 Subject: [PATCH 13/19] [TB] fix: download urls still not returning filename via HEAD. --- .../Services/TorrentClients/TorBoxTorrentClient.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index e953193..72dd2e0 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -322,6 +322,15 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien { return fileName.Trim('"'); } + } else + { + if (response.Content.Headers.ContentType?.MediaType == "application/zip") + { + return $"download-{new Random().Next(1, 10001)}.zip"; + } else + { + logger.LogDebug($"Failed to get filename for URI {downloadUrl}"); + } } } From bd96795f3479e1ae940d3d92a8a6599b0733ef54 Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Sun, 16 Mar 2025 20:32:00 +1000 Subject: [PATCH 14/19] [TB] fix: moving hash dir files too far up --- .../Services/TorrentClients/TorBoxTorrentClient.cs | 10 ++++++++-- server/RdtClient.Service/Services/UnpackClient.cs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 72dd2e0..a432946 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -353,14 +353,20 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien return Map(result!); } - - public static void MoveHashDirectoryUpTB(String extractPath, Torrent _torrent) + + public static void MoveHashDirContents(String extractPath, Torrent _torrent) { var hashDir = Path.Combine(extractPath, _torrent.Hash); + if (Directory.Exists(hashDir)) { var innerFolder = Directory.GetDirectories(hashDir)[0]; + if (!Path.GetFileName(innerFolder).Equals(_torrent.Hash, StringComparison.CurrentCultureIgnoreCase)) + { + innerFolder = hashDir; + } + foreach (var file in Directory.GetFiles(innerFolder)) { var destFile = Path.Combine(extractPath, Path.GetFileName(file)); diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index b94cb14..cf48458 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -106,7 +106,7 @@ public class UnpackClient(Download download, String destinationPath) if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) { - TorBoxTorrentClient.MoveHashDirectoryUpTB(extractPath, _torrent); + TorBoxTorrentClient.MoveHashDirContents(extractPath, _torrent); } } catch (Exception ex) From 7d1aeed85c79a01dc3c3dc18ef90c093313cc1f5 Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Sun, 16 Mar 2025 23:33:17 +1000 Subject: [PATCH 15/19] [TB] fix: getting provider in UnpackClient Co-authored-by: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> --- server/RdtClient.Service/Services/UnpackClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index cf48458..33e0ff0 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -104,7 +104,7 @@ public class UnpackClient(Download download, String destinationPath) await FileHelper.Delete(filePath); } - if (Settings.Get.Provider.Provider == Data.Enums.Provider.TorBox) + if (_torrent.ClientKind == Data.Enums.Provider.TorBox) { TorBoxTorrentClient.MoveHashDirContents(extractPath, _torrent); } From 7a822bef5cbefe6eba16defbc8c8989003ec3645 Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Mon, 17 Mar 2025 00:28:19 +1000 Subject: [PATCH 16/19] [TB] fix: extract folder move logic --- .../TorrentClients/TorBoxTorrentClient.cs | 18 +++++++++++++----- .../Services/TorrentRunner.cs | 1 - 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index a432946..62aff18 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -362,24 +362,32 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien { var innerFolder = Directory.GetDirectories(hashDir)[0]; - if (!Path.GetFileName(innerFolder).Equals(_torrent.Hash, StringComparison.CurrentCultureIgnoreCase)) + var moveDir = extractPath; + if (!extractPath.Contains(_torrent.RdName!)) { - innerFolder = hashDir; + moveDir = hashDir; } foreach (var file in Directory.GetFiles(innerFolder)) { - var destFile = Path.Combine(extractPath, Path.GetFileName(file)); + var destFile = Path.Combine(moveDir, Path.GetFileName(file)); File.Move(file, destFile); } foreach (var dir in Directory.GetDirectories(innerFolder)) { - var destDir = Path.Combine(extractPath, Path.GetFileName(dir)); + var destDir = Path.Combine(moveDir, Path.GetFileName(dir)); Directory.Move(dir, destDir); } - Directory.Delete(hashDir, true); + if (!extractPath.Contains(_torrent.RdName!)) + { + Directory.Delete(innerFolder, true); + } + else + { + Directory.Delete(hashDir, true); + } } } diff --git a/server/RdtClient.Service/Services/TorrentRunner.cs b/server/RdtClient.Service/Services/TorrentRunner.cs index a5b8072..a7e7cb6 100644 --- a/server/RdtClient.Service/Services/TorrentRunner.cs +++ b/server/RdtClient.Service/Services/TorrentRunner.cs @@ -8,7 +8,6 @@ using RdtClient.Service.Services.Downloaders; using System.Collections.Concurrent; using System.Diagnostics; using System.Text.Json; -using System.Web; namespace RdtClient.Service.Services; From afc7d1a9648e91f1ba1e83d7f1e282d80a17c2cc Mon Sep 17 00:00:00 2001 From: Sam Heinz <54530346+asylumexp@users.noreply.github.com> Date: Mon, 17 Mar 2025 00:50:51 +1000 Subject: [PATCH 17/19] [TB] fix: replace Contains with EndsWith --- .../Services/TorrentClients/TorBoxTorrentClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 62aff18..329c872 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -363,7 +363,7 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien var innerFolder = Directory.GetDirectories(hashDir)[0]; var moveDir = extractPath; - if (!extractPath.Contains(_torrent.RdName!)) + if (!extractPath.EndsWith(_torrent.RdName!)) { moveDir = hashDir; } From 93fac2312818a65a7b54afc9fafba29aa72c16c1 Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Sun, 16 Mar 2025 15:34:25 +0000 Subject: [PATCH 18/19] run `dotnet format` --- .../Services/TorrentClients/TorBoxTorrentClient.cs | 8 +++++--- server/RdtClient.Service/Services/UnpackClient.cs | 14 +++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 329c872..5cfcd3f 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -322,12 +322,14 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien { return fileName.Trim('"'); } - } else + } + else { if (response.Content.Headers.ContentType?.MediaType == "application/zip") { return $"download-{new Random().Next(1, 10001)}.zip"; - } else + } + else { logger.LogDebug($"Failed to get filename for URI {downloadUrl}"); } @@ -353,7 +355,7 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien return Map(result!); } - + public static void MoveHashDirContents(String extractPath, Torrent _torrent) { var hashDir = Path.Combine(extractPath, _torrent.Hash); diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index 33e0ff0..d5e1cd7 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -11,13 +11,13 @@ namespace RdtClient.Service.Services; public class UnpackClient(Download download, String destinationPath) { public Boolean Finished { get; private set; } - + public String? Error { get; private set; } - + public Int32 Progess { get; private set; } private readonly Torrent _torrent = download.Torrent ?? throw new($"Torrent is null"); - + private readonly CancellationTokenSource _cancellationTokenSource = new(); public void Start() @@ -70,13 +70,13 @@ public class UnpackClient(Download download, String destinationPath) if (archiveEntries.Any(m => m.Contains(".r00"))) { extractPathTemp = Path.Combine(extractPath, Guid.NewGuid().ToString()); - + if (!Directory.Exists(extractPathTemp)) { Directory.CreateDirectory(extractPathTemp); } } - + if (extractPathTemp != null) { Extract(filePath, extractPathTemp, cancellationToken); @@ -168,10 +168,10 @@ public class UnpackClient(Download download, String destinationPath) d => { Debug.WriteLine(d); - Progess = (Int32) Math.Round(d); + Progess = (Int32)Math.Round(d); }, cancellationToken: cancellationToken); - + archive.Dispose(); GC.Collect(); From aa6e6c7df539637dbf70a66caa43abf1d4e418ac Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Sun, 16 Mar 2025 15:38:39 +0000 Subject: [PATCH 19/19] Add release notes for #749 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7950585..2babfed 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). +## [Unreleased] +### Changed +- Download .zip of torrent files from TorBox when possible, thanks @asylumexp! + ## [2.0.102] - 2025-03-07 ### Changed - Fixed Angular build for Docker.