transmission-rpc/examples/torrent-add.rs
Aleksei Fedotov e71bc1c665 Handle adding duplicated torrent.
Starting from Transmission 2.80 (rpc-version-semver 5.1.0, rpc-version:
15) 'torrent-add' could return 'torrent-duplicated' from torrent-add if
the torrent already exists. Replace 'TorrentAdded' with
'TorrentAddedOrDuplicate'.
2022-10-02 09:31:11 +02:00

30 lines
983 B
Rust

extern crate transmission_rpc;
use dotenv::dotenv;
use std::env;
use transmission_rpc::types::{BasicAuth, Result, RpcResponse};
use transmission_rpc::types::{TorrentAddArgs, TorrentAddedOrDuplicate};
use transmission_rpc::TransClient;
#[tokio::main]
async fn main() -> Result<()> {
dotenv().ok();
env_logger::init();
let url = env::var("TURL")?;
let mut client;
if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) {
client = TransClient::with_auth(&url, BasicAuth {user, password});
} else {
client = TransClient::new(&url);
}
let add: TorrentAddArgs = TorrentAddArgs {
filename: Some("https://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso.torrent".to_string()),
..TorrentAddArgs::default()
};
let res: RpcResponse<TorrentAddedOrDuplicate> = client.torrent_add(add).await?;
println!("Add result: {:?}", &res.is_ok());
println!("response: {:?}", &res);
Ok(())
}