[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

@ -334,6 +334,9 @@ impl<'a> AddTorrent<'a> {
if SUPPORTED_SCHEMES.iter().any(|s| path.starts_with(s)) {
return Ok(Self::Url(Cow::Borrowed(path)));
}
if path.len() == 40 && !Path::new(path).exists() && Magnet::parse(path).is_ok() {
return Ok(Self::Url(Cow::Borrowed(path)));
}
Self::from_local_filename(path)
}
@ -884,7 +887,7 @@ impl Session {
// So we must discover at least one peer and connect to it to be able to proceed further.
let add_res = match add {
AddTorrent::Url(magnet) if magnet.starts_with("magnet:") => {
AddTorrent::Url(magnet) if magnet.starts_with("magnet:") || magnet.len() == 40 => {
let magnet = Magnet::parse(&magnet)
.context("provided path is not a valid magnet URL")?;
let info_hash = magnet