[feature] support 40-byte infohash (not a magnet) as a way to add torrents

This commit is contained in:
Igor Katson 2024-11-07 19:35:02 +00:00
parent 8d2aa93a78
commit 95f5a322f6
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
3 changed files with 23 additions and 2 deletions

View file

@ -35,6 +35,16 @@ impl Magnet {
/// Parse a magnet link.
pub fn parse(url: &str) -> anyhow::Result<Magnet> {
if url.len() == 40 {
if let Ok(id20) = Id20::from_str(url) {
return Ok(Magnet {
id20: Some(id20),
id32: None,
trackers: vec![],
select_only: None,
});
}
}
let url = url::Url::parse(url).context("magnet link must be a valid URL")?;
if url.scheme() != "magnet" {
anyhow::bail!("expected scheme magnet");