rqbit/crates/librqbit/README.md

41 lines
1.1 KiB
Markdown
Raw Normal View History

2023-11-15 19:53:50 +01:00
# librqbit
A torrent library 100% written in rust
## Basic example
2023-11-15 20:21:30 +01:00
This is a simple program on how to use this library
2023-11-15 19:53:50 +01:00
This program will just download a simple torrent file with a Magnet link
```rust
use std::error::Error;
2023-11-15 21:12:31 +01:00
use std::path::PathBuf;
2023-11-15 20:27:02 +01:00
use librqbit::session::{AddTorrentResponse, Session};
2023-11-15 21:14:03 +01:00
use librqbit::spawn_utils::BlockingSpawner;
2023-11-15 19:53:50 +01:00
const MAGNET_LINK: &str = "magnet:?..."; // Put your magnet link here
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>>{
2023-11-15 21:03:03 +01:00
// Create the session
let session = Session::new("C:\\Anime".parse().unwrap(), BlockingSpawner::new(false)).await?;
// Add the torrent to the session
2023-11-15 19:53:50 +01:00
let handle = match session.add_torrent(MAGNET_LINK, None).await {
2023-11-15 21:03:03 +01:00
Ok(AddTorrentResponse::Added(handle)) => {
Ok(handle)
2023-11-15 20:27:02 +01:00
},
2023-11-15 21:03:03 +01:00
Err(e) => {
eprintln!("Something goes wrong when downloading torrent : {:?}", e);
Err(())
}
_ => Err(())
}.expect("Failed to add torrent to the session");
// Wait until the download is completed
2023-11-15 20:27:02 +01:00
handle.wait_until_completed().await?;
2023-11-15 19:53:50 +01:00
Ok(())
}
```