implement magnet links

This commit is contained in:
yggverse 2025-08-05 15:06:44 +03:00
parent ec6d9a4e00
commit 7da285ca69
5 changed files with 58 additions and 31 deletions

View file

@ -15,3 +15,18 @@ pub fn bytes(value: u64) -> String {
format!("{:.2} GB", f / GB)
}
}
pub fn magnet(info_hash: &str, trackers: Option<&std::collections::HashSet<url::Url>>) -> String {
let mut b = if info_hash.len() == 40 {
format!("magnet:?xt=urn:btih:{info_hash}")
} else {
todo!("info-hash v2 is not supported by librqbit")
};
if let Some(t) = trackers {
for tracker in t {
b.push_str("&tr=");
b.push_str(&urlencoding::encode(tracker.as_str()))
}
}
b
}