From 816c72f4182dc28b4045a43e3e6708f9ee41976a Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Mon, 3 Mar 2025 11:55:26 +0000 Subject: [PATCH] Use `DownloadableFileFilter` in `TorBoxTorrentClient` to filter files --- .../TorrentClients/TorBoxTorrentClient.cs | 46 ++----------------- 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index cc0a6ce..5a7d95a 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -1,4 +1,3 @@ -using System.Text.RegularExpressions; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using TorBoxNET; @@ -10,7 +9,7 @@ using RdtClient.Service.Helpers; namespace RdtClient.Service.Services.TorrentClients; -public class TorBoxTorrentClient(ILogger logger, IHttpClientFactory httpClientFactory) : ITorrentClient +public class TorBoxTorrentClient(ILogger logger, IHttpClientFactory httpClientFactory, IDownloadableFileFilter fileFilter) : ITorrentClient { private TimeSpan? _offset; private TorBoxNetClient GetClient() @@ -288,46 +287,9 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien { var torrentId = await GetClient().Torrents.GetHashInfoAsync(torrent.Hash, skipCache: true); - 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)) - { - 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)) - { - if (Regex.IsMatch(fileName, torrent.ExcludeRegex)) - - { - Log($"Not downloading {fileName}, it matches regex {torrent.ExcludeRegex}", torrent); - - return false; - } - } - - return true; - }); - - return selectedFiles.Select(file => $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}") - .ToList(); + 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)