rqbit/crates/librqbit
2023-11-19 20:38:41 +00:00
..
resources I can now download torrent metainfo from peers!! 2021-07-02 17:58:53 +01:00
src Trying to see why it hangs for a bit sometimes 2023-11-19 20:38:41 +00:00
.gitignore Make a serde bencode serializer 2021-07-01 23:37:57 +01:00
Cargo.toml timed existence for lock time debugging 2023-11-19 19:40:45 +00:00
README.md Fix librqbit readme 2023-11-16 07:47:00 +00:00

librqbit

A torrent library 100% written in rust

Basic example

This is a simple program on how to use this library This program will just download a simple torrent file with a Magnet link

use std::error::Error;
use std::path::PathBuf;
use librqbit::session::{AddTorrentResponse, Session};
use librqbit::spawn_utils::BlockingSpawner;

const MAGNET_LINK: &str = "magnet:?..."; // Put your magnet link here

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>>{

    // Create the session
    let session = Session::new("C:\\Anime".parse().unwrap(), BlockingSpawner::new(false)).await?;

    // Add the torrent to the session
    let handle = match session.add_torrent(MAGNET_LINK, None).await {
        Ok(AddTorrentResponse::Added(handle)) => {
            Ok(handle)
        },
        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
    handle.wait_until_completed().await?;

    Ok(())
}