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] 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)