mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
implement magnet links
This commit is contained in:
parent
ec6d9a4e00
commit
7da285ca69
5 changed files with 58 additions and 31 deletions
24
src/feed.rs
24
src/feed.rs
|
|
@ -7,8 +7,7 @@ pub struct Feed {
|
|||
description: Option<String>,
|
||||
link: Option<String>,
|
||||
title: String,
|
||||
/// Valid, parsed from Url, ready-to-use address string donor
|
||||
trackers: Option<HashSet<String>>,
|
||||
trackers: Option<HashSet<Url>>,
|
||||
}
|
||||
|
||||
impl Feed {
|
||||
|
|
@ -22,7 +21,7 @@ impl Feed {
|
|||
description: description.map(escape),
|
||||
link: link.map(|s| escape(s.to_string())),
|
||||
title: escape(title),
|
||||
trackers: trackers.map(|v| v.into_iter().map(|u| u.to_string()).collect()),
|
||||
trackers,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +69,7 @@ impl Feed {
|
|||
.map(|b| b.to_string())
|
||||
.unwrap_or("?".into()) // @TODO
|
||||
),
|
||||
escape(self.magnet(&torrent.info_hash))
|
||||
escape(format::magnet(&torrent.info_hash, self.trackers.as_ref()))
|
||||
));
|
||||
|
||||
if let Some(d) = item_description(torrent.length, torrent.files) {
|
||||
|
|
@ -91,23 +90,6 @@ impl Feed {
|
|||
buffer.push_str("</channel></rss>");
|
||||
buffer
|
||||
}
|
||||
|
||||
// Tools
|
||||
|
||||
fn magnet(&self, info_hash: &str) -> 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(ref trackers) = self.trackers {
|
||||
for tracker in trackers {
|
||||
b.push_str("&tr=");
|
||||
b.push_str(&urlencoding::encode(tracker))
|
||||
}
|
||||
}
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
fn escape(subject: String) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue