mirror of
https://github.com/YGGverse/btracker-gemini.git
synced 2026-03-31 09:05:30 +00:00
require valid Url, implement magnet links
This commit is contained in:
parent
e8b409c4d6
commit
b2f3809656
4 changed files with 30 additions and 4 deletions
|
|
@ -20,6 +20,8 @@ titanite = "0.3.2"
|
||||||
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
|
||||||
librqbit-core = "5.0.0"
|
librqbit-core = "5.0.0"
|
||||||
plurify = "0.2.0"
|
plurify = "0.2.0"
|
||||||
|
url = "2.5.7"
|
||||||
|
urlencoding = "2.1.3"
|
||||||
|
|
||||||
# development
|
# development
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,9 @@ openssl pkcs12 -export -out server.pfx -inkey server.pem -in server.crt</pre>
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
btracker-gemini -i /path/to/server.pfx\
|
btracker-gemini -i /path/to/server.pfx\
|
||||||
-s /path/to/btracker-fs
|
-s /path/to/btracker-fs\
|
||||||
|
-t udp://tracker1:6969\
|
||||||
|
-t udp://tracker2:6969
|
||||||
```
|
```
|
||||||
* prepend `RUST_LOG=trace` or `RUST_LOG=btracker_gemini=trace` to debug
|
* prepend `RUST_LOG=trace` or `RUST_LOG=btracker_gemini=trace` to debug
|
||||||
* use `-b` to bind server on specified `host:port`
|
* use `-b` to bind server on specified `host:port`
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use std::{
|
||||||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
|
|
@ -13,7 +14,7 @@ pub struct Config {
|
||||||
|
|
||||||
/// Tracker(s) to join / scrape requests
|
/// Tracker(s) to join / scrape requests
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub tracker: Option<Vec<String>>,
|
pub tracker: Option<Vec<Url>>,
|
||||||
|
|
||||||
/// Bind server `host:port` to listen incoming connections on it
|
/// Bind server `host:port` to listen incoming connections on it
|
||||||
#[arg(short, long, default_value_t = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 1965)))]
|
#[arg(short, long, default_value_t = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 1965)))]
|
||||||
|
|
|
||||||
25
src/main.rs
25
src/main.rs
|
|
@ -18,6 +18,7 @@ use std::{
|
||||||
thread,
|
thread,
|
||||||
};
|
};
|
||||||
use titanite::*;
|
use titanite::*;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
if std::env::var("RUST_LOG").is_ok() {
|
if std::env::var("RUST_LOG").is_ok() {
|
||||||
|
|
@ -225,7 +226,7 @@ fn index(config: &Config, public: &Public, page: Option<usize>) -> Result<String
|
||||||
if let Some(ref trackers) = config.tracker {
|
if let Some(ref trackers) = config.tracker {
|
||||||
b.push("```".into());
|
b.push("```".into());
|
||||||
for tracker in trackers {
|
for tracker in trackers {
|
||||||
b.push(tracker.clone());
|
b.push(tracker.to_string());
|
||||||
}
|
}
|
||||||
b.push("```\n".into());
|
b.push("```\n".into());
|
||||||
}
|
}
|
||||||
|
|
@ -243,12 +244,17 @@ fn index(config: &Config, public: &Public, page: Option<usize>) -> Result<String
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
));
|
));
|
||||||
b.push(format!(
|
b.push(format!(
|
||||||
"=> {} {} • {} • {}\n",
|
"=> {} {} • {} • {}",
|
||||||
i.info_hash.as_string(),
|
i.info_hash.as_string(),
|
||||||
torrent.time.format("%Y/%m/%d"), // @TODO optional
|
torrent.time.format("%Y/%m/%d"), // @TODO optional
|
||||||
size(&i),
|
size(&i),
|
||||||
files(&i),
|
files(&i),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
b.push(format!(
|
||||||
|
"=> {} Magnet\n",
|
||||||
|
magnet(&i, config.tracker.as_ref())
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
b.push("## Navigation\n".into());
|
b.push("## Navigation\n".into());
|
||||||
|
|
@ -294,3 +300,18 @@ fn size(meta: &TorrentMetaV1Owned) -> String {
|
||||||
+ meta.info.length.unwrap_or_default(),
|
+ meta.info.length.unwrap_or_default(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn magnet(meta: &TorrentMetaV1Owned, trackers: Option<&Vec<Url>>) -> String {
|
||||||
|
let mut b = format!("magnet:?xt=urn:btih:{}", meta.info_hash.as_string());
|
||||||
|
if let Some(ref n) = meta.info.name {
|
||||||
|
b.push_str("&dn=");
|
||||||
|
b.push_str(&urlencoding::encode(&n.to_string()))
|
||||||
|
}
|
||||||
|
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