Crates.io | magneto |
lib.rs | magneto |
version | 0.2.3 |
source | src |
created_at | 2024-11-19 19:09:50.098667 |
updated_at | 2024-11-20 20:43:14.544601 |
description | A torrent searching library |
homepage | |
repository | https://github.com/mitander/magneto |
max_upload_size | |
id | 1453748 |
size | 120,074 |
Magneto
is a library for searching torrents across multiple providers.
It provides a unified interface for querying torrent metadata and integrating
custom providers.
reqwest
and tokio
.Add this to your Cargo.toml
:
[dependencies]
tokio = { version = "1", features = ["full"] }
magneto = "0.2"
Then:
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,
);
}
}
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()));
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,
};
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<Request, ClientError> {
// Convert SearchRequest parameters to a reqwest::Request
unimplemented!();
}
fn parse_response(&self, response: &str) -> Result<Vec<Torrent>, ClientError> {
// Parse the raw reponse into Vec<Torrent>
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));
}