From dcea8dcc1ab600ef7ecd8f5fc845eec9e0243275 Mon Sep 17 00:00:00 2001 From: Edouard CHIN Date: Thu, 28 Apr 2022 21:18:56 +0200 Subject: [PATCH] Filter torrents with the category query string: - ### Problem When using multiple *arr instances (sonarr, radarr ...), the queue on each instance displays *all* torrents being processed by RDT. The normal behaviour is to display torrents that have the same category as the one set in the DownloadClient config on radarr/sonarr. ### Solution *arr uses the `/api/v2/torrents/info` QBittorrent endpoint which accepts a `category` query string. This is how the Qbittorent API behaves when that query string exists: ```text See https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-list Get torrents with the given category. empty string means "without category"; no "category" parameter means "any category" ``` See [here](https://github.com/Radarr/Radarr/blob/3125b038d5c2ca8c12f089059b7ca3303456aa9d/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrentProxyV2.cs#L96) how radarr sets the categories when making the query. Thanks for your indulgence, first time writing dotnet :) --- .../Controllers/QBittorrentController.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/server/RdtClient.Web/Controllers/QBittorrentController.cs b/server/RdtClient.Web/Controllers/QBittorrentController.cs index 24127c3..6747120 100644 --- a/server/RdtClient.Web/Controllers/QBittorrentController.cs +++ b/server/RdtClient.Web/Controllers/QBittorrentController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.IO; using System.Net.Http; using System.Threading.Tasks; @@ -135,10 +136,20 @@ namespace RdtClient.Web.Controllers [Route("torrents/info")] [HttpGet] [HttpPost] - public async Task>> TorrentsInfo() + public async Task>> TorrentsInfo([FromQuery] QBTorrentsHashRequest request) { - var result = await _qBittorrent.TorrentInfo(); - return Ok(result); + var results = await _qBittorrent.TorrentInfo(); + IList filteredResults = new List(); + + if (request.Category == null) { + filteredResults = results; + } else if (request.Category == "") { + filteredResults = results.Where(m => m.Category == null).ToList(); + } else { + filteredResults = results.Where(m => m.Category == request.Category).ToList(); + } + + return Ok(filteredResults); } [Authorize] @@ -450,6 +461,7 @@ namespace RdtClient.Web.Controllers public class QBTorrentsHashRequest { public String Hash { get; set; } + public String Category { get; set; } } public class QBTorrentsDeleteRequest