From 9e223de32ea0a07e49297b7b433532b86f2c19b8 Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Fri, 7 Feb 2025 14:40:13 +0000 Subject: [PATCH 1/4] Ensure `MinDownloadSize`, `IncludeRegex` and `ExcludeRegex` are honoured by `PremiumizeTorrentClient` --- .../TorrentClients/PremiumizeTorrentClient.cs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs index 438fe29..313916d 100644 --- a/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using System.Text.RegularExpressions; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using PremiumizeNET; using RdtClient.Data.Enums; @@ -287,6 +288,39 @@ public class PremiumizeTorrentClient(ILogger logger, IH if (!String.IsNullOrWhiteSpace(item.Link)) { Log($"Found item {item.Name} in folder {folder.Name} ({folderId}) with link {item.Link}", torrent); + + if (item.Type == "file") + { + if (torrent.DownloadMinSize > 0) + { + if (item.Link.Length < torrent.DownloadMinSize * 1024 * 1024) + { + Log($"Not downloading {item.Name}, its size of {item.Link.Length} bytes is smaller than the minimum size of {torrent.DownloadMinSize} bytes"); + + continue; + } + } + + if (!String.IsNullOrWhiteSpace(torrent.IncludeRegex)) + { + if (!Regex.IsMatch(item.Name, torrent.IncludeRegex)) + { + Log($"Not downloading {item.Name}, it does not match regex {torrent.IncludeRegex}"); + + continue; + } + } + else if (!String.IsNullOrWhiteSpace(torrent.ExcludeRegex)) + { + if (Regex.IsMatch(item.Name, torrent.ExcludeRegex)) + { + Log($"Not downloading {item.Name}, it matches regex {torrent.ExcludeRegex}"); + + continue; + } + } + } + downloadLinks.Add(item.Link); } else From 26f1f26cd12b7e356147b5d5c362b7571af07583 Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Fri, 7 Feb 2025 14:43:59 +0000 Subject: [PATCH 2/4] Ensure `MinDownloadSize`, `IncludeRegex` and `ExcludeRegex` are honoured by `TorBoxTorrentClient` --- .../TorrentClients/TorBoxTorrentClient.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 45f562b..3c64d05 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -1,3 +1,4 @@ +using System.Text.RegularExpressions; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using TorBoxNET; @@ -284,17 +285,30 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien public async Task?> GetDownloadLinks(Torrent torrent) { - var files = new List(); - var torrentId = await GetClient().Torrents.GetHashInfoAsync(torrent.Hash, skipCache: true); - foreach (var file in torrent.Files) + var selectedFiles = torrent.Files.Where(file => { - var newFile = $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}"; - files.Add(newFile); - } + if (torrent.DownloadMinSize > 0 && file.Bytes < torrent.DownloadMinSize * 1024 * 1024) + { + return false; + } - return files; + if (!String.IsNullOrWhiteSpace(torrent.IncludeRegex)) + { + return !Regex.IsMatch(Path.GetFileName(file.Path), torrent.IncludeRegex); + } + + if (!String.IsNullOrWhiteSpace(torrent.ExcludeRegex)) + { + return Regex.IsMatch(Path.GetFileName(file.Path), torrent.ExcludeRegex); + } + + return true; + }); + + return selectedFiles.Select(file => $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}") + .ToList(); } public async Task GetFileName(String downloadUrl) From e5e64e6946aac440d129ed58d5632d130e44796e Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Thu, 13 Feb 2025 11:41:41 +0000 Subject: [PATCH 3/4] Include `torrent` in logs when rejecting files in `PM` `GetDownloadLinks` --- .../Services/TorrentClients/PremiumizeTorrentClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs index 313916d..5a11bc0 100644 --- a/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/PremiumizeTorrentClient.cs @@ -295,7 +295,7 @@ public class PremiumizeTorrentClient(ILogger logger, IH { if (item.Link.Length < torrent.DownloadMinSize * 1024 * 1024) { - Log($"Not downloading {item.Name}, its size of {item.Link.Length} bytes is smaller than the minimum size of {torrent.DownloadMinSize} bytes"); + Log($"Not downloading {item.Name}, its size of {item.Link.Length} bytes is smaller than the minimum size of {torrent.DownloadMinSize} bytes", torrent); continue; } @@ -305,7 +305,7 @@ public class PremiumizeTorrentClient(ILogger logger, IH { if (!Regex.IsMatch(item.Name, torrent.IncludeRegex)) { - Log($"Not downloading {item.Name}, it does not match regex {torrent.IncludeRegex}"); + Log($"Not downloading {item.Name}, it does not match regex {torrent.IncludeRegex}", torrent); continue; } @@ -314,7 +314,7 @@ public class PremiumizeTorrentClient(ILogger logger, IH { if (Regex.IsMatch(item.Name, torrent.ExcludeRegex)) { - Log($"Not downloading {item.Name}, it matches regex {torrent.ExcludeRegex}"); + Log($"Not downloading {item.Name}, it matches regex {torrent.ExcludeRegex}", torrent); continue; } From 9299314b1498054a9f337ba37e6d354d9ae13bc5 Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Thu, 13 Feb 2025 11:50:40 +0000 Subject: [PATCH 4/4] Log when rejecting files in `TB` `GetDownloadLinks` --- .../TorrentClients/TorBoxTorrentClient.cs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 3c64d05..506912a 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -6,6 +6,7 @@ using RdtClient.Data.Enums; using RdtClient.Data.Models.TorrentClient; using System.Web; using RdtClient.Data.Models.Data; +using RdtClient.Service.Helpers; namespace RdtClient.Service.Services.TorrentClients; @@ -289,19 +290,37 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien var selectedFiles = torrent.Files.Where(file => { + var fileName = Path.GetFileName(file.Path); + if (torrent.DownloadMinSize > 0 && file.Bytes < torrent.DownloadMinSize * 1024 * 1024) { + Log($"Not downloading {fileName}, its size of {file.Bytes} bytes is smaller than the minimum size of {torrent.DownloadMinSize} bytes", torrent); + return false; } if (!String.IsNullOrWhiteSpace(torrent.IncludeRegex)) { - return !Regex.IsMatch(Path.GetFileName(file.Path), torrent.IncludeRegex); + if (!Regex.IsMatch(fileName, torrent.IncludeRegex)) + { + Log($"Not downloading {fileName}, it does not match regex {torrent.IncludeRegex}", torrent); + + return false; + } + + // If IncludeRegex is set, don't look at ExcludeRegex + return true; } if (!String.IsNullOrWhiteSpace(torrent.ExcludeRegex)) { - return Regex.IsMatch(Path.GetFileName(file.Path), torrent.ExcludeRegex); + if (Regex.IsMatch(fileName, torrent.ExcludeRegex)) + + { + Log($"Not downloading {fileName}, it matches regex {torrent.ExcludeRegex}", torrent); + + return false; + } } return true; @@ -353,4 +372,14 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien return Map(result!); } + + private void Log(String message, Torrent? torrent = null) + { + if (torrent != null) + { + message = $"{message} {torrent.ToLog()}"; + } + + logger.LogDebug(message); + } }