Merge pull request #741 from Cucumberrbob/feat/ad-rd-exclude-all-fail-torrent

feat: [AD] [RD] don't download anything when all files excluded
This commit is contained in:
Roger Far 2025-03-21 14:14:18 -06:00 committed by GitHub
commit 2be825e248
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 39 deletions

View file

@ -476,7 +476,7 @@ public class AllDebridTorrentClientTest
} }
[Fact] [Fact]
public async Task GetDownloadLinks_WhenAllFilesExcluded_ReturnsAllFiles() public async Task GetDownloadLinks_WhenAllFilesExcluded_ReturnsEmptyList()
{ {
// Arrange // Arrange
var mocks = new Mocks(); var mocks = new Mocks();
@ -502,7 +502,6 @@ public class AllDebridTorrentClientTest
} }
]; ];
var expectedLinksSet = new HashSet<String>(files.Select(n => n.DownloadLink)!);
mocks.AllDebridClientMock.Setup(c => c.Magnet.FilesAsync(Int64.Parse(torrent.RdId), It.IsAny<CancellationToken>())).ReturnsAsync(files); mocks.AllDebridClientMock.Setup(c => c.Magnet.FilesAsync(Int64.Parse(torrent.RdId), It.IsAny<CancellationToken>())).ReturnsAsync(files);
mocks.FileFilterMock.Setup(f => f.IsDownloadable(torrent, It.IsAny<String>(), It.IsAny<Int64>())).Returns(false); mocks.FileFilterMock.Setup(f => f.IsDownloadable(torrent, It.IsAny<String>(), It.IsAny<Int64>())).Returns(false);
@ -513,8 +512,7 @@ public class AllDebridTorrentClientTest
// Assert // Assert
Assert.NotNull(result); Assert.NotNull(result);
var linksSet = new HashSet<String>(result); Assert.Empty(result);
Assert.Equal(expectedLinksSet, linksSet);
mocks.FileFilterMock.Verify(f => f.IsDownloadable(torrent, "file-1.txt", 100)); mocks.FileFilterMock.Verify(f => f.IsDownloadable(torrent, "file-1.txt", 100));
mocks.FileFilterMock.Verify(f => f.IsDownloadable(torrent, "file-2.txt", 100)); mocks.FileFilterMock.Verify(f => f.IsDownloadable(torrent, "file-2.txt", 100));

View file

@ -252,28 +252,14 @@ public class AllDebridTorrentClient(ILogger<AllDebridTorrentClient> logger, IAll
return null; return null;
} }
Log($"Getting download links", torrent);
var allFiles = await allDebridNetClientFactory.GetClient().Magnet.FilesAsync(Int64.Parse(torrent.RdId)); var allFiles = await allDebridNetClientFactory.GetClient().Magnet.FilesAsync(Int64.Parse(torrent.RdId));
var files = GetFiles(allFiles); var files = GetFiles(allFiles);
files = files.Where(f => fileFilter.IsDownloadable(torrent, f.Path, f.Bytes)).ToList(); files = files.Where(f => fileFilter.IsDownloadable(torrent, f.Path, f.Bytes)).ToList();
Log($"Getting download links", torrent);
if (files.Count == 0)
{
Log($"Filtered all files out! Downloading ALL files instead!", torrent);
files = GetFiles(allFiles);
}
Log($"Selecting links:");
foreach (var file in files)
{
Log($"{file.Path} ({file.Bytes}b) {file.DownloadLink}");
}
return files.Where(m => m.DownloadLink != null).Select(m => m.DownloadLink!.ToString()).ToList(); return files.Where(m => m.DownloadLink != null).Select(m => m.DownloadLink!.ToString()).ToList();
} }

View file

@ -144,7 +144,7 @@ public class RealDebridTorrentClient(ILogger<RealDebridTorrentClient> logger, IH
public async Task SelectFiles(Data.Models.Data.Torrent torrent) public async Task SelectFiles(Data.Models.Data.Torrent torrent)
{ {
IList<TorrentClientFile> files; List<TorrentClientFile> files;
Log("Seleting files", torrent); Log("Seleting files", torrent);
@ -155,32 +155,17 @@ public class RealDebridTorrentClient(ILogger<RealDebridTorrentClient> logger, IH
} }
else else
{ {
Log("Selecting all files", torrent); Log("Selecting files", torrent);
files = [.. torrent.Files]; files = [.. torrent.Files];
} }
Log($"Selecting {files.Count}/{torrent.Files.Count} files", torrent);
files = files.Where(f => fileFilter.IsDownloadable(torrent, f.Path, f.Bytes)).ToList(); files = files.Where(f => fileFilter.IsDownloadable(torrent, f.Path, f.Bytes)).ToList();
if (files.Count == 0) Log($"Selecting {files.Count}/{torrent.Files.Count} files", torrent);
{
Log($"Filtered all files out! Downloading ALL files instead!", torrent);
files = torrent.Files;
}
var fileIds = files.Select(m => m.Id.ToString()).ToArray(); var fileIds = files.Select(m => m.Id.ToString()).ToArray();
Log($"Selecting files:");
foreach (var file in files)
{
Log($"{file.Id}: {file.Path} ({file.Bytes}b)");
}
Log("", torrent);
await GetClient().Torrents.SelectFilesAsync(torrent.RdId!, [.. fileIds]); await GetClient().Torrents.SelectFilesAsync(torrent.RdId!, [.. fileIds]);
} }