# magneto [github](https://github.com/mitander/magneto) [crates.io](https://crates.io/crates/magneto) [docs.rs](https://docs.rs/magneto) `Magneto` is a library for searching torrents across multiple providers. It provides a unified interface for querying torrent metadata and integrating custom providers. ## Features - Fully async-powered using `reqwest` and `tokio`. - Query multiple torrent search providers simultaneously. - Retrieve torrent results in a unified format. - Add custom providers with minimal effort. ## Supported providers - Knaben: A multi search archiver, acting as a cached proxy towards multiple different trackers. - PirateBay: The galaxy’s most resilient Public BitTorrent site. - YTS: A public torrent site specialising in HD movies of small size. ## Usage Add this to your `Cargo.toml`: ```toml [dependencies] tokio = { version = "1", features = ["full"] } magneto = "0.2" ``` Then: ```rust use magneto::{Magneto, SearchRequest}; #[tokio::main] async fn main() { let magneto = Magneto::new(); let request = SearchRequest::new("Ubuntu"); let results = magneto.search(request).await.unwrap(); for torrent in results { println!( "found: {} from {} with magnet link {} (seeders: {}, peers: {})", torrent.name, torrent.provider, torrent.magnet_link, torrent.seeders, torrent.peers, ); } } ``` ### Specifying search providers ```rust use magneto::{Magneto, Knaben, PirateBay, Yts}; // By default, all built-in providers are used (Knaben, PirateBay, Yts) let magneto = Magneto::new(); // You can specify which providers to use like this let magneto = Magneto::with_providers(vec![Box::new(Knaben::new()), Box::new(PirateBay::new())]); // Or like this let magneto = Magneto::default() .add_provider(Box::new(Knaben::new())) .add_provider(Box::new(Yts::new())); ``` ### Search request parameters ```rust use magneto::{Category, SearchRequest, OrderBy}; // You can add categories to filter your search results let request = SearchRequest::new("Ubuntu") .add_category(Category::Software) .add_categories(vec![Category::Audio, Category::Movies]); // Or initialize the request like this for more customization let request = SearchRequest { query: "Debian", order_by: OrderBy::Seeders, categories: vec![Category::Software], number_of_results: 10, }; ``` ### Add a custom provider ```rust use magneto::{ async_trait, Client, ClientError, Magneto, Request, SearchProvider, SearchRequest, Torrent, }; struct CustomProvider; #[async_trait] impl SearchProvider for CustomProvider { fn build_request( &self, client: &Client, request: SearchRequest<'_>, ) -> Result { // Convert SearchRequest parameters to a reqwest::Request unimplemented!(); } fn parse_response(&self, response: &str) -> Result, ClientError> { // Parse the raw reponse into Vec unimplemented!(); } fn id(&self) -> String { // Return a unique id, built-in providers use the provider url unimplemented!(); } } #[tokio::main] async fn main() { let custom_provider = CustomProvider{}; let magneto = Magneto::new().add_provider(Box::new(custom_provider)); } ``` ## License [MIT](/LICENSE)