feat(dl): replace Transmission with qBittorrent
qBittorrent's add call answers `Ok.` and nothing else — no hash, no name, no duplicate signal — so arr derives the v1 infohash from the magnet or the `.torrent` bytes before the call and looks the torrent up by it. That also drops Transmission's numeric torrent id: the hash is the only identity now. The reaper needs "stopped because a share limit was reached", and qBittorrent's state field cannot tell that apart from a hand-paused torrent. So the ratio and idle counters are checked against the limits arr set, and a torrent stopped by a global limit reads as still seeding rather than being deleted. The WebUI needs a login, so `ARR_QBITTORRENT_USERNAME` and `ARR_QBITTORRENT_PASSWORD` join the env-only secrets; leaving both unset is valid for an instance that whitelists arr's subnet. Verified against qBittorrent 5 (WebAPI 2.15.1) in a container: it rejects `setShareLimits` without `shareLimitAction`, which 4.x ignores, so it is always sent. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
afe167ca7b
commit
ab4f95b166
@@ -42,14 +42,12 @@ pub struct Download {
|
||||
tag = "system",
|
||||
responses(
|
||||
(status = 200, description = "Live downloads started by arr", body = [Download]),
|
||||
(status = 503, description = "Transmission or database unavailable", body = crate::movies::ErrorBody)
|
||||
(status = 503, description = "qBittorrent or database unavailable", body = crate::movies::ErrorBody)
|
||||
)
|
||||
)]
|
||||
pub(crate) async fn list(State(state): State<AppState>) -> Result<Json<Vec<Download>>, ApiError> {
|
||||
let database = state.database().ok_or(ApiError::Unavailable)?;
|
||||
let transmission = state
|
||||
.transmission()
|
||||
.ok_or(ApiError::Upstream("transmission"))?;
|
||||
let qbit = state.qbit().ok_or(ApiError::Upstream("qbit"))?;
|
||||
|
||||
let torrents = {
|
||||
let mut cache = state.download_snapshot().write().await;
|
||||
@@ -57,18 +55,18 @@ pub(crate) async fn list(State(state): State<AppState>) -> Result<Json<Vec<Downl
|
||||
if at.elapsed() < SNAPSHOT_TTL {
|
||||
torrents.clone()
|
||||
} else {
|
||||
let torrents = transmission
|
||||
let torrents = qbit
|
||||
.list_torrents()
|
||||
.await
|
||||
.map_err(|_| ApiError::Upstream("transmission"))?;
|
||||
.map_err(|_| ApiError::Upstream("qbit"))?;
|
||||
*cache = Some((Instant::now(), torrents.clone()));
|
||||
torrents
|
||||
}
|
||||
} else {
|
||||
let torrents = transmission
|
||||
let torrents = qbit
|
||||
.list_torrents()
|
||||
.await
|
||||
.map_err(|_| ApiError::Upstream("transmission"))?;
|
||||
.map_err(|_| ApiError::Upstream("qbit"))?;
|
||||
*cache = Some((Instant::now(), torrents.clone()));
|
||||
torrents
|
||||
}
|
||||
@@ -116,7 +114,7 @@ fn phase(torrent: &Torrent) -> DownloadPhase {
|
||||
} else {
|
||||
match torrent.state {
|
||||
TorrentState::Seeding => DownloadPhase::Seeding,
|
||||
// Transmission's own verdict, not a zero rate: a torrent between
|
||||
// qBittorrent's own verdict, not a zero rate: a torrent between
|
||||
// peers reads zero for a poll or two and finishes fine, and
|
||||
// §9.8's stalled chip is for the case that never does.
|
||||
TorrentState::Downloading if torrent.is_stalled => DownloadPhase::Stalled,
|
||||
@@ -133,7 +131,7 @@ mod tests {
|
||||
use arr_db::Db;
|
||||
use axum::extract::State;
|
||||
use serde_json::json;
|
||||
use wiremock::matchers::{body_partial_json, method};
|
||||
use wiremock::matchers::{method, path};
|
||||
use wiremock::{Mock, MockServer, ResponseTemplate};
|
||||
|
||||
use super::{list, phase, DownloadPhase};
|
||||
@@ -143,7 +141,6 @@ mod tests {
|
||||
fn torrent_states_become_the_download_phases() {
|
||||
let torrent =
|
||||
|state: arr_dl::TorrentState, rate: u64, error: Option<&str>| arr_dl::Torrent {
|
||||
id: 1,
|
||||
name: "name".into(),
|
||||
hash: "hash".into(),
|
||||
state,
|
||||
@@ -186,24 +183,13 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn endpoint_joins_only_arr_grabs_and_reuses_the_snapshot() {
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("POST"))
|
||||
.respond_with(
|
||||
ResponseTemplate::new(409).insert_header("x-transmission-session-id", "session"),
|
||||
)
|
||||
.up_to_n_times(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
Mock::given(method("POST"))
|
||||
.and(body_partial_json(json!({"method": "torrent-get"})))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"result": "success",
|
||||
"arguments": {"torrents": [{
|
||||
"id": 1, "name": "grabbed", "hashString": "ABC",
|
||||
"status": 4, "percentDone": 0.4, "rateDownload": 123,
|
||||
"eta": 60, "errorString": "", "downloadDir": "/downloads",
|
||||
"labels": [], "isFinished": false
|
||||
}]}
|
||||
})))
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/api/v2/torrents/info"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!([{
|
||||
"hash": "ABC", "name": "grabbed", "state": "downloading",
|
||||
"progress": 0.4, "dlspeed": 123, "eta": 60,
|
||||
"save_path": "/downloads", "tags": ""
|
||||
}])))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
@@ -231,7 +217,7 @@ mod tests {
|
||||
let state = AppState::new(Upstreams::new("unused".into(), server.uri()))
|
||||
.expect("state")
|
||||
.with_database(database)
|
||||
.with_transmission(arr_dl::TransmissionClient::new(&server.uri()).expect("client"));
|
||||
.with_qbit(arr_dl::QbitClient::new(&server.uri()).expect("client"));
|
||||
let first = list(State(state.clone())).await.expect("first").0;
|
||||
let second = list(State(state)).await.expect("second").0;
|
||||
assert_eq!(first.len(), 1);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! `GET /api/health` — is each of the three upstreams answering.
|
||||
//!
|
||||
//! The three probed here are the ones DESIGN.md §9.5 calls "Broken": without
|
||||
//! Prowlarr nothing is found, without Transmission nothing is fetched, and
|
||||
//! Prowlarr nothing is found, without qBittorrent nothing is fetched, and
|
||||
//! without TMDB nothing is identified. The endpoint always answers `200` —
|
||||
//! the body carries the verdict, so a degraded service can still explain
|
||||
//! itself to the UI instead of looking like a fourth outage.
|
||||
@@ -118,12 +118,12 @@ pub struct HealthReport {
|
||||
#[schema(example = "0.1.0")]
|
||||
pub version: String,
|
||||
pub prowlarr: Check,
|
||||
pub transmission: Check,
|
||||
pub qbit: Check,
|
||||
pub tmdb: Check,
|
||||
pub subtitles: SubtitleHealth,
|
||||
}
|
||||
|
||||
/// Report reachability of Prowlarr, Transmission and TMDB, plus the
|
||||
/// Report reachability of Prowlarr, qBittorrent and TMDB, plus the
|
||||
/// subtitle upstreams (#200).
|
||||
#[utoipa::path(
|
||||
get,
|
||||
@@ -136,14 +136,14 @@ pub struct HealthReport {
|
||||
pub async fn health(State(state): State<AppState>) -> Json<HealthReport> {
|
||||
// Independent network probes; serialising them would make the endpoint
|
||||
// as slow as the sum of the timeouts.
|
||||
let (prowlarr, transmission, tmdb, subtitles) = tokio::join!(
|
||||
let (prowlarr, qbit, tmdb, subtitles) = tokio::join!(
|
||||
probe_prowlarr(&state),
|
||||
probe_transmission(&state),
|
||||
probe_qbit(&state),
|
||||
probe_tmdb(&state),
|
||||
probe_subtitles(&state)
|
||||
);
|
||||
|
||||
let status = if [prowlarr.status, transmission.status, tmdb.status]
|
||||
let status = if [prowlarr.status, qbit.status, tmdb.status]
|
||||
.into_iter()
|
||||
.chain(subtitles.statuses())
|
||||
.all(|check| check == Status::Ok)
|
||||
@@ -157,7 +157,7 @@ pub async fn health(State(state): State<AppState>) -> Json<HealthReport> {
|
||||
status,
|
||||
version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
prowlarr,
|
||||
transmission,
|
||||
qbit,
|
||||
tmdb,
|
||||
subtitles,
|
||||
})
|
||||
@@ -181,17 +181,16 @@ async fn probe_prowlarr(state: &AppState) -> Check {
|
||||
}
|
||||
}
|
||||
|
||||
/// Transmission answers an RPC call without a session id with `409` plus the
|
||||
/// id to retry with. That is a live daemon, so it counts as reachable.
|
||||
async fn probe_transmission(state: &AppState) -> Check {
|
||||
let request = state
|
||||
.http()
|
||||
.post(&state.upstreams().transmission_url)
|
||||
.json(&serde_json::json!({ "method": "session-get" }));
|
||||
/// A live `WebUI` answers `/api/v2/app/version`, and answers `403` when the
|
||||
/// probe carries no session. Both are a running daemon, which is all this
|
||||
/// lamp claims; whether arr's credentials work shows up on the first grab.
|
||||
async fn probe_qbit(state: &AppState) -> Check {
|
||||
let base = state.upstreams().qbittorrent_url.trim_end_matches('/');
|
||||
let request = state.http().get(format!("{base}/api/v2/app/version"));
|
||||
match request.send().await {
|
||||
Ok(response)
|
||||
if response.status().is_success()
|
||||
|| response.status() == reqwest::StatusCode::CONFLICT =>
|
||||
|| response.status() == reqwest::StatusCode::FORBIDDEN =>
|
||||
{
|
||||
Check::ok()
|
||||
}
|
||||
|
||||
+25
-44
@@ -177,8 +177,8 @@ mod tests {
|
||||
use wiremock::matchers::{method, path};
|
||||
use wiremock::{Mock, MockServer, ResponseTemplate};
|
||||
|
||||
/// A Prowlarr that answers `/ping`, and a Transmission that answers an
|
||||
/// RPC call the way a real one does when it has no session id yet.
|
||||
/// A Prowlarr that answers `/ping`, and a qBittorrent that answers the
|
||||
/// version call the way a real one does for an unauthenticated caller.
|
||||
async fn upstreams_up() -> (MockServer, MockServer) {
|
||||
let prowlarr = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
@@ -189,16 +189,14 @@ mod tests {
|
||||
.mount(&prowlarr)
|
||||
.await;
|
||||
|
||||
let transmission = MockServer::start().await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/transmission/rpc"))
|
||||
.respond_with(
|
||||
ResponseTemplate::new(409).insert_header("X-Transmission-Session-Id", "abc"),
|
||||
)
|
||||
.mount(&transmission)
|
||||
let qbit = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/api/v2/app/version"))
|
||||
.respond_with(ResponseTemplate::new(403).set_body_string("Forbidden"))
|
||||
.mount(&qbit)
|
||||
.await;
|
||||
|
||||
(prowlarr, transmission)
|
||||
(prowlarr, qbit)
|
||||
}
|
||||
|
||||
/// Serve the app on an ephemeral port and return its base URL. The server
|
||||
@@ -225,7 +223,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn all_upstreams_up_is_ok() {
|
||||
let (prowlarr, transmission) = upstreams_up().await;
|
||||
let (prowlarr, qbit) = upstreams_up().await;
|
||||
let tmdb = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/configuration"))
|
||||
@@ -234,12 +232,9 @@ mod tests {
|
||||
.await;
|
||||
|
||||
let state = AppState::new(
|
||||
Upstreams::new(
|
||||
prowlarr.uri(),
|
||||
format!("{}/transmission/rpc", transmission.uri()),
|
||||
)
|
||||
.with_tmdb_url(tmdb.uri())
|
||||
.with_tmdb_api_key(Some("key".into())),
|
||||
Upstreams::new(prowlarr.uri(), qbit.uri())
|
||||
.with_tmdb_url(tmdb.uri())
|
||||
.with_tmdb_api_key(Some("key".into())),
|
||||
)
|
||||
.expect("state")
|
||||
// The subtitle binaries default to `PATH`; pin them to something
|
||||
@@ -250,19 +245,15 @@ mod tests {
|
||||
let body = report(state).await;
|
||||
assert_eq!(body["status"], "ok");
|
||||
assert_eq!(body["prowlarr"]["status"], "ok");
|
||||
assert_eq!(body["transmission"]["status"], "ok");
|
||||
assert_eq!(body["qbit"]["status"], "ok");
|
||||
assert_eq!(body["tmdb"]["status"], "ok");
|
||||
assert_eq!(body["version"], env!("CARGO_PKG_VERSION"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_missing_tmdb_key_is_unconfigured_not_an_outage() {
|
||||
let (prowlarr, transmission) = upstreams_up().await;
|
||||
let state = AppState::new(Upstreams::new(
|
||||
prowlarr.uri(),
|
||||
format!("{}/transmission/rpc", transmission.uri()),
|
||||
))
|
||||
.expect("state");
|
||||
let (prowlarr, qbit) = upstreams_up().await;
|
||||
let state = AppState::new(Upstreams::new(prowlarr.uri(), qbit.uri())).expect("state");
|
||||
|
||||
let body = report(state).await;
|
||||
assert_eq!(body["tmdb"]["status"], "unconfigured");
|
||||
@@ -271,20 +262,17 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_unreachable_upstream_degrades_the_service() {
|
||||
let (_prowlarr, transmission) = upstreams_up().await;
|
||||
let (_prowlarr, qbit) = upstreams_up().await;
|
||||
|
||||
// Port 1 is privileged and nothing binds it, so the probe gets a
|
||||
// refused connection immediately instead of waiting out the timeout.
|
||||
let state = AppState::new(Upstreams::new(
|
||||
"http://127.0.0.1:1".into(),
|
||||
format!("{}/transmission/rpc", transmission.uri()),
|
||||
))
|
||||
.expect("state");
|
||||
let state =
|
||||
AppState::new(Upstreams::new("http://127.0.0.1:1".into(), qbit.uri())).expect("state");
|
||||
|
||||
let body = report(state).await;
|
||||
assert_eq!(body["status"], "degraded");
|
||||
assert_eq!(body["prowlarr"]["status"], "unreachable");
|
||||
assert_eq!(body["transmission"]["status"], "ok");
|
||||
assert_eq!(body["qbit"]["status"], "ok");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -295,13 +283,9 @@ mod tests {
|
||||
.respond_with(ResponseTemplate::new(500))
|
||||
.mount(&prowlarr)
|
||||
.await;
|
||||
let transmission = MockServer::start().await;
|
||||
let qbit = MockServer::start().await;
|
||||
|
||||
let state = AppState::new(Upstreams::new(
|
||||
prowlarr.uri(),
|
||||
format!("{}/transmission/rpc", transmission.uri()),
|
||||
))
|
||||
.expect("state");
|
||||
let state = AppState::new(Upstreams::new(prowlarr.uri(), qbit.uri())).expect("state");
|
||||
|
||||
let body = report(state).await;
|
||||
assert_eq!(body["prowlarr"]["status"], "unreachable");
|
||||
@@ -310,7 +294,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_failed_tmdb_probe_never_echoes_the_api_key() {
|
||||
let (prowlarr, transmission) = upstreams_up().await;
|
||||
let (prowlarr, qbit) = upstreams_up().await;
|
||||
let tmdb = MockServer::start().await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/configuration"))
|
||||
@@ -319,12 +303,9 @@ mod tests {
|
||||
.await;
|
||||
|
||||
let state = AppState::new(
|
||||
Upstreams::new(
|
||||
prowlarr.uri(),
|
||||
format!("{}/transmission/rpc", transmission.uri()),
|
||||
)
|
||||
.with_tmdb_url(tmdb.uri())
|
||||
.with_tmdb_api_key(Some("super-secret".into())),
|
||||
Upstreams::new(prowlarr.uri(), qbit.uri())
|
||||
.with_tmdb_url(tmdb.uri())
|
||||
.with_tmdb_api_key(Some("super-secret".into())),
|
||||
)
|
||||
.expect("state");
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ pub struct Root {
|
||||
/// The payload for creating or replacing a root.
|
||||
#[derive(Debug, Clone, Deserialize, ToSchema)]
|
||||
pub struct RootInput {
|
||||
/// `movie` or `tv` — the Transmission label and layout prefix (§7.1, §7.4).
|
||||
/// `movie` or `tv` — the qBittorrent label and layout prefix (§7.1, §7.4).
|
||||
pub kind: String,
|
||||
/// `main` or `kids`.
|
||||
pub audience: String,
|
||||
|
||||
@@ -1655,7 +1655,7 @@ pub async fn season_releases(
|
||||
/// A grab for this season that downloaded in full and was then condemned at
|
||||
/// import (#227, §5.7).
|
||||
///
|
||||
/// The torrent stays at 100% in Transmission — §7.3 leaves that lifecycle to
|
||||
/// The torrent stays at 100% in qBittorrent — §7.3 leaves that lifecycle to
|
||||
/// the reaper — the release is blacklisted and every episode it was covering
|
||||
/// reopens as a gap. Nothing on screen connected the two, so the season read
|
||||
/// `0/10` as though no grab had ever been tried. Every fact is already
|
||||
@@ -1713,7 +1713,7 @@ async fn season_import_failures(
|
||||
WHERE newer.target_kind = 'season'
|
||||
AND newer.target_id = g.target_id
|
||||
-- 'vanished' is not a live attempt either: the
|
||||
-- torrent left Transmission, so letting it take the
|
||||
-- torrent left qBittorrent, so letting it take the
|
||||
-- headline would leave the season saying nothing at
|
||||
-- all about a gap that still exists.
|
||||
AND newer.state NOT IN ('failed', 'vanished')
|
||||
@@ -1794,7 +1794,7 @@ pub struct SeasonPackState {
|
||||
/// #227. The last pack that downloaded in full and was then condemned at
|
||||
/// import, while the season is still waiting for a file. A deck that
|
||||
/// cannot say this leaves the season reading as though nothing was ever
|
||||
/// tried, with the torrent still sitting at 100% in Transmission.
|
||||
/// tried, with the torrent still sitting at 100% in qBittorrent.
|
||||
pub import_failure: Option<ImportFailure>,
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -6,7 +6,7 @@ use std::sync::{atomic::AtomicU64, Arc};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use arr_db::Db;
|
||||
use arr_dl::TransmissionClient;
|
||||
use arr_dl::QbitClient;
|
||||
use arr_probe::Extractor;
|
||||
use arr_subs::{Backend, OpenAiEndpoint, Provider, Syncer};
|
||||
use tokio::sync::mpsc;
|
||||
@@ -33,7 +33,7 @@ const PROBE_TIMEOUT: Duration = Duration::from_secs(3);
|
||||
pub struct Upstreams {
|
||||
pub prowlarr_url: String,
|
||||
pub prowlarr_api_key: Option<String>,
|
||||
pub transmission_url: String,
|
||||
pub qbittorrent_url: String,
|
||||
pub tmdb_url: String,
|
||||
pub tmdb_api_key: Option<String>,
|
||||
}
|
||||
@@ -41,11 +41,11 @@ pub struct Upstreams {
|
||||
impl Upstreams {
|
||||
/// Every upstream at its documented default, no keys.
|
||||
#[must_use]
|
||||
pub fn new(prowlarr_url: String, transmission_url: String) -> Self {
|
||||
pub fn new(prowlarr_url: String, qbittorrent_url: String) -> Self {
|
||||
Self {
|
||||
prowlarr_url,
|
||||
prowlarr_api_key: None,
|
||||
transmission_url,
|
||||
qbittorrent_url,
|
||||
tmdb_url: DEFAULT_TMDB_URL.to_string(),
|
||||
tmdb_api_key: None,
|
||||
}
|
||||
@@ -109,7 +109,7 @@ pub struct AppState {
|
||||
extractor: Extractor,
|
||||
jellyfin: Option<JellyfinClient>,
|
||||
syncer: Syncer,
|
||||
transmission: Option<TransmissionClient>,
|
||||
qbit: Option<QbitClient>,
|
||||
download_snapshot: DownloadSnapshot,
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ impl AppState {
|
||||
extractor: Extractor::default(),
|
||||
jellyfin: None,
|
||||
syncer: Syncer::default(),
|
||||
transmission: None,
|
||||
qbit: None,
|
||||
download_snapshot: Arc::new(RwLock::new(None)),
|
||||
})
|
||||
}
|
||||
@@ -201,11 +201,11 @@ impl AppState {
|
||||
self
|
||||
}
|
||||
|
||||
/// Attach the shared Transmission client used by the API's live download
|
||||
/// Attach the shared qBittorrent client used by the API's live download
|
||||
/// snapshot endpoint.
|
||||
#[must_use]
|
||||
pub fn with_transmission(mut self, transmission: TransmissionClient) -> Self {
|
||||
self.transmission = Some(transmission);
|
||||
pub fn with_qbit(mut self, qbit: QbitClient) -> Self {
|
||||
self.qbit = Some(qbit);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -368,8 +368,8 @@ impl AppState {
|
||||
self.database.as_ref()
|
||||
}
|
||||
|
||||
pub(crate) fn transmission(&self) -> Option<&TransmissionClient> {
|
||||
self.transmission.as_ref()
|
||||
pub(crate) fn qbit(&self) -> Option<&QbitClient> {
|
||||
self.qbit.as_ref()
|
||||
}
|
||||
|
||||
pub(crate) fn download_snapshot(&self) -> &DownloadSnapshot {
|
||||
|
||||
Reference in New Issue
Block a user