mirror of
https://github.com/YGGverse/btracker.git
synced 2026-04-01 01:25:33 +00:00
implement magnet links
This commit is contained in:
parent
ec6d9a4e00
commit
7da285ca69
5 changed files with 58 additions and 31 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue