implement export-trackers argument option

This commit is contained in:
yggverse 2025-07-07 17:30:32 +03:00
parent f4425557ee
commit 113dd9ac09
4 changed files with 23 additions and 5 deletions

View file

@ -87,6 +87,9 @@ aquatic-crawler --infohash /path/to/info-hash-ipv4.json\
--export-rss-description <EXPORT_RSS_DESCRIPTION>
Custom description for RSS feed (channel)
--export-trackers
Appends `--tracker` value to magnets and torrents
--enable-dht
Enable DHT resolver

View file

@ -45,6 +45,10 @@ pub struct Config {
#[arg(long)]
pub export_rss_description: Option<String>,
/// Appends `--tracker` value to magnets and torrents
#[arg(long, default_value_t = false)]
pub export_trackers: bool,
/// Enable DHT resolver
#[arg(long, default_value_t = false)]
pub enable_dht: bool,

View file

@ -67,7 +67,7 @@ async fn main() -> Result<()> {
upload_bps: config.upload_limit.and_then(NonZero::new),
download_bps: config.download_limit.and_then(NonZero::new),
},
trackers: trackers.clone(),
trackers: trackers.list().clone(),
..SessionOptions::default()
},
)
@ -109,7 +109,14 @@ async fn main() -> Result<()> {
match time::timeout(
Duration::from_secs(config.add_torrent_timeout),
session.add_torrent(
AddTorrent::from_url(magnet(&i, None)),
AddTorrent::from_url(magnet(
&i,
if config.export_trackers && !trackers.is_empty() {
Some(trackers.list())
} else {
None
},
)),
Some(AddTorrentOptions {
paused: true, // continue after `only_files` init
overwrite: true,
@ -227,7 +234,11 @@ async fn main() -> Result<()> {
&config.export_rss_title,
&config.export_rss_link,
&config.export_rss_description,
Some(trackers.clone()),
if config.export_trackers && !trackers.is_empty() {
Some(trackers.list().clone())
} else {
None
},
)?;
for (k, v) in index.list() {
rss.push(

View file

@ -14,7 +14,7 @@ impl Trackers {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn clone(&self) -> HashSet<Url> {
self.0.clone()
pub fn list(&self) -> &HashSet<Url> {
&self.0
}
}